From: Kent Overstreet Date: Sun, 8 Jan 2023 05:05:30 +0000 (-0500) Subject: bcachefs: Improve bkey_cached_lock_for_evict() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=7af365eb3694b7ef7ce2b90b6de4b830a49cdda4;p=linux.git bcachefs: Improve bkey_cached_lock_for_evict() We don't need a write lock to check if a key is dirty. Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c index 4833cb4c7cf52..53b9f0825ec59 100644 --- a/fs/bcachefs/btree_key_cache.c +++ b/fs/bcachefs/btree_key_cache.c @@ -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; }