Skip to content

Commit f2297e9

Browse files
committed
NO-ISSUE Support experimental extended options
1 parent ce42f71 commit f2297e9

File tree

1 file changed

+86
-4
lines changed

1 file changed

+86
-4
lines changed

libmimalloc-sys/src/extended.rs

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,6 @@ pub type mi_deferred_free_fun =
316316
pub type mi_error_fun = Option<unsafe extern "C" fn(code: c_int, arg: *mut c_void)>;
317317

318318
/// Runtime options. All options are false by default.
319-
///
320-
/// Note: Currently experimental options (values > `mi_option_verbose` are not
321-
/// given named constants), as they may change and make exposing a stable API
322-
/// difficult.
323319
pub type mi_option_t = c_int;
324320

325321
// Note: mimalloc doc website seems to have the order of show_stats and
@@ -335,6 +331,76 @@ pub const mi_option_show_stats: mi_option_t = 1;
335331
/// Option allowing printing verbose messages to stderr.
336332
pub const mi_option_verbose: mi_option_t = 2;
337333

334+
/// Option specifying eagerly commit segments (4MiB) (enabled by default).
335+
pub const mi_option_eager_commit: mi_option_t = 3;
336+
337+
/// Option specifying eagerly commit large (256MiB) memory regions (enabled by default, except on Windows).
338+
pub const mi_option_eager_region_commit: mi_option_t = 4;
339+
340+
/// Option (experimental) to use large OS pages (2MiB in size) if possible.
341+
///
342+
/// Use large OS pages (2MiB) when available; for some workloads this can
343+
/// significantly improve performance. Use mi_option_verbose to check if
344+
/// the large OS pages are enabled -- usually one needs to explicitly allow
345+
/// large OS pages (as on Windows and Linux). However, sometimes the OS is
346+
/// very slow to reserve contiguous physical memory for large OS pages so
347+
/// use with care on systems that can have fragmented memory (for that
348+
/// reason, we generally recommend to use mi_option_reserve_huge_os_pages
349+
/// instead whenever possible).
350+
pub const mi_option_large_os_pages: mi_option_t = 5;
351+
352+
/// Option (experimental) specifying number of huge OS pages (1GiB in size) to reserve at the start of the program.
353+
///
354+
/// This reserves the huge pages at startup and sometimes this can give a large (latency) performance
355+
/// improvement on big workloads. Usually it is better to not use MIMALLOC_LARGE_OS_PAGES in
356+
/// combination with this setting. Just like large OS pages, use with care as reserving contiguous
357+
/// physical memory can take a long time when memory is fragmented (but reserving the huge pages is
358+
/// done at startup only once). Note that we usually need to explicitly enable huge OS pages (as on
359+
/// Windows and Linux)). With huge OS pages, it may be beneficial to set the setting
360+
/// mi_option_eager_commit_delay=N (N is 1 by default) to delay the initial N segments (of 4MiB) of
361+
/// a thread to not allocate in the huge OS pages; this prevents threads that are short lived and
362+
/// allocate just a little to take up space in the huge OS page area (which cannot be reset).
363+
pub const mi_option_reserve_huge_os_pages: mi_option_t = 6;
364+
365+
/// Option (experimental) specifying number of segments per thread to keep cached.
366+
pub const mi_option_segment_cache: mi_option_t = 7;
367+
368+
/// Option (experimental) to reset page memory after mi_option_reset_delay milliseconds when it becomes free.
369+
///
370+
/// By default, mimalloc will reset (or purge) OS pages that are not in use, to signal to the OS
371+
/// that the underlying physical memory can be reused. This can reduce memory fragmentation in
372+
/// long running (server) programs. By setting it to 0 this will no longer be done which can improve
373+
/// performance for batch-like programs. As an alternative, the mi_option_reset_delay= can be set
374+
/// higher (100ms by default) to make the page reset occur less frequently instead of turning it
375+
/// off completely.
376+
///
377+
/// Default: 1 (true)
378+
pub const mi_option_page_reset: mi_option_t = 8;
379+
380+
/// Experimental
381+
pub const mi_option_segment_reset: mi_option_t = 9;
382+
383+
/// Option (experimental) specifying delay in milli-seconds before resetting a page (100ms by default).
384+
pub const mi_option_reset_delay: mi_option_t = 10;
385+
386+
/// Option (experimental) to pretend there are at most N NUMA nodes.
387+
///
388+
/// If not set, the actual NUMA nodes are detected at runtime. Setting N to 1 may avoid
389+
/// problems in some virtual environments. Also, setting it to a lower number than the
390+
/// actual NUMA nodes is fine and will only cause threads to potentially allocate more
391+
/// memory across actual NUMA nodes (but this can happen in any case as NUMA local
392+
/// allocation is always a best effort but not guaranteed).
393+
pub const mi_option_use_numa_nodes: mi_option_t = 11;
394+
395+
/// Experimental
396+
pub const mi_option_reset_decommits: mi_option_t = 12;
397+
398+
/// Experimental
399+
pub const mi_option_eager_commit_delay: mi_option_t = 13;
400+
401+
/// Option (experimental) specifying OS tag to assign to mimalloc'd memory.
402+
pub const mi_option_os_tag: mi_option_t = 14;
403+
338404
extern "C" {
339405
// Note: mi_option_{enable,disable} aren't exposed because they're redundant
340406
// and because of https://github.com/microsoft/mimalloc/issues/266.
@@ -682,3 +748,19 @@ extern "C" {
682748
arg: *mut c_void,
683749
) -> bool;
684750
}
751+
752+
#[cfg(test)]
753+
mod tests {
754+
use super::*;
755+
756+
#[test]
757+
fn runtime_option() {
758+
unsafe {
759+
mi_option_set(mi_option_page_reset, 12);
760+
assert_eq!(mi_option_get(mi_option_page_reset), 12);
761+
762+
mi_option_set(mi_option_reset_delay, 10000);
763+
assert_eq!(mi_option_get(mi_option_reset_delay), 10000);
764+
}
765+
}
766+
}

0 commit comments

Comments
 (0)