mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 15:09:31 +03:00
add environment option to reserve huge pages upfront
This commit is contained in:
parent
741f37e1f0
commit
0e639addb0
4 changed files with 10 additions and 1 deletions
|
@ -228,6 +228,7 @@ typedef enum mi_option_e {
|
||||||
mi_option_eager_commit,
|
mi_option_eager_commit,
|
||||||
mi_option_eager_region_commit,
|
mi_option_eager_region_commit,
|
||||||
mi_option_large_os_pages, // implies eager commit
|
mi_option_large_os_pages, // implies eager commit
|
||||||
|
mi_option_reserve_huge_os_pages,
|
||||||
mi_option_page_reset,
|
mi_option_page_reset,
|
||||||
mi_option_cache_reset,
|
mi_option_cache_reset,
|
||||||
mi_option_reset_decommits,
|
mi_option_reset_decommits,
|
||||||
|
|
|
@ -422,6 +422,12 @@ static void mi_process_load(void) {
|
||||||
const char* msg = NULL;
|
const char* msg = NULL;
|
||||||
mi_allocator_init(&msg);
|
mi_allocator_init(&msg);
|
||||||
if (msg != NULL) _mi_verbose_message(msg);
|
if (msg != NULL) _mi_verbose_message(msg);
|
||||||
|
|
||||||
|
if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
|
||||||
|
size_t pages = mi_option_get(mi_option_reserve_huge_os_pages);
|
||||||
|
double max_secs = (double)pages / 10.0; // 0.1s per page
|
||||||
|
mi_reserve_huge_os_pages(pages, max_secs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the process; called by thread_init or the process loader
|
// Initialize the process; called by thread_init or the process loader
|
||||||
|
|
|
@ -58,6 +58,7 @@ static mi_option_desc_t options[_mi_option_last] =
|
||||||
{ 1, UNINIT, "eager_region_commit" },
|
{ 1, UNINIT, "eager_region_commit" },
|
||||||
#endif
|
#endif
|
||||||
{ 0, UNINIT, "large_os_pages" }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
|
{ 0, UNINIT, "large_os_pages" }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
|
||||||
|
{ 0, UNINIT, "reserve_huge_os_pages" },
|
||||||
{ 0, UNINIT, "page_reset" },
|
{ 0, UNINIT, "page_reset" },
|
||||||
{ 0, UNINIT, "cache_reset" },
|
{ 0, UNINIT, "cache_reset" },
|
||||||
{ 0, UNINIT, "reset_decommits" }, // note: cannot enable this if secure is on
|
{ 0, UNINIT, "reset_decommits" }, // note: cannot enable this if secure is on
|
||||||
|
|
3
src/os.c
3
src/os.c
|
@ -108,7 +108,7 @@ void _mi_os_init(void) {
|
||||||
}
|
}
|
||||||
// Try to see if large OS pages are supported
|
// Try to see if large OS pages are supported
|
||||||
unsigned long err = 0;
|
unsigned long err = 0;
|
||||||
bool ok = mi_option_is_enabled(mi_option_large_os_pages);
|
bool ok = mi_option_is_enabled(mi_option_large_os_pages) || mi_option_is_enabled(mi_option_reserve_huge_os_pages);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// To use large pages on Windows, we first need access permission
|
// To use large pages on Windows, we first need access permission
|
||||||
// Set "Lock pages in memory" permission in the group policy editor
|
// Set "Lock pages in memory" permission in the group policy editor
|
||||||
|
@ -788,6 +788,7 @@ int mi_reserve_huge_os_pages( size_t pages, double max_secs ) mi_attr_noexcept
|
||||||
if (estimate > 1.5*max_secs) return (-1); // seems like we are going to timeout
|
if (estimate > 1.5*max_secs) return (-1); // seems like we are going to timeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_mi_verbose_message("reserved %zu huge pages\n", pages);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue