bcachefs: Improve bkey_cached_lock_for_evict()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 8 Jan 2023 05:05:30 +0000 (00:05 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:49 +0000 (17:09 -0400)
We don't need a write lock to check if a key is dirty.

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

index 4833cb4c7cf52ca42de00d9917f2ccf8d491a6e8..53b9f0825ec59594305db8f782b7d7fe7e917031 100644 (file)
@@ -56,13 +56,12 @@ static bool bkey_cached_lock_for_evict(struct bkey_cached *ck)
        if (!six_trylock_intent(&ck->c.lock))
                return false;
 
-       if (!six_trylock_write(&ck->c.lock)) {
+       if (test_bit(BKEY_CACHED_DIRTY, &ck->flags)) {
                six_unlock_intent(&ck->c.lock);
                return false;
        }
 
-       if (test_bit(BKEY_CACHED_DIRTY, &ck->flags)) {
-               six_unlock_write(&ck->c.lock);
+       if (!six_trylock_write(&ck->c.lock)) {
                six_unlock_intent(&ck->c.lock);
                return false;
        }