HPA: Fix infinite purging loop

One of the condition to start purging is `hpa_hugify_blocked_by_ndirty`
function call returns true. This can happen in cases where we have no
dirty memory for this shard at all. In this case purging loop will be an
infinite loop.

`hpa_hugify_blocked_by_ndirty` was introduced at 0f6c420, but at that
time purging loop has different form and additional `break` was not
required. Purging loop form was re-written at 6630c5989, but additional
exit condition wasn't added there at the time.

Repo code was shared by Patrik Dokoupil at [1], I stripped it down to
minimum to reproduce issue in jemalloc unit tests.

[1]: https://github.com/jemalloc/jemalloc/pull/2533
This commit is contained in:
Dmitry Ilvokhin 2024-04-04 10:02:08 -07:00 committed by Qi Wang
parent fa451de17f
commit 47d69b4eab
2 changed files with 57 additions and 4 deletions

View file

@ -537,9 +537,16 @@ hpa_shard_maybe_do_deferred_work(tsdn_t *tsdn, hpa_shard_t *shard,
purged = false;
while (hpa_should_purge(tsdn, shard) && nops < max_ops) {
purged = hpa_try_purge(tsdn, shard);
if (purged) {
nops++;
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) {