Skip to content

Commit e9afada

Browse files
committed
Bug 1726619 - Replace MOZ_LOW_PARALLELISM_BUILD with automated heuristic parallelism based on memory usage, and use for hazard builds r=firefox-build-system-reviewers,glandium
Differential Revision: https://phabricator.services.mozilla.com/D123147
1 parent 644eb70 commit e9afada

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

js/src/devtools/rootAnalysis/mach_commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ def gather_hazard_data(self, command_context, **kwargs):
253253
buildscript = " ".join(
254254
[
255255
command_context.topsrcdir + "/mach hazards compile",
256+
"--job-size=3.0", # Conservatively estimate 3GB/process
256257
"--application=" + application,
257258
"--haz-objdir=" + objdir,
258259
]

python/mozbuild/mozbuild/base.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
memoized_property,
4444
)
4545

46+
try:
47+
import psutil
48+
except Exception:
49+
psutil = None
50+
4651

4752
def ancestors(path):
4853
"""Emit the parent directories of a path."""
@@ -731,6 +736,7 @@ def _run_make(
731736
print_directory=True,
732737
pass_thru=False,
733738
num_jobs=0,
739+
job_size=0,
734740
keep_going=False,
735741
):
736742
"""Invoke make.
@@ -775,17 +781,24 @@ def _run_make(
775781
else:
776782
args.append(flag)
777783

778-
if num_jobs > 0:
779-
args.append("-j%d" % num_jobs)
780-
elif os.environ.get("MOZ_LOW_PARALLELISM_BUILD"):
784+
if num_jobs == 0:
785+
if job_size == 0:
786+
job_size = 2.0 if self.substs.get("CC_TYPE") == "gcc" else 1.0 # GiB
787+
781788
cpus = multiprocessing.cpu_count()
782-
jobs = max(1, int(0.75 * cpus))
783-
print(
784-
" Low parallelism requested: using %d jobs for %d cores" % (jobs, cpus)
785-
)
786-
args.append("-j%d" % jobs)
787-
else:
788-
args.append("-j%d" % multiprocessing.cpu_count())
789+
if not psutil or not job_size:
790+
num_jobs = cpus
791+
else:
792+
mem_gb = psutil.virtual_memory().total / 1024 ** 3
793+
from_mem = round(mem_gb / job_size)
794+
num_jobs = max(1, min(cpus, from_mem))
795+
print(
796+
" Parallelism determined by memory: using %d jobs for %d cores "
797+
"based on %.1f GiB RAM and estimated job size of %.1f GiB"
798+
% (num_jobs, cpus, mem_gb, job_size)
799+
)
800+
801+
args.append("-j%d" % num_jobs)
789802

790803
if ignore_errors:
791804
args.append("-k")

python/mozbuild/mozbuild/build_commands.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ class Build(MachCommandBase):
4040
default="0",
4141
metavar="jobs",
4242
type=int,
43-
help="Number of concurrent jobs to run. Default is the number of CPUs.",
43+
help="Number of concurrent jobs to run. Default is based on the number of "
44+
"CPUs and the estimated size of the jobs (see --job-size).",
45+
)
46+
@CommandArgument(
47+
"--job-size",
48+
default="0",
49+
metavar="size",
50+
type=float,
51+
help="Estimated RAM required, in GiB, for each parallel job. Used to "
52+
"compute a default number of concurrent jobs.",
4453
)
4554
@CommandArgument(
4655
"-C",
@@ -65,6 +74,7 @@ def build(
6574
command_context,
6675
what=None,
6776
jobs=0,
77+
job_size=0,
6878
directory=None,
6979
verbose=False,
7080
keep_going=False,
@@ -115,6 +125,7 @@ def build(
115125
command_context.metrics,
116126
what=what,
117127
jobs=jobs,
128+
job_size=job_size,
118129
directory=directory,
119130
verbose=verbose,
120131
keep_going=keep_going,
@@ -156,6 +167,7 @@ def build(
156167
command_context.metrics,
157168
what=what,
158169
jobs=jobs,
170+
job_size=job_size,
159171
directory=directory,
160172
verbose=verbose,
161173
keep_going=keep_going,

python/mozbuild/mozbuild/controller/building.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ def build(
10641064
metrics,
10651065
what=None,
10661066
jobs=0,
1067+
job_size=0,
10671068
directory=None,
10681069
verbose=False,
10691070
keep_going=False,
@@ -1255,6 +1256,7 @@ def get_substs_flag(name):
12551256
print_directory=False,
12561257
ensure_exit_code=False,
12571258
num_jobs=jobs,
1259+
job_size=job_size,
12581260
silent=not verbose,
12591261
append_env=tgt_env,
12601262
keep_going=keep_going,
@@ -1269,6 +1271,7 @@ def get_substs_flag(name):
12691271
status = self._run_client_mk(
12701272
line_handler=output.on_line,
12711273
jobs=jobs,
1274+
job_size=job_size,
12721275
verbose=verbose,
12731276
keep_going=keep_going,
12741277
append_env=append_env,
@@ -1619,6 +1622,7 @@ def _run_client_mk(
16191622
target=None,
16201623
line_handler=None,
16211624
jobs=0,
1625+
job_size=0,
16221626
verbose=None,
16231627
keep_going=False,
16241628
append_env=None,
@@ -1701,6 +1705,7 @@ def _run_client_mk(
17011705
line_handler=line_handler,
17021706
log=False,
17031707
num_jobs=jobs,
1708+
job_size=job_size,
17041709
silent=not verbose,
17051710
keep_going=keep_going,
17061711
append_env=append_env,

taskcluster/ci/build/linux-base-toolchains.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ linux64-base-toolchains/opt:
1919
worker:
2020
max-run-time: 7200
2121
env:
22-
MOZ_LOW_PARALLELISM_BUILD: '1'
2322
PERFHERDER_EXTRA_OPTIONS: base-toolchains
2423
FORCE_GCC: '1'
2524
run:
@@ -59,7 +58,6 @@ linux64-base-toolchains/debug:
5958
worker:
6059
max-run-time: 7200
6160
env:
62-
MOZ_LOW_PARALLELISM_BUILD: '1'
6361
PERFHERDER_EXTRA_OPTIONS: base-toolchains
6462
FORCE_GCC: '1'
6563
run:

taskcluster/ci/build/linux.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ linux64-gcc/opt:
183183
worker:
184184
max-run-time: 7200
185185
env:
186-
MOZ_LOW_PARALLELISM_BUILD: '1'
187186
PERFHERDER_EXTRA_OPTIONS: gcc
188187
FORCE_GCC: '1'
189188
run:

0 commit comments

Comments
 (0)