[PATCH 2/3] ns: pad refcount

Mateusz Guzik posted 3 patches 1 week, 1 day ago
[PATCH 2/3] ns: pad refcount
Posted by Mateusz Guzik 1 week, 1 day ago
Note no effort is made to make sure structs embedding the namespace are
themselves aligned, so this is not guaranteed to eliminate cacheline
bouncing due to refcount management.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
 include/linux/ns/ns_common_types.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/ns/ns_common_types.h b/include/linux/ns/ns_common_types.h
index b332b019b29c..0014fbc1c626 100644
--- a/include/linux/ns/ns_common_types.h
+++ b/include/linux/ns/ns_common_types.h
@@ -108,11 +108,13 @@ extern const struct proc_ns_operations utsns_operations;
  * @ns_tree: namespace tree nodes and active reference count
  */
 struct ns_common {
+	struct {
+		refcount_t __ns_ref; /* do not use directly */
+	} ____cacheline_aligned_in_smp;
 	u32 ns_type;
 	struct dentry *stashed;
 	const struct proc_ns_operations *ops;
 	unsigned int inum;
-	refcount_t __ns_ref; /* do not use directly */
 	union {
 		struct ns_tree;
 		struct rcu_head ns_rcu;
-- 
2.48.1
Re: [PATCH 2/3] ns: pad refcount
Posted by Oleg Nesterov 1 week, 1 day ago
On 11/23, Mateusz Guzik wrote:
>
>  struct ns_common {
> +	struct {
> +		refcount_t __ns_ref; /* do not use directly */
> +	} ____cacheline_aligned_in_smp;

Cough... stupid question. Why not just

	refcount_t __ns_ref ____cacheline_aligned_in_smp;

? why do we need the anonymous struct?

Oleg.
Re: [PATCH 2/3] ns: pad refcount
Posted by Mateusz Guzik 1 week, 1 day ago
On Sun, Nov 23, 2025 at 7:58 PM Oleg Nesterov <oleg@redhat.com> wrote:
>
> On 11/23, Mateusz Guzik wrote:
> >
> >  struct ns_common {
> > +     struct {
> > +             refcount_t __ns_ref; /* do not use directly */
> > +     } ____cacheline_aligned_in_smp;
>
> Cough... stupid question. Why not just
>
>         refcount_t __ns_ref ____cacheline_aligned_in_smp;
>
> ? why do we need the anonymous struct?
>

This would merely align the offset of the field, with the rest
directly following.
Re: [PATCH 2/3] ns: pad refcount
Posted by Oleg Nesterov 1 week ago
On 11/23, Mateusz Guzik wrote:
>
> On Sun, Nov 23, 2025 at 7:58 PM Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > On 11/23, Mateusz Guzik wrote:
> > >
> > >  struct ns_common {
> > > +     struct {
> > > +             refcount_t __ns_ref; /* do not use directly */
> > > +     } ____cacheline_aligned_in_smp;
> >
> > Cough... stupid question. Why not just
> >
> >         refcount_t __ns_ref ____cacheline_aligned_in_smp;
> >
> > ? why do we need the anonymous struct?
> >
>
> This would merely align the offset of the field, with the rest
> directly following.

Ah. I didn't bother to read the changelog and misunderstood the intent.

OK, thanks. At least I have warned you that my question is stupid ;)

Oleg.