Eagerly purge oversized merged extents.
This change improves memory usage slightly, at virtually no CPU cost.
This commit is contained in:
parent
f6c30cbafa
commit
fb56766ca9
@ -135,6 +135,26 @@ arena_decay_tick(tsdn_t *tsdn, arena_t *arena) {
|
||||
arena_decay_ticks(tsdn, arena, 1);
|
||||
}
|
||||
|
||||
/* Purge a single extent to retained / unmapped directly. */
|
||||
JEMALLOC_ALWAYS_INLINE void
|
||||
arena_decay_extent(tsdn_t *tsdn,arena_t *arena, extent_hooks_t **r_extent_hooks,
|
||||
extent_t *extent) {
|
||||
size_t extent_size = extent_size_get(extent);
|
||||
extent_dalloc_wrapper(tsdn, arena,
|
||||
r_extent_hooks, extent);
|
||||
if (config_stats) {
|
||||
/* Update stats accordingly. */
|
||||
arena_stats_lock(tsdn, &arena->stats);
|
||||
arena_stats_add_u64(tsdn, &arena->stats,
|
||||
&arena->decay_dirty.stats->nmadvise, 1);
|
||||
arena_stats_add_u64(tsdn, &arena->stats,
|
||||
&arena->decay_dirty.stats->purged, extent_size >> LG_PAGE);
|
||||
arena_stats_sub_zu(tsdn, &arena->stats, &arena->stats.mapped,
|
||||
extent_size);
|
||||
arena_stats_unlock(tsdn, &arena->stats);
|
||||
}
|
||||
}
|
||||
|
||||
JEMALLOC_ALWAYS_INLINE void *
|
||||
arena_malloc(tsdn_t *tsdn, arena_t *arena, size_t size, szind_t ind, bool zero,
|
||||
tcache_t *tcache, bool slow_path) {
|
||||
|
@ -1708,6 +1708,7 @@ extent_record(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
||||
extent = extent_try_coalesce(tsdn, arena, r_extent_hooks,
|
||||
rtree_ctx, extents, extent, NULL, growing_retained);
|
||||
} else if (extent_size_get(extent) >= SC_LARGE_MINCLASS) {
|
||||
assert(extents == &arena->extents_dirty);
|
||||
/* Always coalesce large extents eagerly. */
|
||||
bool coalesced;
|
||||
do {
|
||||
@ -1716,6 +1717,12 @@ extent_record(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
|
||||
r_extent_hooks, rtree_ctx, extents, extent,
|
||||
&coalesced, growing_retained);
|
||||
} while (coalesced);
|
||||
if (extent_size_get(extent) >= oversize_threshold) {
|
||||
/* Shortcut to purge the oversize extent eagerly. */
|
||||
malloc_mutex_unlock(tsdn, &extents->mtx);
|
||||
arena_decay_extent(tsdn, arena, r_extent_hooks, extent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
extent_deactivate_locked(tsdn, arena, extents, extent);
|
||||
|
||||
|
@ -121,6 +121,12 @@ get_arena_dirty_npurge(unsigned arena_ind) {
|
||||
return get_arena_npurge_impl("stats.arenas.0.dirty_npurge", arena_ind);
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
get_arena_dirty_purged(unsigned arena_ind) {
|
||||
do_epoch();
|
||||
return get_arena_npurge_impl("stats.arenas.0.dirty_purged", arena_ind);
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
get_arena_muzzy_npurge(unsigned arena_ind) {
|
||||
do_epoch();
|
||||
@ -559,7 +565,7 @@ TEST_BEGIN(test_decay_now) {
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_decay_never) {
|
||||
test_skip_if(check_background_thread_enabled());
|
||||
test_skip_if(check_background_thread_enabled() || !config_stats);
|
||||
|
||||
unsigned arena_ind = do_arena_create(-1, -1);
|
||||
int flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
@ -579,8 +585,8 @@ TEST_BEGIN(test_decay_never) {
|
||||
dallocx(ptrs[i], flags);
|
||||
size_t pdirty = get_arena_pdirty(arena_ind);
|
||||
size_t pmuzzy = get_arena_pmuzzy(arena_ind);
|
||||
assert_zu_gt(pdirty, pdirty_prev,
|
||||
"Expected dirty pages to increase.");
|
||||
assert_zu_gt(pdirty + (size_t)get_arena_dirty_purged(arena_ind),
|
||||
pdirty_prev, "Expected dirty pages to increase.");
|
||||
assert_zu_eq(pmuzzy, 0, "Unexpected muzzy pages");
|
||||
pdirty_prev = pdirty;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user