Skip to content

Commit 657aeb4

Browse files
committed
ns: make all reference counts on initial namespace a nop
They are always active so no need to needlessly cacheline ping-pong. Link: https://patch.msgid.link/20251110-work-namespace-nstree-fixes-v1-12-e8a9264e0fb9@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 3826d5d commit 657aeb4

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

include/linux/ns_common.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static __always_inline __must_check int __ns_ref_active_read(const struct ns_com
6262

6363
static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
6464
{
65+
if (is_ns_init_id(ns))
66+
return false;
6567
if (refcount_dec_and_test(&ns->__ns_ref)) {
6668
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns));
6769
return true;
@@ -71,6 +73,8 @@ static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
7173

7274
static __always_inline __must_check bool __ns_ref_get(struct ns_common *ns)
7375
{
76+
if (is_ns_init_id(ns))
77+
return true;
7478
if (refcount_inc_not_zero(&ns->__ns_ref))
7579
return true;
7680
VFS_WARN_ON_ONCE(__ns_ref_active_read(ns));
@@ -82,12 +86,27 @@ static __always_inline __must_check int __ns_ref_read(const struct ns_common *ns
8286
return refcount_read(&ns->__ns_ref);
8387
}
8488

89+
static __always_inline void __ns_ref_inc(struct ns_common *ns)
90+
{
91+
if (is_ns_init_id(ns))
92+
return;
93+
refcount_inc(&ns->__ns_ref);
94+
}
95+
96+
static __always_inline __must_check bool __ns_ref_dec_and_lock(struct ns_common *ns,
97+
spinlock_t *ns_lock)
98+
{
99+
if (is_ns_init_id(ns))
100+
return false;
101+
return refcount_dec_and_lock(&ns->__ns_ref, ns_lock);
102+
}
103+
85104
#define ns_ref_read(__ns) __ns_ref_read(to_ns_common((__ns)))
86-
#define ns_ref_inc(__ns) refcount_inc(&to_ns_common((__ns))->__ns_ref)
105+
#define ns_ref_inc(__ns) __ns_ref_inc(to_ns_common((__ns)))
87106
#define ns_ref_get(__ns) __ns_ref_get(to_ns_common((__ns)))
88107
#define ns_ref_put(__ns) __ns_ref_put(to_ns_common((__ns)))
89-
#define ns_ref_put_and_lock(__ns, __lock) \
90-
refcount_dec_and_lock(&to_ns_common((__ns))->__ns_ref, (__lock))
108+
#define ns_ref_put_and_lock(__ns, __ns_lock) \
109+
__ns_ref_dec_and_lock(to_ns_common((__ns)), __ns_lock)
91110

92111
#define ns_ref_active_read(__ns) \
93112
((__ns) ? __ns_ref_active_read(to_ns_common(__ns)) : 0)

0 commit comments

Comments
 (0)