Skip to content

Commit 4e1d1b4

Browse files
ahrensbehlendorf
authored andcommitted
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 c32c475 commit 4e1d1b4

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
@@ -4050,7 +4050,7 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
40504050
mutex_enter(&arc_evict_lock);
40514051
arc_evict_count += bytes_evicted;
40524052

4053-
if ((int64_t)(arc_free_memory() - arc_sys_free / 2) > 0) {
4053+
if (arc_free_memory() > arc_sys_free / 2) {
40544054
arc_evict_waiter_t *aw;
40554055
while ((aw = list_head(&arc_evict_waiters)) != NULL &&
40564056
aw->aew_count <= arc_evict_count) {
@@ -5136,14 +5136,20 @@ arc_wait_for_eviction(uint64_t amount)
51365136
list_link_init(&aw.aew_node);
51375137
cv_init(&aw.aew_cv, NULL, CV_DEFAULT, NULL);
51385138

5139-
arc_evict_waiter_t *last =
5140-
list_tail(&arc_evict_waiters);
5141-
if (last != NULL) {
5142-
ASSERT3U(last->aew_count, >, arc_evict_count);
5143-
aw.aew_count = last->aew_count + amount;
5144-
} else {
5145-
aw.aew_count = arc_evict_count + amount;
5139+
uint64_t last_count = 0;
5140+
if (!list_is_empty(&arc_evict_waiters)) {
5141+
arc_evict_waiter_t *last =
5142+
list_tail(&arc_evict_waiters);
5143+
last_count = last->aew_count;
51465144
}
5145+
/*
5146+
* Note, the last waiter's count may be less than
5147+
* arc_evict_count if we are low on memory in which
5148+
* case arc_evict_state_impl() may have deferred
5149+
* wakeups (but still incremented arc_evict_count).
5150+
*/
5151+
aw.aew_count =
5152+
MAX(last_count, arc_evict_count) + amount;
51475153

51485154
list_insert_tail(&arc_evict_waiters, &aw);
51495155

0 commit comments

Comments
 (0)