Skip to content

Commit a2c3b0f

Browse files
committed
add option to reserve huge os pages at a specific numa node.
1 parent 076f815 commit a2c3b0f

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

doc/mimalloc-doc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ typedef enum mi_option_e {
782782
mi_option_eager_region_commit, ///< Eagerly commit large (256MiB) memory regions (enabled by default, except on Windows)
783783
mi_option_large_os_pages, ///< Use large OS pages (2MiB in size) if possible
784784
mi_option_reserve_huge_os_pages, ///< The number of huge OS pages (1GiB in size) to reserve at the start of the program.
785+
mi_option_reserve_huge_os_pages_at, ///< Reserve huge OS pages at node N.
785786
mi_option_segment_cache, ///< The number of segments per thread to keep cached.
786787
mi_option_page_reset, ///< Reset page memory after \a mi_option_reset_delay milliseconds when it becomes free.
787788
mi_option_segment_reset, ///< Experimental
@@ -1053,6 +1054,8 @@ or via environment variables.
10531054
`MIMALLOC_EAGER_COMMIT_DELAY=N` (`N` is 1 by default) to delay the initial `N` segments (of 4MiB)
10541055
of a thread to not allocate in the huge OS pages; this prevents threads that are short lived
10551056
and allocate just a little to take up space in the huge OS page area (which cannot be reset).
1057+
- `MIMALLOC_RESERVE_HUGE_OS_PAGES_AT=N`: where N is the numa node. This reserves the huge pages at a specific numa node.
1058+
(`N` is -1 by default to reserve huge pages evenly among the given number of numa nodes (or use the available ones as detected))
10561059
10571060
Use caution when using `fork` in combination with either large or huge OS pages: on a fork, the OS uses copy-on-write
10581061
for all pages in the original process including the huge OS pages. When any memory is now written in that area, the

include/mimalloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ typedef enum mi_option_e {
306306
mi_option_reset_decommits,
307307
mi_option_large_os_pages, // implies eager commit
308308
mi_option_reserve_huge_os_pages,
309+
mi_option_reserve_huge_os_pages_at,
309310
mi_option_reserve_os_memory,
310311
mi_option_segment_cache,
311312
mi_option_page_reset,

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ or via environment variables:
302302
`MIMALLOC_EAGER_COMMIT_DELAY=N` (`N` is 1 by default) to delay the initial `N` segments (of 4MiB)
303303
of a thread to not allocate in the huge OS pages; this prevents threads that are short lived
304304
and allocate just a little to take up space in the huge OS page area (which cannot be reset).
305+
- `MIMALLOC_RESERVE_HUGE_OS_PAGES_AT=N`: where N is the numa node. This reserves the huge pages at a specific numa node.
306+
(`N` is -1 by default to reserve huge pages evenly among the given number of numa nodes (or use the available ones as detected))
305307

306308
Use caution when using `fork` in combination with either large or huge OS pages: on a fork, the OS uses copy-on-write
307309
for all pages in the original process including the huge OS pages. When any memory is now written in that area, the

src/init.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,12 @@ void mi_process_init(void) mi_attr_noexcept {
494494

495495
if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
496496
size_t pages = mi_option_get(mi_option_reserve_huge_os_pages);
497-
mi_reserve_huge_os_pages_interleave(pages, 0, pages*500);
497+
long reserve_at = mi_option_get(mi_option_reserve_huge_os_pages_at);
498+
if (reserve_at != -1) {
499+
mi_reserve_huge_os_pages_at(pages, reserve_at, pages*500);
500+
} else {
501+
mi_reserve_huge_os_pages_interleave(pages, 0, pages*500);
502+
}
498503
}
499504
if (mi_option_is_enabled(mi_option_reserve_os_memory)) {
500505
long ksize = mi_option_get(mi_option_reserve_os_memory);

src/options.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static mi_option_desc_t options[_mi_option_last] =
7676
#endif
7777
{ 0, UNINIT, MI_OPTION(large_os_pages) }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
7878
{ 0, UNINIT, MI_OPTION(reserve_huge_os_pages) }, // per 1GiB huge pages
79+
{ -1, UNINIT, MI_OPTION(reserve_huge_os_pages_at) }, // reserve huge pages at node N
7980
{ 0, UNINIT, MI_OPTION(reserve_os_memory) },
8081
{ 0, UNINIT, MI_OPTION(segment_cache) }, // cache N segments per thread
8182
{ 1, UNINIT, MI_OPTION(page_reset) }, // reset page memory on free

0 commit comments

Comments
 (0)