Re: [RFC 1/1] rwsem: Shrink rwsem by one pointer

From: Linus Torvalds

Date: Wed Feb 18 2026 - 17:46:12 EST


Oh, I already said "this looks good", but I take it back. Looking a
bit closer, I noticed a problem:

On Wed, 18 Feb 2026 at 13:00, Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:
>
> @@ -612,8 +594,6 @@ rwsem_del_wake_waiter(struct rw_semaphore *sem, struct rwsem_waiter *waiter,
> struct wake_q_head *wake_q)
> __releases(&sem->wait_lock)
> {
> - bool first = rwsem_first_waiter(sem) == waiter;
> -
> wake_q_init(wake_q);
>
> /*
> @@ -621,7 +601,7 @@ rwsem_del_wake_waiter(struct rw_semaphore *sem, struct rwsem_waiter *waiter,
> * the first waiter, we wake up the remaining waiters as they may
> * be eligible to acquire or spin on the lock.
> */
> - if (rwsem_del_waiter(sem, waiter) && first)
> + if (rwsem_del_waiter(sem, waiter) && sem->first_waiter == waiter)
> rwsem_mark_wake(sem, RWSEM_WAKE_ANY, wake_q);

This looks wrong.

Notice how "first" used to be done before deletion.

How it's doing that

sem->first_waiter == waiter

test *after* the deletion, which makes no sense at all, and will never
trigger, afaik.

I think that "&& first" was always pointless, because
rwsem_del_waiter() would only return true if it was the only waiter,
and if it was the only waiter then it was first by definition. But now
it's gone from "pointless" to "actively wrong", because now that
"first" test will be false.

So I think the whole test should just be deleted. The return value of
rwsem_del_waiter() is already the right value.

Anyway, this is all from just looking at the patch, so maybe I missed
something, but it does look very wrong.

Linus