From 90c6d52cadf7c8fe479be4f115657b07d8f4668a Mon Sep 17 00:00:00 2001 From: Darkatse <39111369+Darkatse@users.noreply.github.com> Date: Sun, 22 Nov 2026 11:49:20 -0500 Subject: [PATCH] Make `no_thp` disable transparent huge pages again mimalloc v2.3.0/v3.3.0 changed `MI_NO_THP` to only skip `madvise(MADV_HUGEPAGE)`; disabling THP for the process now depends on the `allow_thp` option, whose default comes from `MI_DEFAULT_ALLOW_THP`. Define that instead, as `MI_NO_THP=ON` does in mimalloc's CMake build, and test it on Linux. --- .github/workflows/ci.yml | 8 ++++++++ libmimalloc-sys/build.rs | 2 +- libmimalloc-sys/src/lib.rs | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd537c9..c3d0652 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,6 +87,14 @@ jobs: - name: Test libmimalloc-sys crate bindings (v2, extended) run: cargo run --features libmimalloc-sys-test/v2,libmimalloc-sys-test/extended -p libmimalloc-sys-test + - name: Test libmimalloc-sys (no_thp) + if: ${{ contains(matrix.os, 'ubuntu') }} + run: cargo test --features libmimalloc-sys/no_thp -p libmimalloc-sys + + - name: Test libmimalloc-sys (v2, no_thp) + if: ${{ contains(matrix.os, 'ubuntu') }} + run: cargo test --features libmimalloc-sys/v2,libmimalloc-sys/no_thp -p libmimalloc-sys + - name: Test override dylib if: ${{ !contains(matrix.os, 'windows') }} run: cargo run -ptest-override-with-dylib --features override diff --git a/libmimalloc-sys/build.rs b/libmimalloc-sys/build.rs index 0f3fcda..5284406 100644 --- a/libmimalloc-sys/build.rs +++ b/libmimalloc-sys/build.rs @@ -99,7 +99,7 @@ fn main() { if (target_os == "linux" || target_os == "android") && env::var_os("CARGO_FEATURE_NO_THP").is_some() { - build.define("MI_NO_THP", "1"); + build.define("MI_DEFAULT_ALLOW_THP", "0"); } if debug_enabled { diff --git a/libmimalloc-sys/src/lib.rs b/libmimalloc-sys/src/lib.rs index ebd069b..3adf67b 100644 --- a/libmimalloc-sys/src/lib.rs +++ b/libmimalloc-sys/src/lib.rs @@ -136,4 +136,15 @@ mod tests { let ptr = unsafe { mi_malloc(42) }; unsafe { libc::free(ptr) }; } + + #[cfg(all(feature = "no_thp", target_os = "linux"))] + #[test] + fn no_thp_disables_transparent_huge_pages() { + // mimalloc disables THP when it initializes + unsafe { mi_free(mi_malloc(8)) }; + assert_eq!( + unsafe { libc::prctl(libc::PR_GET_THP_DISABLE, 0, 0, 0, 0) }, + 1 + ); + } }