bcachefs: Inline bch2_two_state_(trylock|unlock)
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 23 Nov 2022 17:22:39 +0000 (12:22 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:51 +0000 (17:09 -0400)
Standard inlining of fast paths - these locks are now used by our new
nocow mode.

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

index 8f06e08370a260b724805d7663af152e792cd670..b325fb105322a8393587813d9852bcbd652ebb4f 100644 (file)
@@ -10,6 +10,6 @@ void __bch2_bucket_nocow_lock(struct bucket_nocow_lock_table *t,
        struct bch_fs *c = container_of(t, struct bch_fs, nocow_locks);
        u64 start_time = local_clock();
 
-       bch2_two_state_lock(l, flags & BUCKET_NOCOW_LOCK_UPDATE);
+       __bch2_two_state_lock(l, flags & BUCKET_NOCOW_LOCK_UPDATE);
        bch2_time_stats_update(&c->times[BCH_TIME_nocow_lock_contended], start_time);
 }
index dc508d545de0577fbae077355c842f923db2c950..9764c2e6a9102658c2bc8181d82790070c2001a9 100644 (file)
@@ -2,32 +2,7 @@
 
 #include "two_state_shared_lock.h"
 
-void bch2_two_state_unlock(two_state_lock_t *lock, int s)
+void __bch2_two_state_lock(two_state_lock_t *lock, int s)
 {
-       long i = s ? 1 : -1;
-
-       BUG_ON(atomic_long_read(&lock->v) == 0);
-
-       if (atomic_long_sub_return_release(i, &lock->v) == 0)
-               wake_up_all(&lock->wait);
-}
-
-bool bch2_two_state_trylock(two_state_lock_t *lock, int s)
-{
-       long i = s ? 1 : -1;
-       long v = atomic_long_read(&lock->v), old;
-
-       do {
-               old = v;
-
-               if (i > 0 ? v < 0 : v > 0)
-                       return false;
-       } while ((v = atomic_long_cmpxchg_acquire(&lock->v,
-                                       old, old + i)) != old);
-       return true;
-}
-
-void bch2_two_state_lock(two_state_lock_t *lock, int s)
-{
-       wait_event(lock->wait, bch2_two_state_trylock(lock, s));
+       __wait_event(lock->wait, bch2_two_state_trylock(lock, s));
 }
index 1b4f108908a1cb3331546d4031fe022e192b3d21..9058017720025a8f1e0f0d21b8965c70080b4fe1 100644 (file)
@@ -6,6 +6,8 @@
 #include <linux/sched.h>
 #include <linux/wait.h>
 
+#include "util.h"
+
 /*
  * Two-state lock - can be taken for add or block - both states are shared,
  * like read side of rwsem, but conflict with other state:
@@ -21,8 +23,37 @@ static inline void two_state_lock_init(two_state_lock_t *lock)
        init_waitqueue_head(&lock->wait);
 }
 
-void bch2_two_state_unlock(two_state_lock_t *, int);
-bool bch2_two_state_trylock(two_state_lock_t *, int);
-void bch2_two_state_lock(two_state_lock_t *, int);
+static inline void bch2_two_state_unlock(two_state_lock_t *lock, int s)
+{
+       long i = s ? 1 : -1;
+
+       EBUG_ON(atomic_long_read(&lock->v) == 0);
+
+       if (atomic_long_sub_return_release(i, &lock->v) == 0)
+               wake_up_all(&lock->wait);
+}
+
+static inline bool bch2_two_state_trylock(two_state_lock_t *lock, int s)
+{
+       long i = s ? 1 : -1;
+       long v = atomic_long_read(&lock->v), old;
+
+       do {
+               old = v;
+
+               if (i > 0 ? v < 0 : v > 0)
+                       return false;
+       } while ((v = atomic_long_cmpxchg_acquire(&lock->v,
+                                       old, old + i)) != old);
+       return true;
+}
+
+void __bch2_two_state_lock(two_state_lock_t *, int);
+
+static inline void bch2_two_state_lock(two_state_lock_t *lock, int s)
+{
+       if (!bch2_two_state_trylock(lock, s))
+               __bch2_two_state_lock(lock, s);
+}
 
 #endif /* _BCACHEFS_TWO_STATE_LOCK_H */