On 2/2/25 3:09 AM, 'Alexey Savchkov' via The Meson Build System wrote:
> I build multiple C++ meson/ninja projects in parallel (on a build agent)
> and need to limit meson concurrency otherwise a project takes up all
> available system resources. Initially I tried to specify the -j option to
> 'meson compile' and it indeed limits the number of cc1plus processes but
> then comes the linker and throws a number of lto1-ltrans processes which is
> apparently not affected by the -j flag (it should perhaps?). Then in
> addition to -j I also set project('myproject', 'cpp', default_options:
> [..., 'backend_max_links=1', ...]) - again with no effect on lto1-ltrans.
> The only way I can contol the number of lto1-ltrans processes is by varying
> the number of CPUs in the system with lto1-ltrans's being exactly equal to
> the number of CPUs but this is only for localisation of the cause and isn't
> a real solution for me.
>
> Is it by intension or a bug? Looks like it is impossible to build more than
> one project at one time.
If you're seeing too many lto1-ltrans processes then this is not
controlled by backend_max_links or even -j1.
> These are the compildation flags that rpmbuild (%meson-macros) outputs:
>
> + CFLAGS='-O2 -flto=auto -ffat-lto-objects [......]
Using -j1 limits to a single GCC linker job at a time. GCC's linker
support then runs "auto" number of lto1-ltrans jobs, which can
communicate with the GNU Make jobserver to limit the parallelism but
otherwise uses as many processes as you have CPUs.
This is a Ninja bug that may be fixed by
https://github.com/ninja-build/ninja/pull/2506
The other option is to configure meson with
-D b_lto_threads=1
to prevent LTO from using more than one job at a time. This will prevent
sharing resources across multiple projects at all, but at least you
won't have problematic system resource exhaustion.
--
Eli Schwartz