mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-08-24 00:04:48 +03:00
remove reset_decommits option
This commit is contained in:
parent
d2279b2a3f
commit
83a066fd2d
4 changed files with 19 additions and 39 deletions
|
@ -272,9 +272,8 @@ typedef enum mi_option_e {
|
||||||
mi_option_segment_cache,
|
mi_option_segment_cache,
|
||||||
mi_option_page_reset,
|
mi_option_page_reset,
|
||||||
mi_option_cache_reset,
|
mi_option_cache_reset,
|
||||||
mi_option_reset_decommits,
|
|
||||||
mi_option_eager_commit_delay,
|
|
||||||
mi_option_segment_reset,
|
mi_option_segment_reset,
|
||||||
|
mi_option_eager_commit_delay,
|
||||||
mi_option_os_tag,
|
mi_option_os_tag,
|
||||||
mi_option_max_numa_node,
|
mi_option_max_numa_node,
|
||||||
mi_option_max_errors,
|
mi_option_max_errors,
|
||||||
|
|
28
src/memory.c
28
src/memory.c
|
@ -350,12 +350,12 @@ void _mi_mem_free(void* p, size_t size, size_t id, mi_stats_t* stats) {
|
||||||
mi_assert_internal(size <= MI_REGION_MAX_OBJ_SIZE); if (size > MI_REGION_MAX_OBJ_SIZE) return;
|
mi_assert_internal(size <= MI_REGION_MAX_OBJ_SIZE); if (size > MI_REGION_MAX_OBJ_SIZE) return;
|
||||||
// we can align the size up to page size (as we allocate that way too)
|
// we can align the size up to page size (as we allocate that way too)
|
||||||
// this ensures we fully commit/decommit/reset
|
// this ensures we fully commit/decommit/reset
|
||||||
size = _mi_align_up(size, _mi_os_page_size());
|
size = _mi_align_up(size, _mi_os_page_size());
|
||||||
const size_t blocks = mi_region_block_count(size);
|
const size_t blocks = mi_region_block_count(size);
|
||||||
mi_region_info_t info = mi_atomic_read(®ion->info);
|
mi_region_info_t info = mi_atomic_read(®ion->info);
|
||||||
bool is_large;
|
bool is_large;
|
||||||
bool is_eager_committed;
|
bool is_committed;
|
||||||
void* start = mi_region_info_read(info,&is_large,&is_eager_committed);
|
void* start = mi_region_info_read(info, &is_large, &is_committed);
|
||||||
mi_assert_internal(start != NULL);
|
mi_assert_internal(start != NULL);
|
||||||
void* blocks_start = (uint8_t*)start + (bit_idx * MI_SEGMENT_SIZE);
|
void* blocks_start = (uint8_t*)start + (bit_idx * MI_SEGMENT_SIZE);
|
||||||
mi_assert_internal(blocks_start == p); // not a pointer in our area?
|
mi_assert_internal(blocks_start == p); // not a pointer in our area?
|
||||||
|
@ -366,18 +366,14 @@ void _mi_mem_free(void* p, size_t size, size_t id, mi_stats_t* stats) {
|
||||||
// TODO: implement delayed decommit/reset as these calls are too expensive
|
// TODO: implement delayed decommit/reset as these calls are too expensive
|
||||||
// if the memory is reused soon.
|
// if the memory is reused soon.
|
||||||
// reset: 10x slowdown on malloc-large, decommit: 17x slowdown on malloc-large
|
// reset: 10x slowdown on malloc-large, decommit: 17x slowdown on malloc-large
|
||||||
if (!is_large) {
|
if (!is_large &&
|
||||||
if (mi_option_is_enabled(mi_option_segment_reset)) {
|
mi_option_is_enabled(mi_option_segment_reset) &&
|
||||||
if (!is_eager_committed && // cannot reset large pages
|
mi_option_is_enabled(mi_option_eager_commit)) // cannot reset halfway committed segments, use `option_page_reset` instead
|
||||||
(mi_option_is_enabled(mi_option_eager_commit) || // cannot reset halfway committed segments, use `option_page_reset` instead
|
{
|
||||||
mi_option_is_enabled(mi_option_reset_decommits))) // but we can decommit halfway committed segments
|
_mi_os_reset(p, size, stats);
|
||||||
{
|
//_mi_os_decommit(p, size, stats); // todo: and clear dirty bits?
|
||||||
_mi_os_reset(p, size, stats);
|
}
|
||||||
//_mi_os_decommit(p, size, stats); // todo: and clear dirty bits?
|
if (!is_committed) {
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!is_eager_committed) {
|
|
||||||
// adjust commit statistics as we commit again when re-using the same slot
|
// adjust commit statistics as we commit again when re-using the same slot
|
||||||
_mi_stat_decrease(&stats->committed, mi_good_commit_size(size));
|
_mi_stat_decrease(&stats->committed, mi_good_commit_size(size));
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,11 +65,10 @@ static mi_option_desc_t options[_mi_option_last] =
|
||||||
{ 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) },
|
||||||
{ 0, UNINIT, MI_OPTION(segment_cache) }, // cache N segments per thread
|
{ 0, UNINIT, MI_OPTION(segment_cache) }, // cache N segments per thread
|
||||||
{ 0, UNINIT, MI_OPTION(page_reset) },
|
{ 1, UNINIT, MI_OPTION(page_reset) },
|
||||||
{ 0, UNINIT, MI_OPTION(cache_reset) },
|
{ 0, UNINIT, MI_OPTION(cache_reset) },
|
||||||
{ 0, UNINIT, MI_OPTION(reset_decommits) }, // note: cannot enable this if secure is on
|
|
||||||
{ 0, UNINIT, MI_OPTION(eager_commit_delay) }, // the first N segments per thread are not eagerly committed
|
|
||||||
{ 0, UNINIT, MI_OPTION(segment_reset) }, // reset segment memory on free (needs eager commit)
|
{ 0, UNINIT, MI_OPTION(segment_reset) }, // reset segment memory on free (needs eager commit)
|
||||||
|
{ 0, UNINIT, MI_OPTION(eager_commit_delay) }, // the first N segments per thread are not eagerly committed
|
||||||
{ 100, UNINIT, MI_OPTION(os_tag) }, // only apple specific for now but might serve more or less related purpose
|
{ 100, UNINIT, MI_OPTION(os_tag) }, // only apple specific for now but might serve more or less related purpose
|
||||||
{ 256, UNINIT, MI_OPTION(max_numa_node) }, // maximum allowed numa node
|
{ 256, UNINIT, MI_OPTION(max_numa_node) }, // maximum allowed numa node
|
||||||
{ 16, UNINIT, MI_OPTION(max_errors) } // maximum errors that are output
|
{ 16, UNINIT, MI_OPTION(max_errors) } // maximum errors that are output
|
||||||
|
@ -88,7 +87,7 @@ void _mi_options_init(void) {
|
||||||
mi_option_desc_t* desc = &options[option];
|
mi_option_desc_t* desc = &options[option];
|
||||||
_mi_verbose_message("option '%s': %ld\n", desc->name, desc->value);
|
_mi_verbose_message("option '%s': %ld\n", desc->name, desc->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mi_max_error_count = mi_option_get(mi_option_max_errors);
|
mi_max_error_count = mi_option_get(mi_option_max_errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
src/os.c
20
src/os.c
|
@ -646,10 +646,6 @@ bool _mi_os_decommit(void* addr, size_t size, mi_stats_t* stats) {
|
||||||
return mi_os_commitx(addr, size, false, true /* conservative? */, &is_zero, stats);
|
return mi_os_commitx(addr, size, false, true /* conservative? */, &is_zero, stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _mi_os_commit_unreset(void* addr, size_t size, bool* is_zero, mi_stats_t* stats) {
|
|
||||||
return mi_os_commitx(addr, size, true, true /* conservative? */, is_zero, stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Signal to the OS that the address range is no longer in use
|
// Signal to the OS that the address range is no longer in use
|
||||||
// but may be used later again. This will release physical memory
|
// but may be used later again. This will release physical memory
|
||||||
|
@ -708,22 +704,12 @@ static bool mi_os_resetx(void* addr, size_t size, bool reset, mi_stats_t* stats)
|
||||||
// pages and reduce swapping while keeping the memory committed.
|
// pages and reduce swapping while keeping the memory committed.
|
||||||
// We page align to a conservative area inside the range to reset.
|
// We page align to a conservative area inside the range to reset.
|
||||||
bool _mi_os_reset(void* addr, size_t size, mi_stats_t* stats) {
|
bool _mi_os_reset(void* addr, size_t size, mi_stats_t* stats) {
|
||||||
if (mi_option_is_enabled(mi_option_reset_decommits)) {
|
return mi_os_resetx(addr, size, true, stats);
|
||||||
return _mi_os_decommit(addr,size,stats);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return mi_os_resetx(addr, size, true, stats);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _mi_os_unreset(void* addr, size_t size, bool* is_zero, mi_stats_t* stats) {
|
bool _mi_os_unreset(void* addr, size_t size, bool* is_zero, mi_stats_t* stats) {
|
||||||
if (mi_option_is_enabled(mi_option_reset_decommits)) {
|
*is_zero = false;
|
||||||
return _mi_os_commit_unreset(addr, size, is_zero, stats); // re-commit it (conservatively!)
|
return mi_os_resetx(addr, size, false, stats);
|
||||||
}
|
|
||||||
else {
|
|
||||||
*is_zero = false;
|
|
||||||
return mi_os_resetx(addr, size, false, stats);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue