From: Ilya Gladyshev <ilya.gladyshev@linux.dev>
To: Linus Torvalds <torvalds@linuxfoundation.org>
Cc: Zi Yan <ziy@nvidia.com>,
"David Hildenbrand (Arm)" <david@kernel.org>,
akpm@linux-foundation.org, andrew+netdev@lunn.ch,
apopple@nvidia.com, artem.kuzin@huawei.com,
baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com,
edumazet@google.com, harry.yoo@oracle.com,
hramamurthy@google.com, ivgorbunov@me.com, joshwash@google.com,
kirill@shutemov.name, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, lorenzo.stoakes@oracle.com, mhocko@suse.com,
muchun.song@linux.dev, pfalcato@suse.de, rppt@kernel.org,
surenb@google.com, vbabka@suse.cz, willy@infradead.org,
yuzhao@google.com
Subject: Re: [PATCH v6 3/3] mm: implement page refcount locking via dedicated bit
Date: Sat, 26 Sep 2026 01:46:01 +0300 [thread overview]
Message-ID: <58411d37-dd5b-41c2-8b9e-d54939a1119d@linux.dev> (raw)
In-Reply-To: <CAHk-=widZMoVwT+to2PKPfy-y2gERYWdLsZCZvXcz0ZbXYpt9w@mail.gmail.com>
On 9/25/26 22:00, Linus Torvalds wrote:
> On Fri, 25 Sept 2026 at 00:03, Ilya Gladyshev
<ilya.gladyshev@linux.dev> 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.
Cool idea, thanks!
This, however, will still require converting all page_frag_free()
callers to use the generic dispatching dtor (which is __folio_put()
for now), right?
---
Beyond that, I see two trade-offs with my patchset. Neither seems
important for the current kernel code, but I'd like to outline them
anyway.
1. We lose the "high-performance + custom deallocation" scenario
For example, in cases where the current refcount allows you to write
the following:
if (!put_page_testzero()) {
/* We failed to steal the last refcount. However, our refcount is
* already decremented, and therefore we can move forward -- the one
* who stole our page will free it via the generic dispatching dtor.
*/
}
The proposed refcount impl will require either a slow decrement or a
proper (slow) deallocation when put_page_testzero() succeeds. So,
basically, the compaction_free() scenario but with a performance
requirement.
2. Page deallocation becomes unpredictable
With the current refcount impl, if you work with a page of "type X",
you can be sure that folio_put() will perform X-specific actions on
it, and you can make implicit assumptions based on that. This is no
longer true for fast decrements.
---
Ilya Gladyshev // foxido.dev
next prev parent reply other threads:[~2026-09-25 22:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 19:50 [PATCH v6 0/3] mm: improve folio refcount scalability Ilya Gladyshev
2026-09-12 19:50 ` [PATCH v6 1/3] gve: reduce pagecnt_bias to USHRT_MAX Ilya Gladyshev
2026-09-12 19:50 ` [PATCH v6 2/3] mm: drop page refcount zero state semantics Ilya Gladyshev
2026-09-14 9:13 ` Kiryl Shutsemau
2026-09-12 19:50 ` [PATCH v6 3/3] mm: implement page refcount locking via dedicated bit Ilya Gladyshev
2026-09-14 10:39 ` Kiryl Shutsemau
2026-09-15 2:42 ` Zi Yan
2026-09-23 17:34 ` Ilya Gladyshev
2026-09-24 18:51 ` David Hildenbrand (Arm)
2026-09-24 20:06 ` Linus Torvalds
2026-09-25 2:44 ` Zi Yan
2026-09-25 7:03 ` Ilya Gladyshev
2026-09-25 7:06 ` David Hildenbrand (Arm)
2026-09-25 19:00 ` Linus Torvalds
2026-09-25 22:46 ` Ilya Gladyshev [this message]
2026-09-25 7:15 ` David Hildenbrand (Arm)
2026-09-25 19:38 ` Matthew Wilcox
2026-09-25 23:13 ` Ilya Gladyshev
2026-09-14 0:06 ` [PATCH v6 0/3] mm: improve folio refcount scalability Andrew Morton
2026-09-14 8:10 ` Ilya Gladyshev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58411d37-dd5b-41c2-8b9e-d54939a1119d@linux.dev \
--to=ilya.gladyshev@linux.dev \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=andrew+netdev@lunn.ch \
--cc=apopple@nvidia.com \
--cc=artem.kuzin@huawei.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=edumazet@google.com \
--cc=harry.yoo@oracle.com \
--cc=hramamurthy@google.com \
--cc=ivgorbunov@me.com \
--cc=joshwash@google.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=torvalds@linuxfoundation.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=yuzhao@google.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®