Skip to content

Commit e7c8dde

Browse files
committed
fs: simplify rwlock to spinlock
We're not taking the read_lock() anymore now that all lookup is lockless. Just use a simple spinlock. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 4368898 commit e7c8dde

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

fs/namespace.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ static struct kmem_cache *mnt_cache __ro_after_init;
7878
static DECLARE_RWSEM(namespace_sem);
7979
static HLIST_HEAD(unmounted); /* protected by namespace_sem */
8080
static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
81-
static DEFINE_RWLOCK(mnt_ns_tree_lock);
82-
static seqcount_rwlock_t mnt_ns_tree_seqcount = SEQCNT_RWLOCK_ZERO(mnt_ns_tree_seqcount, &mnt_ns_tree_lock);
81+
static DEFINE_SEQLOCK(mnt_ns_tree_lock);
8382

8483
static struct rb_root mnt_ns_tree = RB_ROOT; /* protected by mnt_ns_tree_lock */
8584
static LIST_HEAD(mnt_ns_list); /* protected by mnt_ns_tree_lock */
@@ -131,14 +130,12 @@ static int mnt_ns_cmp(struct rb_node *a, const struct rb_node *b)
131130

132131
static inline void mnt_ns_tree_write_lock(void)
133132
{
134-
write_lock(&mnt_ns_tree_lock);
135-
write_seqcount_begin(&mnt_ns_tree_seqcount);
133+
write_seqlock(&mnt_ns_tree_lock);
136134
}
137135

138136
static inline void mnt_ns_tree_write_unlock(void)
139137
{
140-
write_seqcount_end(&mnt_ns_tree_seqcount);
141-
write_unlock(&mnt_ns_tree_lock);
138+
write_sequnlock(&mnt_ns_tree_lock);
142139
}
143140

144141
static void mnt_ns_tree_add(struct mnt_namespace *ns)
@@ -163,7 +160,7 @@ static void mnt_ns_tree_add(struct mnt_namespace *ns)
163160

164161
static void mnt_ns_release(struct mnt_namespace *ns)
165162
{
166-
lockdep_assert_not_held(&mnt_ns_tree_lock);
163+
lockdep_assert_not_held(&mnt_ns_tree_lock.lock);
167164

168165
/* keep alive for {list,stat}mount() */
169166
if (refcount_dec_and_test(&ns->passive)) {
@@ -225,11 +222,11 @@ static struct mnt_namespace *lookup_mnt_ns(u64 mnt_ns_id)
225222

226223
guard(rcu)();
227224
do {
228-
seq = read_seqcount_begin(&mnt_ns_tree_seqcount);
225+
seq = read_seqbegin(&mnt_ns_tree_lock);
229226
node = rb_find_rcu(&mnt_ns_id, &mnt_ns_tree, mnt_ns_find);
230227
if (node)
231228
break;
232-
} while (read_seqcount_retry(&mnt_ns_tree_seqcount, seq));
229+
} while (read_seqretry(&mnt_ns_tree_lock, seq));
233230

234231
if (!node)
235232
return NULL;

0 commit comments

Comments
 (0)