From: Matthew Wilcox <willy@infradead.org>
To: Ilya Gladyshev <ilya.gladyshev@linux.dev>
Cc: akpm@linux-foundation.org, andrew+netdev@lunn.ch,
apopple@nvidia.com, artem.kuzin@huawei.com,
baolin.wang@linux.alibaba.com, david@kernel.org,
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, torvalds@linuxfoundation.org, vbabka@suse.cz,
yuzhao@google.com, ziy@nvidia.com
Subject: Re: [PATCH v6 3/3] mm: implement page refcount locking via dedicated bit
Date: Fri, 25 Sep 2026 20:38:21 +0100 [thread overview]
Message-ID: <arbNrVX20f2WDJjO@casper.infradead.org> (raw)
In-Reply-To: <ebd6540ad89a4bb80e2a62d00901b5c827315b66.1789239015.git.ilya.gladyshev@linux.dev>
On Sat, Sep 12, 2026 at 10:50:10PM +0300, Ilya Gladyshev wrote:
> This patch reallocates the refcount value range:
>
> (1) refcount < 0 means dead refcount (uninit / frozen)
> (2) refcount = 0 allowed only as a temporary state (see below)
> (3) refcount > 0 is a regular reference count
>
> In other words, refcount is now split into "dead bit" and a 31-bit
> counter.
It seems to me that refcount overflow is now a problem.
We can deliberately increase the refcount on a page by stuffing it into
a pipe. Over and over again. See merge commit 6b3a70773630 and the four
commits on that branch: f958d7b528b1 88b1a17dfc3e 8fde12ca79af 15fab63e1e57
Unfortunately, I think the discussion that led to those commits was
conducted off-list because security. I wish we had a way to declassify
thse emails after the fact.
> +/* Most significant bit in page refcount */
> +#define PAGEREF_FROZEN_BIT BIT(31)
> +
> +/* Page reference counter can be in 3 logical states,
> + * which are described below with their value representation
> + * state | value
> + * (1) safe with owners | 1...INT_MAX
> + * (2) safe with no owners | 0
> + * (3) frozen | INT_MIN....-1
I think we need four states. The first two are the same.
(3) frozen: 0xc000'0000 - 0xffff'ffff
(4) temporarily overflown: 0x8000'0000 - 0xbfff'ffff
(we don't really need that much space for temporary overflow; we could
have something like 0x8100'0000 as the boundary if that works out better)
> static inline bool __page_count_is_frozen(int count)
> {
> - return count == 0;
> + return count & PAGEREF_FROZEN_BIT;
This probably becomes '(unsigned)count >> 30 == 3'. If we choose a
different boundary then something like (unsigned)count >> 24 >= 0x81.
> static inline int page_ref_count(const struct page *page)
> {
> - return atomic_read(&page->_refcount);
> + int val = atomic_read(&page->_refcount);
> +
> + if (unlikely(val & PAGEREF_FROZEN_BIT))
> + return 0;
... use __page_count_is_frozen() here?
and you need to adjust folio_ref_zero_or_close_to_overflow().
try_get_page() can stay as it is.
(Thanks to Pedro for asking me annoying questions about mapcount
overflow which prompted me to look at this again)
next prev parent reply other threads:[~2026-09-25 19:38 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
2026-09-25 7:15 ` David Hildenbrand (Arm)
2026-09-25 19:38 ` Matthew Wilcox [this message]
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=arbNrVX20f2WDJjO@casper.infradead.org \
--to=willy@infradead.org \
--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=ilya.gladyshev@linux.dev \
--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=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®