From e1c38eef76cb8bb3e49a32073c5c579afaae48fa Mon Sep 17 00:00:00 2001 From: daan Date: Thu, 24 Sep 2020 17:20:39 -0700 Subject: [PATCH] use allow_decommit option for both the segment cache and pages --- include/mimalloc.h | 2 +- src/options.c | 4 ++-- src/segment-cache.c | 4 ++-- src/segment.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/mimalloc.h b/include/mimalloc.h index 7b6d5a0b..90e7675d 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -314,7 +314,7 @@ typedef enum mi_option_e { mi_option_eager_commit_delay, mi_option_allow_decommit, mi_option_reset_delay, - mi_option_arena_reset_delay, + mi_option_segment_decommit_delay, mi_option_use_numa_nodes, mi_option_limit_os_alloc, mi_option_os_tag, diff --git a/src/options.c b/src/options.c index f81bb8af..9705a4cc 100644 --- a/src/options.c +++ b/src/options.c @@ -88,8 +88,8 @@ static mi_option_desc_t options[_mi_option_last] = { 1, UNINIT, MI_OPTION(eager_commit_delay) }, // the first N segments per thread are not eagerly committed (but per page in the segment on demand) #endif { 1, UNINIT, MI_OPTION(allow_decommit) }, // decommit slices when no longer used (after reset_delay milli-seconds) - { 500, UNINIT, MI_OPTION(reset_delay) }, // reset delay in milli-seconds - { 1000, UNINIT, MI_OPTION(arena_reset_delay) }, // reset delay in milli-seconds for freed segments + { 500, UNINIT, MI_OPTION(reset_delay) }, // page reset delay in milli-seconds (= decommit) + { 1000, UNINIT, MI_OPTION(segment_decommit_delay) },// decommit delay in milli-seconds for freed segments { 0, UNINIT, MI_OPTION(use_numa_nodes) }, // 0 = use available numa nodes, otherwise use at most N nodes. { 0, UNINIT, MI_OPTION(limit_os_alloc) }, // 1 = do not use OS memory for allocation (but only reserved arenas) { 100, UNINIT, MI_OPTION(os_tag) }, // only apple specific for now but might serve more or less related purpose diff --git a/src/segment-cache.c b/src/segment-cache.c index f1ed5c06..d1f49ab6 100644 --- a/src/segment-cache.c +++ b/src/segment-cache.c @@ -177,8 +177,8 @@ mi_decl_noinline bool _mi_segment_cache_push(void* start, size_t size, size_t me slot->is_pinned = is_pinned; mi_atomic_storei64_relaxed(&slot->expire,(mi_msecs_t)0); slot->commit_mask = commit_mask; - if (!mi_commit_mask_is_empty(commit_mask) && !is_large && !is_pinned) { - long delay = mi_option_get(mi_option_arena_reset_delay); + if (!mi_commit_mask_is_empty(commit_mask) && !is_large && !is_pinned && mi_option_is_enabled(mi_option_allow_decommit)) { + long delay = mi_option_get(mi_option_segment_decommit_delay); if (delay == 0) { _mi_abandoned_await_readers(); // wait until safe to decommit mi_commit_mask_decommit(&slot->commit_mask, start, MI_SEGMENT_SIZE, tld->stats); diff --git a/src/segment.c b/src/segment.c index 8624f7e4..e64f8409 100644 --- a/src/segment.c +++ b/src/segment.c @@ -384,7 +384,7 @@ static bool mi_segment_commitx(mi_segment_t* segment, bool commit, uint8_t* p, s mi_assert_internal((void*)start != (void*)segment); mi_commit_mask_t cmask = mi_commit_mask_intersect(segment->commit_mask, mask); _mi_stat_increase(&_mi_stats_main.committed, full_size - mi_commit_mask_committed_size(cmask, MI_SEGMENT_SIZE)); // adjust for overlap - _mi_os_decommit(start, full_size, stats); // ok if this fails + if (segment->allow_decommit) { _mi_os_decommit(start, full_size, stats); } // ok if this fails mi_commit_mask_clear(&segment->commit_mask, mask); } // increase expiration of reusing part of the delayed decommit @@ -422,7 +422,7 @@ static void mi_segment_perhaps_decommit(mi_segment_t* segment, uint8_t* p, size_ } static void mi_segment_delayed_decommit(mi_segment_t* segment, bool force, mi_stats_t* stats) { - if (mi_commit_mask_is_empty(segment->decommit_mask)) return; + if (!segment->allow_decommit || mi_commit_mask_is_empty(segment->decommit_mask)) return; mi_msecs_t now = _mi_clock_now(); if (!force && now < segment->decommit_expire) return;