bcachefs: Fix infinite loop in bch2_btree_cache_scan()
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 11 Nov 2021 20:50:22 +0000 (15:50 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:16 +0000 (17:09 -0400)
When attempting to free btree nodes, we might not be able to free all
the nodes that were requested. But the code was looping until it had
freed _all_ the nodes requested, when it should have only been
attempting to free nr nodes.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_cache.c

index 7f5620a..4e855ae 100644 (file)
@@ -309,7 +309,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
 
                touched++;
 
-               if (freed >= nr)
+               if (touched >= nr)
                        break;
 
                if (!btree_node_reclaim(c, b)) {
@@ -323,7 +323,7 @@ restart:
        list_for_each_entry_safe(b, t, &bc->live, list) {
                touched++;
 
-               if (freed >= nr) {
+               if (touched >= nr) {
                        /* Save position */
                        if (&t->list != &bc->live)
                                list_move_tail(&bc->live, &t->list);