Re: [PATCH v6 3/3] mm: implement page refcount locking via dedicated bit
From: Linus Torvalds
Date: Fri Sep 25 2026 - 15:13:54 EST
On Fri, 25 Sept 2026 at 00:03, Ilya Gladyshev <ilya.gladyshev@xxxxxxxxx> wrote:
>
> Hmmm, I’m afraid that since you need CAS for a safe 1->FR transition,
> it will result in a CAS loop for the decrement itself (like in
> atomic_sub_unless). And this will introduce scalability issues just like
> in folio_try_get(), but this time for everyone...
Note that we could make that CAS case be the thing that only the
special cases do.
IOW, maybe only do that slow sequence in compaction_free() and the
memory offlining.
So we'd have two different cases:
- the high-performance case is ready and willing to accept the "sees
zero" window and the extra 0->FR state that can race with somebody
else taking an optimistic ref
- the unusual slow cases that are *not* willing to deal with
optimistic ref takers do the "CAS 1 -> FR" state atomically and always
use compare-and-exchange for their freeing path
That actually sounds like a good approach to me.
But maybe I'm missing something obvious and it doesn't really solve the issue.
Linus