Merge PR 1363

This commit is contained in:
Valiantsin Dzerakh committed 2026-11-22 16:17:00 +03:00
commit 2bfde7ac0c
3 files changed
+59 -3

No files matched your search

+21 -3
View File
@@ -42,8 +42,9 @@ objects Ninja just rebuilt (new mtime). A mismatch deletes the object, Ninja rec
summary line. A fork checks the hardlinked generated objects against build/<version>/obj/objects.sha256 (read-only; a
bad shared object stops the fork and asks for a main build run, which recompiles it and breaks the shared inode).
Compile jobs share a memory budget (MEM_BUDGET, default the smaller of 50 GiB and 80% of RAM) at JOB_MEM per job, so a
big machine does not run out of memory on the largest chunks. Each phase reports its wall time and the peak memory
Compile jobs share a memory budget (compile_budget: the smaller of MEM_BUDGET = 50 GiB, 80% of RAM and, on Windows,
80% of the memory free at the start) at JOB_MEM per job, so a big machine does not run out of memory on the largest
chunks, nor a small one already running a browser and the setup. Each phase reports its wall time and the peak memory
of its processes (Windows job object accounting: committed private bytes).
--ninja PATH names the Ninja to run; without MSYS2 the bin/ninja.exe of the release folder (tools/make_release.py) is used.
@@ -77,6 +78,7 @@ import urllib.request
from pathlib import Path
import check_isa
import hostmem
import romfs_index
from build_shaders import stale as stale_shaders
from check_content import GENERATED_MARKER
@@ -220,6 +222,18 @@ GiB = 1 << 30
# (295k-entry tables). 768 MiB leaves headroom for the largest file.
JOB_MEM = 768 << 20
MEM_BUDGET = 50 * GiB # total for all compile jobs
MEM_SHARE = 0.8 # of the RAM, and of the free memory, the compile jobs may take
def compile_budget(total, free):
"""Bytes the compile jobs may take together: MEM_BUDGET, MEM_SHARE of the RAM (total) and MEM_SHARE of the memory
free now (free: hostmem.available_ram, None when unknown). The total alone counted the RAM other programs hold: on
an 8 GiB PC with 3 GiB free it allowed 8 jobs of JOB_MEM (6 GiB), so the compile paged or a job ran out of memory.
recomp/gen.py sizes the lift workers from the free memory the same way."""
budget = min(MEM_BUDGET, int(total * MEM_SHARE))
if free is not None:
budget = min(budget, int(max(0, free) * MEM_SHARE))
return budget
def below_root(p):
@@ -1179,8 +1193,12 @@ def main():
mods = {} if args.make_runtime_lib else {m: chunk_files(gen, m) for m in linked}
cpus = os.cpu_count() or 1
budget = min(MEM_BUDGET, int(total_ram() * 0.8))
free = hostmem.available_ram()
budget = compile_budget(total_ram(), free)
jobs = args.jobs or max(1, min(cpus, budget // JOB_MEM))
if not args.jobs:
print(f'build_game: {cpus} CPUs, {mib(budget)} for compile jobs'
f'{"" if free is None else f" ({mib(free)} free memory)"}', flush=True)
plugins = read_plugin_files(gen)
missing = [n for n in names if n not in hashes and n not in plugins]
if missing: