> So *some* saving can be achieved without moving stuff out. I thought about that but fowner doesn't need to be in there at all. And then we don't have to care about growing or shrinking the struct, or its padding. > > +struct fown_struct nop_fown_struct = { > > + .lock = __RW_LOCK_UNLOCKED(nop_fown_struct.lock), > > + .pid = NULL, > > + .pid_type = PIDTYPE_MAX, > > + .uid = INVALID_UID, > > + .euid = INVALID_UID, > > + .signum = 0, > > +}; > > why this instead of NULL checking? Dedicated nop types makes it harder to cause accidental NULL dereferences and currently checking whether a signal needs to be sent is predicated on ->pid within fowner not being NULL. Which made a nop type at least a viable option. I don't have a strong opinion. > > + > > +/* > > + * Allocate an file->f_owner struct if it doesn't exist, handling racing > > + * allocations correctly. > > + */ > > +struct fown_struct *file_f_owner_allocate(struct file *file) > > +{ > > + struct fown_struct *f_owner; > > + > > + f_owner = smp_load_acquire(&file->f_owner); > > For all spots of the sort you don't need an acquire fence, a consume > fence is sufficient which I believe in Linux is guaranteed to be > provided with READ_ONCE. I failed to find smp_load_consume, presumably > for that reason. Thanks. > > +struct fown_struct *file_f_owner_allocate(struct file *file) > > +{ > > + struct fown_struct *f_owner; > > + > > + f_owner = smp_load_acquire(&file->f_owner); > > + if (f_owner != &nop_fown_struct) > > + return NULL; > > + > > + f_owner = kzalloc(sizeof(struct fown_struct), GFP_KERNEL); > > + if (!f_owner) > > + return ERR_PTR(-ENOMEM); > > + > > + rwlock_init(&f_owner->lock); > > + f_owner->file = file; > > + /* If someone else raced us, drop our allocation. */ > > + if (unlikely(cmpxchg(&file->f_owner, &nop_fown_struct, f_owner) != > > + &nop_fown_struct)) { > > + kfree(f_owner); > > + return NULL; > > this wants to return the found pointer, not NULL Caller was supposed to only see an allocation if they own it.