Re: [PATCH] futex: Avoid hash-bucket locking for mismatched waits

From: Usama Arif

Date: Mon Aug 10 2026 - 08:42:53 EST




On 08/08/2026 10:19, Thomas Gleixner wrote:
> On Fri, Jul 31 2026 at 12:26, Usama Arif wrote:
>>
>> + /*
>> + * A mismatch here refuses the wait without locating the hash bucket;
>> + * a match is rechecked under the lock below before queueing.
>> + *
>> + * get_futex_key() runs get_user_pages_fast() only for shared futexes,
>> + * so their page is resident and the non-faulting read suffices, with
>> + * the locked path recovering if it does not. A private futex may
>
> That's a fairy tale:
>
> get_futex_key()
> ...
> // shared
> get_user_pages_fast(); // gets a page reference
> ...
> folio = page_folio(page);
> ...
>
> out:
> folio_put(folio); // drops the page reference
>
> Thanks,
>
> tglx

I will fix the comment if the discussion in the other thread hopefully
works out and there is a v2. folio_put() does not immediately evict the
page; however as you point out it removes the guarantee that it stays
available.

get_futex_key() has just resolved the shared page, so a non-faulting
read is "very likely" to succeed. If it doesn't, we get -EFAULT and will
then reach the existing locked check and continues to do what is done
without the patch.