1*4882a593SmuzhiyunFrom b8384ef181084c630d0073dcb81dfd338da40c42 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Maksim Sisov <msisov@igalia.com>
3*4882a593SmuzhiyunDate: Wed, 15 Sep 2021 14:29:03 +0300
4*4882a593SmuzhiyunSubject: [PATCH] limit number of LTO jobs.
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun--thinlto-jobs accepts "all" only since llvm 13. Dunfell
7*4882a593Smuzhiyunbranch uses quite old llvm that doesn't support this keyword.
8*4882a593SmuzhiyunThus, use the previously used number of threads.
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunUpstream-Status: Inappropriate
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunSigned-off-by: Maksim Sisov <msisov@igalia.com>
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun---
15*4882a593Smuzhiyun build/config/compiler/BUILD.gn     | 12 ++++++------
16*4882a593Smuzhiyun build/config/compiler/compiler.gni |  5 +++++
17*4882a593Smuzhiyun 2 files changed, 11 insertions(+), 6 deletions(-)
18*4882a593Smuzhiyun
19*4882a593Smuzhiyundiff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
20*4882a593Smuzhiyunindex ef3285ae74e1b..a704f0f485e4e 100644
21*4882a593Smuzhiyun--- a/build/config/compiler/BUILD.gn
22*4882a593Smuzhiyun+++ b/build/config/compiler/BUILD.gn
23*4882a593Smuzhiyun@@ -683,7 +683,7 @@ config("compiler") {
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun     if (is_win) {
26*4882a593Smuzhiyun       ldflags += [
27*4882a593Smuzhiyun-        "/opt:lldltojobs=all",
28*4882a593Smuzhiyun+        "/opt:lldltojobs=" + max_jobs_per_link,
29*4882a593Smuzhiyun         "-mllvm:-import-instr-limit=$import_instr_limit",
30*4882a593Smuzhiyun         "/lldltocache:" +
31*4882a593Smuzhiyun             rebase_path("$root_out_dir/thinlto-cache", root_build_dir),
32*4882a593Smuzhiyun@@ -696,11 +696,11 @@ config("compiler") {
33*4882a593Smuzhiyun       # usage in crbug.com/1038040. Note this will increase build time in
34*4882a593Smuzhiyun       # Chrome OS.
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun-      # In ThinLTO builds, we run at most one link process at a time,
37*4882a593Smuzhiyun-      # and let it use all cores.
38*4882a593Smuzhiyun-      # TODO(thakis): Check if '=0' (that is, number of cores, instead
39*4882a593Smuzhiyun-      # of "all" which means number of hardware threads) is faster.
40*4882a593Smuzhiyun-      ldflags += [ "-Wl,--thinlto-jobs=all" ]
41*4882a593Smuzhiyun+      # Limit the parallelism to avoid too aggressive competition between
42*4882a593Smuzhiyun+      # linker jobs. This is still suboptimal to a potential dynamic
43*4882a593Smuzhiyun+      # resource allocation scheme, but should be good enough.
44*4882a593Smuzhiyun+      ldflags += [ "-Wl,--thinlto-jobs=" + max_jobs_per_link ]
45*4882a593Smuzhiyun+
46*4882a593Smuzhiyun       if (is_apple) {
47*4882a593Smuzhiyun         _object_path_suffix = ""
48*4882a593Smuzhiyun         if (is_ios) {
49*4882a593Smuzhiyundiff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni
50*4882a593Smuzhiyunindex 4738ee80d307c..7a43b1113a495 100644
51*4882a593Smuzhiyun--- a/build/config/compiler/compiler.gni
52*4882a593Smuzhiyun+++ b/build/config/compiler/compiler.gni
53*4882a593Smuzhiyun@@ -99,6 +99,11 @@ declare_args() {
54*4882a593Smuzhiyun   # If true, use Goma for ThinLTO code generation where applicable.
55*4882a593Smuzhiyun   use_goma_thin_lto = false
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun+  # Limit the number of jobs (threads/processes) the linker is allowed
58*4882a593Smuzhiyun+  # to use (for linkers that support this).
59*4882a593Smuzhiyun+  # Upstream chromium uses "all" keyword that is available since llvm 13.
60*4882a593Smuzhiyun+  max_jobs_per_link = 8
61*4882a593Smuzhiyun+
62*4882a593Smuzhiyun   # Whether we're using a sample profile collected on an architecture different
63*4882a593Smuzhiyun   # than the one we're compiling for.
64*4882a593Smuzhiyun   #
65