bcachefs: bch2_btree_key_cache_scan() doesn't need trylock
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 14 Oct 2022 10:48:23 +0000 (06:48 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:44 +0000 (17:09 -0400)
We don't actually allocate memory under the btree key cache lock - so
there's no recursion concerns, and the shrinker can just use
mutex_lock().

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

index b26d4ffe2a11cbe32ac0a0006c2c50a8f6c91b32..be9431dde458b84ed1bb3e77d6939e94e7dcb62b 100644 (file)
@@ -228,6 +228,7 @@ bkey_cached_alloc(struct btree_trans *trans, struct btree_path *path)
                return ck;
        }
 
+       /* GFP_NOFS because we're holding btree locks: */
        ck = kmem_cache_alloc(bch2_key_cache, GFP_NOFS|__GFP_ZERO);
        if (likely(ck)) {
                INIT_LIST_HEAD(&ck->list);
@@ -767,12 +768,7 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
        unsigned start, flags;
        int srcu_idx;
 
-       /* Return -1 if we can't do anything right now */
-       if (sc->gfp_mask & __GFP_FS)
-               mutex_lock(&bc->lock);
-       else if (!mutex_trylock(&bc->lock))
-               return -1;
-
+       mutex_lock(&bc->lock);
        srcu_idx = srcu_read_lock(&c->btree_trans_barrier);
        flags = memalloc_nofs_save();