From 0a9f51d0d8d2a8135cc853be7ed771230854ede6 Mon Sep 17 00:00:00 2001 From: Dmitry Ilvokhin Date: Fri, 2 Aug 2024 09:35:44 -0700 Subject: [PATCH] Simplify `hpa_shard_maybe_do_deferred_work` It doesn't make much sense to repeat purging once we done with hugification, because we can de-hugify pages that were hugified just moment ago for no good reason. Let them wait next deferred work phase instead. And if they still meeting purging conditions then, purge them. --- src/hpa.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/hpa.c b/src/hpa.c index 49d6b037..27fc1589 100644 --- a/src/hpa.c +++ b/src/hpa.c @@ -532,41 +532,41 @@ hpa_shard_maybe_do_deferred_work(tsdn_t *tsdn, hpa_shard_t *shard, if (!forced && shard->opts.deferral_allowed) { return; } + /* * If we're on a background thread, do work so long as there's work to * be done. Otherwise, bound latency to not be *too* bad by doing at * most a small fixed number of operations. */ - bool hugified = false; - bool purged = false; size_t max_ops = (forced ? (size_t)-1 : 16); size_t nops = 0; - do { - /* - * Always purge before hugifying, to make sure we get some - * ability to hit our quiescence targets. - */ - purged = false; - while (hpa_should_purge(tsdn, shard) && nops < max_ops) { - purged = hpa_try_purge(tsdn, shard); - if (!purged) { - /* - * It is fine if we couldn't purge as sometimes - * we try to purge just to unblock - * hugification, but there is maybe no dirty - * pages at all at the moment. - */ - break; - } - nops++; - } - hugified = hpa_try_hugify(tsdn, shard); - if (hugified) { - nops++; + + /* + * Always purge before hugifying, to make sure we get some + * ability to hit our quiescence targets. + */ + while (hpa_should_purge(tsdn, shard) && nops < max_ops) { + if (!hpa_try_purge(tsdn, shard)) { + /* + * It is fine if we couldn't purge as sometimes + * we try to purge just to unblock + * hugification, but there is maybe no dirty + * pages at all at the moment. + */ + break; } malloc_mutex_assert_owner(tsdn, &shard->mtx); + nops++; + } + + /* + * Try to hugify at least once, even if we out of operations to make at + * least some progress on hugification even at worst case. + */ + while (hpa_try_hugify(tsdn, shard) && nops < max_ops) { malloc_mutex_assert_owner(tsdn, &shard->mtx); - } while ((hugified || purged) && nops < max_ops); + nops++; + } } static edata_t *