assertion failed in arc_wait_for_eviction()

If the system is very low on memory (specifically,
`arc_free_memory() < arc_sys_free/2`, i.e. less than 1/16th of RAM
free), `arc_evict_state_impl()` will defer wakups.  In this case, the
arc_evict_waiter_t's remain on the list, even though `arc_evict_count`
has been incremented past their `aew_count`.

The problem is that `arc_wait_for_eviction()` assumes that if there are
waiters on the list, the count they are waiting for has not yet been
reached.  However, the deferred wakeups may violate this, causing
`ASSERT(last->aew_count > arc_evict_count)` to fail.

This commit resolves the issue by having new waiters use the greater of
`arc_evict_count` and the last `aew_count`.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: George Amanakis <gamanakis@gmail.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #11285
Closes #11397
This commit is contained in:
Matthew Ahrens 2021-01-07 20:06:32 -08:00 committed by Brian Behlendorf
parent c32c475363
commit 4e1d1b4b92
1 changed files with 14 additions and 8 deletions

View File

@ -4050,7 +4050,7 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
mutex_enter(&arc_evict_lock); mutex_enter(&arc_evict_lock);
arc_evict_count += bytes_evicted; arc_evict_count += bytes_evicted;
if ((int64_t)(arc_free_memory() - arc_sys_free / 2) > 0) { if (arc_free_memory() > arc_sys_free / 2) {
arc_evict_waiter_t *aw; arc_evict_waiter_t *aw;
while ((aw = list_head(&arc_evict_waiters)) != NULL && while ((aw = list_head(&arc_evict_waiters)) != NULL &&
aw->aew_count <= arc_evict_count) { aw->aew_count <= arc_evict_count) {
@ -5136,14 +5136,20 @@ arc_wait_for_eviction(uint64_t amount)
list_link_init(&aw.aew_node); list_link_init(&aw.aew_node);
cv_init(&aw.aew_cv, NULL, CV_DEFAULT, NULL); cv_init(&aw.aew_cv, NULL, CV_DEFAULT, NULL);
uint64_t last_count = 0;
if (!list_is_empty(&arc_evict_waiters)) {
arc_evict_waiter_t *last = arc_evict_waiter_t *last =
list_tail(&arc_evict_waiters); list_tail(&arc_evict_waiters);
if (last != NULL) { last_count = last->aew_count;
ASSERT3U(last->aew_count, >, arc_evict_count);
aw.aew_count = last->aew_count + amount;
} else {
aw.aew_count = arc_evict_count + amount;
} }
/*
* Note, the last waiter's count may be less than
* arc_evict_count if we are low on memory in which
* case arc_evict_state_impl() may have deferred
* wakeups (but still incremented arc_evict_count).
*/
aw.aew_count =
MAX(last_count, arc_evict_count) + amount;
list_insert_tail(&arc_evict_waiters, &aw); list_insert_tail(&arc_evict_waiters, &aw);