You are not logged in.

#1 2019-04-27 12:43:46

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 10,421

Ninja overburdening system - how to tame it ?

I maintain several AUR programs that use ninja as build system.

By default ninja uses nproc + 2   as jobs setting.
On my 12C/24T threadripper system with 16 Gib memory (ECC ram is expensive...) this results in my system becoming unresponsive and needing to swap parts out of memory .

I have $MAKEFLAGS=--j20 in makepkg.conf , but ninja doesn't use $MAKEFLAGS envvar .
I've found topics going back to 2015 about this and similar issues, https://github.com/ninja-build/ninja/issues/1482 looks promising.
No idea if/when it will be available from ninja.

executing ninja like this

ninja "$MAKEFLAGS" all ocaml_doc

does mean my system has capacity for other things and doesn't need to swap stuff out from memory.


This fails however if MAKEFLAGS is unset.

I can test whether MAKEFLAGS is set, and assign an arbitrary value like "-j$(nproc)" but feel this is still to high.
something like 85% of nproc , rounded down works well for me, but I have no idea how to calculate such a value and store it in MAKEFLAGS.

Before I implement such a solution in my aur packages using ninja i'd like to hear the opinion of other aur users & maintainers.

Last edited by Lone_Wolf (2019-04-27 12:59:12)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#2 2019-04-27 13:54:38

loqs
Member
Registered: 2014-03-06
Posts: 15,351

Re: Ninja overburdening system - how to tame it ?

Looking at https://github.com/ninja-build/ninja/bl … il.cc#L493 ninja checks sched_getaffinity
so if you start makepkg with `taskset --cpu-list 0-11 makepkg` does that cause ninja to use 14 threads of your 24 core system?

Offline

#3 2019-04-27 14:35:32

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 10,421

Re: Ninja overburdening system - how to tame it ?

It does influence performance and load by a lot, but no idea how to check how many threads/ jobs ninja uses.

comparing performance of taskset 0-19 with that of -j20 suggests the performance is worse with taskset.
Maybe scheduler overhead is causing that ?


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#4 2019-04-27 14:43:05

loqs
Member
Registered: 2014-03-06
Posts: 15,351

Re: Ninja overburdening system - how to tame it ?

ninja adds 2 to the number of processes it uses when it detects more than 2 cores [1] so 0-19 should be equivalent to -j22 but run on 20 cores.

[1] https://github.com/ninja-build/ninja/bl … ja.cc#L228

Offline

#5 2019-04-27 16:12:25

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 10,421

Re: Ninja overburdening system - how to tame it ?

Reduced cpulist to 0-17 to have ninja run 20 jobs, this does bring performance with this specific task much closer to running with -j20.

Ninja is very fast and reliable, but I sometimes wish the effort to create ninja (and meson) had been spend to improve make / autotools.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#6 2019-04-27 21:22:04

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 10,421

Re: Ninja overburdening system - how to tame it ?

I build some more ninja packages and observed.
Using taskset is more restrictive then ninja -j option .

I'll use something like this :

if [[ ! $MAKEFLAGS ]]; then
  ninja
else
  ninja "$MAKEFLAGS"
fi


EDIT:
I've configured several packages this way now and it does appear to work fine.
I'm not marking this as solved yet, as both taskset and this if-then-else are workarounds.

Still hoping there are other options.

Last edited by Lone_Wolf (2019-04-28 11:13:38)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#7 2019-04-29 11:50:02

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 10,421

Re: Ninja overburdening system - how to tame it ?

Aur comments by lahwaacz made me realise ninja supports only a small part of the options MAKEFLAGS allow.
Running ninja "$MAKEFLAGS" does have a high chance of failing if those options are used.

I will switch to a dedicated envvar, NINJAFLAGS .

Add to makepkg.conf :

# limit ninja to 20 jobs
# requires special code in PKGBUILD
# see ninja --help for additonal options
NINJAFLAGS="-j20"

in PKGBUILD :

if [[ ! $NINJAFLAGS ]]; then
  ninja
else
  ninja "$NINJAFLAGS"
fi

This should allow users to configure ninja in whatever way they want without clashing with other programs.
Those that prefer ninja defaults have to do nothing.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

Board footer

Powered by FluxBB