mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 23:19:31 +03:00
add environment option mi_reserve_os_memory
This commit is contained in:
parent
364674185e
commit
8607ff617c
3 changed files with 16 additions and 2 deletions
|
@ -304,6 +304,7 @@ typedef enum mi_option_e {
|
||||||
mi_option_reset_decommits,
|
mi_option_reset_decommits,
|
||||||
mi_option_large_os_pages, // implies eager commit
|
mi_option_large_os_pages, // implies eager commit
|
||||||
mi_option_reserve_huge_os_pages,
|
mi_option_reserve_huge_os_pages,
|
||||||
|
mi_option_reserve_os_memory,
|
||||||
mi_option_segment_cache,
|
mi_option_segment_cache,
|
||||||
mi_option_page_reset,
|
mi_option_page_reset,
|
||||||
mi_option_abandoned_page_reset,
|
mi_option_abandoned_page_reset,
|
||||||
|
|
|
@ -478,7 +478,11 @@ void mi_process_init(void) mi_attr_noexcept {
|
||||||
if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
|
if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
|
||||||
size_t pages = mi_option_get(mi_option_reserve_huge_os_pages);
|
size_t pages = mi_option_get(mi_option_reserve_huge_os_pages);
|
||||||
mi_reserve_huge_os_pages_interleave(pages, 0, pages*500);
|
mi_reserve_huge_os_pages_interleave(pages, 0, pages*500);
|
||||||
}
|
}
|
||||||
|
if (mi_option_is_enabled(mi_option_reserve_os_memory)) {
|
||||||
|
long ksize = mi_option_get(mi_option_reserve_os_memory);
|
||||||
|
if (ksize > 0) mi_reserve_os_memory((size_t)ksize*KiB, true, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the process is done (through `at_exit`)
|
// Called when the process is done (through `at_exit`)
|
||||||
|
|
|
@ -74,7 +74,8 @@ static mi_option_desc_t options[_mi_option_last] =
|
||||||
{ 0, UNINIT, MI_OPTION(reset_decommits) }, // reset uses MADV_FREE/MADV_DONTNEED
|
{ 0, UNINIT, MI_OPTION(reset_decommits) }, // reset uses MADV_FREE/MADV_DONTNEED
|
||||||
#endif
|
#endif
|
||||||
{ 0, UNINIT, MI_OPTION(large_os_pages) }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
|
{ 0, UNINIT, MI_OPTION(large_os_pages) }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
|
||||||
{ 0, UNINIT, MI_OPTION(reserve_huge_os_pages) },
|
{ 0, UNINIT, MI_OPTION(reserve_huge_os_pages) }, // per 1GiB huge pages
|
||||||
|
{ 0, UNINIT, MI_OPTION(reserve_os_memory) },
|
||||||
{ 0, UNINIT, MI_OPTION(segment_cache) }, // cache N segments per thread
|
{ 0, UNINIT, MI_OPTION(segment_cache) }, // cache N segments per thread
|
||||||
{ 1, UNINIT, MI_OPTION(page_reset) }, // reset page memory on free
|
{ 1, UNINIT, MI_OPTION(page_reset) }, // reset page memory on free
|
||||||
{ 0, UNINIT, MI_OPTION(abandoned_page_reset) },// reset free page memory when a thread terminates
|
{ 0, UNINIT, MI_OPTION(abandoned_page_reset) },// reset free page memory when a thread terminates
|
||||||
|
@ -504,6 +505,14 @@ static void mi_option_init(mi_option_desc_t* desc) {
|
||||||
else {
|
else {
|
||||||
char* end = buf;
|
char* end = buf;
|
||||||
long value = strtol(buf, &end, 10);
|
long value = strtol(buf, &end, 10);
|
||||||
|
if (desc->option == mi_option_reserve_os_memory) {
|
||||||
|
// this option is interpreted in KiB to prevent overflow of `long`
|
||||||
|
if (*end == 'K') { end++; }
|
||||||
|
else if (*end == 'M') { value *= KiB; end++; }
|
||||||
|
else if (*end == 'G') { value *= MiB; end++; }
|
||||||
|
else { value = (value + KiB - 1) / KiB; }
|
||||||
|
if (*end == 'B') { end++; }
|
||||||
|
}
|
||||||
if (*end == 0) {
|
if (*end == 0) {
|
||||||
desc->value = value;
|
desc->value = value;
|
||||||
desc->init = INITIALIZED;
|
desc->init = INITIALIZED;
|
||||||
|
|
Loading…
Add table
Reference in a new issue