From 7af365eb3694b7ef7ce2b90b6de4b830a49cdda4 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 8 Jan 2023 00:05:30 -0500 Subject: [PATCH] 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 --- fs/bcachefs/btree_key_cache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c index 4833cb4c7cf5..53b9f0825ec5 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; } -- 2.25.1