5

I was using Ninja 1.8.2 on Debian 9 to build llvm-6.0 using llvm-5.0.

When I inspected the CPU usage of my system, I found the CPU is not 100% used, and there's plenty memory left.

After checking the output of cmake, I found it limiting the parallel linking jobs to 2 because the llvm running on my machine runs in parallel too.

I want to try whether lifting that limit will enable my build to be faster, but there's hardly any document about that.

Edit:

I checked the content of the rules.ninja file in my build dir, and found these:

#############################################
# Pools defined by global property JOB_POOLS

pool link_job_pool
  depth = 2

I also checked the content of build.ninja and found this:

build lib/libLLVMDemangle.a: CXX_STATIC_LIBRARY_LINKER__LLVMDemangle lib/Demangle/CMakeFiles/LLVMDemangle.dir/ItaniumDemangle.cpp.o
  LANGUAGE_COMPILE_FLAGS = -Ofast -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++1y -Wal       l -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -W       non-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fcolor-diagnostics -ffunction-sections -fdata-sections -flto=thin -O3 -D       NDEBUG
  OBJECT_DIR = lib/Demangle/CMakeFiles/LLVMDemangle.dir
  POST_BUILD = :
  PRE_LINK = :
  TARGET_FILE = lib/libLLVMDemangle.a
  TARGET_PDB = LLVMDemangle.a.dbg
  pool = link_job_pool

It seems that other commands for linking all have the arg pool.

JiaHao Xu
  • 2,452
  • 16
  • 31
  • Does your [tag:ninja] file define [pools](https://ninja-build.org/manual.html#ref_pool) for linking? Otherwise there is no specific parallelism limit except for the dependencies you have for the linking step. – Florian Apr 11 '18 at 11:30
  • I'm asking how to lift the limit of linking stage... – JiaHao Xu Apr 11 '18 at 22:11
  • There is no linking stage limit from `ninja` by default. So we need more information to help you. Can you give a [mcve] of your `rules.ninja` file? How do you know there is a "linking limit of 2 jobs in parallel"? Does `llvm` not use [tag:cmake] to generate the build environment? – Florian Apr 12 '18 at 18:48
  • The build.ninja is generated by cmake, and in the output of cmake, it said "limiting parallel link job to 2". I mistook that for the output of ninja, sorry. – JiaHao Xu Apr 15 '18 at 03:55
  • My experience is that the less linking jobs the better, linking stage eats memories a lot, rather than CPU power, two many parallel linking jobs will drain your memory soon, especially you build LLVM with Clang together, on Linux, that's a nightmare to me. – psionic12 Nov 18 '20 at 11:10

1 Answers1

6

Turning my comments into an answer

There is no linking stage limit from by default. But ninja allows to define pools to "allocate one or more rules or edges a finite number of concurrent jobs which is more tightly restricted than the default parallelism."

As uses to generate the build environment, I've checked the CMake code there:

 if(NOT LLVM_PARALLEL_LINK_JOBS AND uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
  message(STATUS "ThinLTO provides its own parallel linking - limiting parallel link jobs to 2.")
  set(LLVM_PARALLEL_LINK_JOBS "2")
endif()

So you can overwrite/preset LLVM_PARALLEL_LINK_JOBS cached variable from the command line:

> cmake -DLLVM_PARALLEL_LINK_JOBS=<your number of parallel link jobs here> ..

Reference

Florian
  • 39,996
  • 9
  • 133
  • 149