Commit 05a49d22 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Make bch2_btree_cache_scan() try harder

Previously, when bch2_btree_cache_scan() attempted to reclaim a node but
failed (because trylock failed, because it was dirty, etc.), it would
count that against the number of nodes it was scanning and attempting to
free. This patch changes that behaviour, so that now we only count nodes
that we then don't free if they have the accessed bit (which we also
clear).
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent e0c014e7
...@@ -327,17 +327,13 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, ...@@ -327,17 +327,13 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
} }
restart: restart:
list_for_each_entry_safe(b, t, &bc->live, list) { list_for_each_entry_safe(b, t, &bc->live, list) {
touched++; /* tweak this */
if (btree_node_accessed(b)) {
if (touched >= nr) { clear_btree_node_accessed(b);
/* Save position */ goto touched;
if (&t->list != &bc->live)
list_move_tail(&bc->live, &t->list);
break;
} }
if (!btree_node_accessed(b) && if (!btree_node_reclaim(c, b)) {
!btree_node_reclaim(c, b)) {
/* can't call bch2_btree_node_hash_remove under lock */ /* can't call bch2_btree_node_hash_remove under lock */
freed++; freed++;
if (&t->list != &bc->live) if (&t->list != &bc->live)
...@@ -358,8 +354,18 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, ...@@ -358,8 +354,18 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
else if (!mutex_trylock(&bc->lock)) else if (!mutex_trylock(&bc->lock))
goto out; goto out;
goto restart; goto restart;
} else } else {
clear_btree_node_accessed(b); continue;
}
touched:
touched++;
if (touched >= nr) {
/* Save position */
if (&t->list != &bc->live)
list_move_tail(&bc->live, &t->list);
break;
}
} }
mutex_unlock(&bc->lock); mutex_unlock(&bc->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment