]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Merge the condition to avoid additional invocation
authorAlan Huang <mmpgouride@gmail.com>
Wed, 25 Sep 2024 16:45:00 +0000 (00:45 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 14 Jan 2025 15:45:08 +0000 (10:45 -0500)
If the lock has been acquired and unlocked, we don't have to do clear
and wakeup again, though harmless since we hold the intent lock. Merge
the condition might be clearer.

Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/six.c

index 537bf049618fa78b879330591e9275452e7a1e8f..7e7c66a1e1a6baae2c981c53588c95fc7ce88b98 100644 (file)
@@ -491,8 +491,12 @@ static int six_lock_slowpath(struct six_lock *lock, enum six_lock_type type,
                                list_del(&wait->list);
                        raw_spin_unlock(&lock->wait_lock);
 
-                       if (unlikely(acquired))
+                       if (unlikely(acquired)) {
                                do_six_unlock_type(lock, type);
+                       } else if (type == SIX_LOCK_write) {
+                               six_clear_bitmask(lock, SIX_LOCK_HELD_write);
+                               six_lock_wakeup(lock, atomic_read(&lock->state), SIX_LOCK_read);
+                       }
                        break;
                }
 
@@ -501,10 +505,6 @@ static int six_lock_slowpath(struct six_lock *lock, enum six_lock_type type,
 
        __set_current_state(TASK_RUNNING);
 out:
-       if (ret && type == SIX_LOCK_write) {
-               six_clear_bitmask(lock, SIX_LOCK_HELD_write);
-               six_lock_wakeup(lock, atomic_read(&lock->state), SIX_LOCK_read);
-       }
        trace_contention_end(lock, 0);
 
        return ret;