[recipe] Enable THP for jemalloc build in GN recipe Configure jemalloc with --with-malloc-conf=thp:always to enable Transparent Huge Pages (THP) by default on Linux. When running large GN generation tasks (such as Chromium's gn gen), jemalloc allocates extensive virtual memory ranges. Without THP enabled by default, allocations rely heavily on 4KB pages, leading to significant kernel overhead in page fault handling and page table walks (minor page faults: ~467k). By enabling thp:always, jemalloc proactively uses 2MB huge pages via madvise(MADV_HUGEPAGE), reducing minor page faults by 54% and improving wall clock time by ~218ms (~6.7%). Benchmark (`hyperfine --warmup 2 --runs 10` on Chromium `gn gen`): - jemalloc (default): 3.236 s ± 0.028 s - jemalloc (thp:always): 3.018 s ± 0.052 s (-218 ms, 1.07x faster) perf stat comparison: - Minor faults: 467,490 -> 215,229 (-54.0%) - CPU cycles: 104.9G -> 98.2G (-6.7B cycles) - User CPU time: 26.54s -> 23.92s (-2.62s) - Sys CPU time: 17.51s -> 15.62s (-1.89s) TAG=agy CONV=4cb5d931-60a8-4f44-8632-3e8d9fb10a8d Change-Id: I134509479c0cf74c397cea8c8227d911e2734963 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/26460 Commit-Queue: David Turner <digit@google.com> Reviewed-by: David Turner <digit@google.com>
diff --git a/infra/recipes/gn.expected/ci_linux.json b/infra/recipes/gn.expected/ci_linux.json index 3a98040..bc50b1a 100644 --- a/infra/recipes/gn.expected/ci_linux.json +++ b/infra/recipes/gn.expected/ci_linux.json
@@ -301,7 +301,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-amd64", "env": { @@ -400,6 +401,7 @@ "--enable-static", "--disable-syscall", "--disable-stats", + "--with-malloc-conf=thp:always", "--with-lg-page=16" ], "cwd": "[START_DIR]/jemalloc/build-linux-arm64", @@ -498,7 +500,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-riscv64", "env": {
diff --git a/infra/recipes/gn.expected/cipd_exists.json b/infra/recipes/gn.expected/cipd_exists.json index 9a363f0..b236cb8 100644 --- a/infra/recipes/gn.expected/cipd_exists.json +++ b/infra/recipes/gn.expected/cipd_exists.json
@@ -301,7 +301,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-amd64", "env": { @@ -400,6 +401,7 @@ "--enable-static", "--disable-syscall", "--disable-stats", + "--with-malloc-conf=thp:always", "--with-lg-page=16" ], "cwd": "[START_DIR]/jemalloc/build-linux-arm64", @@ -498,7 +500,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-riscv64", "env": {
diff --git a/infra/recipes/gn.expected/cipd_register.json b/infra/recipes/gn.expected/cipd_register.json index 76cdb0f..e018c44 100644 --- a/infra/recipes/gn.expected/cipd_register.json +++ b/infra/recipes/gn.expected/cipd_register.json
@@ -301,7 +301,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-amd64", "env": { @@ -400,6 +401,7 @@ "--enable-static", "--disable-syscall", "--disable-stats", + "--with-malloc-conf=thp:always", "--with-lg-page=16" ], "cwd": "[START_DIR]/jemalloc/build-linux-arm64", @@ -498,7 +500,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-riscv64", "env": {
diff --git a/infra/recipes/gn.expected/cq_linux.json b/infra/recipes/gn.expected/cq_linux.json index 91282cc..5c815f5 100644 --- a/infra/recipes/gn.expected/cq_linux.json +++ b/infra/recipes/gn.expected/cq_linux.json
@@ -352,7 +352,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-amd64", "env": { @@ -451,6 +452,7 @@ "--enable-static", "--disable-syscall", "--disable-stats", + "--with-malloc-conf=thp:always", "--with-lg-page=16" ], "cwd": "[START_DIR]/jemalloc/build-linux-arm64", @@ -549,7 +551,8 @@ "--disable-shared", "--enable-static", "--disable-syscall", - "--disable-stats" + "--disable-stats", + "--with-malloc-conf=thp:always" ], "cwd": "[START_DIR]/jemalloc/build-linux-riscv64", "env": {
diff --git a/infra/recipes/gn.py b/infra/recipes/gn.py index 28039e9..a5cd4e6 100644 --- a/infra/recipes/gn.py +++ b/infra/recipes/gn.py
@@ -241,6 +241,10 @@ '--enable-static', '--disable-syscall', '--disable-stats', + # Enable Transparent Huge Pages (THP) by default via madvise to reduce + # minor page faults and page table walk overhead during large generation + # tasks (e.g. saves ~54% minor faults and ~7% wall time on Chromium). + '--with-malloc-conf=thp:always', ] if platform == 'linux-arm64': configure_args.append('--with-lg-page=16')