Re: [RFC 1/1] rwsem: Shrink rwsem by one pointer
From: Matthew Wilcox
Date: Wed Feb 18 2026 - 18:06:17 EST
On Wed, Feb 18, 2026 at 05:47:52PM -0500, Waiman Long wrote:
> On 2/17/26 2:08 PM, Matthew Wilcox (Oracle) wrote:
> > Instead of embedding a list_head in struct rw_semaphore, store a pointer
> > to the first waiter. The list of waiters remains a doubly linked list
> > so we can efficiently add to the tail of the list, remove from the front
> > (or middle) of the list.
> >
> > Some of the list manipulation becomes more complicated, but it's a
> > reasonable tradeoff on the slow paths to shrink some core data structures
> > like struct inode.
>
> If the goal is to use only one pointer for the rwsem structure, would it
> make sense to change list_head to hlist_head for instance? At least we have
> existing helpers that can be used instead of making our own coding
> convention here.
There's no hlist_add_tail(), and obviously there can't be.
hlist_head.first = node1
node1.pprev = hlist_head.first
node1.next = node2
node2.pprev = node1
node2.next = NULL
now we want to add node3 to the tail. there's no pointer to it, we have
to walk the entire chain to find out where to put it.
Whereas with this scheme, we can put it at ->first_waiter.prev. If you
want to generalise this way to use list_head, be my guest, but I don't
want to do that work (and I don't want this patch to get held up behind
a "boil the ocean" approach).