Skip to content

Commit dc303dc

Browse files
authored
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 <[email protected]> Reviewed-by: George Wilson <[email protected]> Reviewed-by: George Amanakis <[email protected]> Signed-off-by: Matthew Ahrens <[email protected]> Closes #11285 Closes #11397
1 parent f11b09d commit dc303dc

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

module/zfs/arc.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4163,7 +4163,7 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
41634163
mutex_enter(&arc_evict_lock);
41644164
arc_evict_count += bytes_evicted;
41654165

4166-
if ((int64_t)(arc_free_memory() - arc_sys_free / 2) > 0) {
4166+
if (arc_free_memory() > arc_sys_free / 2) {
41674167
arc_evict_waiter_t *aw;
41684168
while ((aw = list_head(&arc_evict_waiters)) != NULL &&
41694169
aw->aew_count <= arc_evict_count) {
@@ -5242,14 +5242,20 @@ arc_wait_for_eviction(uint64_t amount)
52425242
list_link_init(&aw.aew_node);
52435243
cv_init(&aw.aew_cv, NULL, CV_DEFAULT, NULL);
52445244

5245-
arc_evict_waiter_t *last =
5246-
list_tail(&arc_evict_waiters);
5247-
if (last != NULL) {
5248-
ASSERT3U(last->aew_count, >, arc_evict_count);
5249-
aw.aew_count = last->aew_count + amount;
5250-
} else {
5251-
aw.aew_count = arc_evict_count + amount;
5245+
uint64_t last_count = 0;
5246+
if (!list_is_empty(&arc_evict_waiters)) {
5247+
arc_evict_waiter_t *last =
5248+
list_tail(&arc_evict_waiters);
5249+
last_count = last->aew_count;
52525250
}
5251+
/*
5252+
* Note, the last waiter's count may be less than
5253+
* arc_evict_count if we are low on memory in which
5254+
* case arc_evict_state_impl() may have deferred
5255+
* wakeups (but still incremented arc_evict_count).
5256+
*/
5257+
aw.aew_count =
5258+
MAX(last_count, arc_evict_count) + amount;
52535259

52545260
list_insert_tail(&arc_evict_waiters, &aw);
52555261

0 commit comments

Comments
 (0)