perf: set static mmap threshold on gnu target env by default

This commit is contained in:
Michael Aaron Murphy 2025-02-12 18:30:32 +01:00 committed by Jeremy Soller
parent 9426a985c6
commit f59eb77252
5 changed files with 34 additions and 6 deletions

14
src/malloc.rs Normal file
View file

@ -0,0 +1,14 @@
use std::os::raw::c_int;
const M_MMAP_THRESHOLD: c_int = -3;
extern "C" {
fn mallopt(param: c_int, value: c_int) -> c_int;
}
/// Prevents glibc from hoarding memory via memory fragmentation.
pub fn limit_mmap_threshold(threshold: i32) {
unsafe {
mallopt(M_MMAP_THRESHOLD, threshold as c_int);
}
}