From: Linus Torvalds <torvalds@linuxfoundation.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Gladyshev Ilya <gladyshev.ilya1@h-partners.com>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Zi Yan <ziy@nvidia.com>,
Harry Yoo <harry.yoo@oracle.com>,
Matthew Wilcox <willy@infradead.org>,
Yu Zhao <yuzhao@google.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
Gorbunov Ivan <gorbunov.ivan@h-partners.com>,
Muchun Song <muchun.song@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Kiryl Shutsemau <kirill@shutemov.name>,
Dave Chinner <david@fromorbit.com>
Subject: Re: [PATCH 0/1] mm: improve folio refcount scalability
Date: Sun, 1 Mar 2026 10:52:57 -0800 [thread overview]
Message-ID: <CAHk-=wgOxtAFf5XeYTcoUHSpWfMrgZaXKc_hrmqt6yKBdr=3Zw@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wgfs7KqS8pD8F9F9yC8jwSgQtmifytbmmXVfz9xXrQzuw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 922 bytes --]
On Sat, 28 Feb 2026 at 19:27, Linus Torvalds
<torvalds@linuxfoundation.org> wrote:
>
> This attached patch is ENTIRELY UNTESTED.
Here's a slightly cleaned up and further simplified version, which is
also actually tested, although only in the "it boots for me" sense.
It generates good code at least with clang:
.LBB76_7:
movl $1, %eax
.LBB76_8:
leal 1(%rax), %ecx
lock cmpxchgl %ecx, 52(%rdi)
sete %cl
je .LBB76_10
testl %eax, %eax
jne .LBB76_8
.LBB76_10:
which actually looks both simple and fairly optimal for that sequence.
Of course, since this is very much about cacheline access patterns,
actual performance will depend on random microarchitectural issues
(and not just the CPU core, but the whole memory subsystem).
Can somebody with a good - and relevant - benchmark system try this out?
Linus
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 820 bytes --]
include/linux/page_ref.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h
index 544150d1d5fd..d8e4f175f74c 100644
--- a/include/linux/page_ref.h
+++ b/include/linux/page_ref.h
@@ -234,8 +234,15 @@ static inline bool page_ref_add_unless(struct page *page, int nr, int u)
rcu_read_lock();
/* avoid writing to the vmemmap area being remapped */
- if (page_count_writable(page, u))
- ret = atomic_add_unless(&page->_refcount, nr, u);
+ if (page_count_writable(page, u)) {
+ /* Assume count == 1, don't read it! */
+ int old = 1;
+ do {
+ ret = atomic_try_cmpxchg(&page->_refcount, &old, old+1);
+ if (likely(ret))
+ break;
+ } while (old);
+ }
rcu_read_unlock();
if (page_ref_tracepoint_active(page_ref_mod_unless))
next prev parent reply other threads:[~2026-03-01 18:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 16:27 Gladyshev Ilya
2026-02-26 16:27 ` [PATCH 1/1] mm: implement page refcount locking via dedicated bit Gladyshev Ilya
2026-02-28 22:19 ` [PATCH 0/1] mm: improve folio refcount scalability Andrew Morton
2026-03-01 3:27 ` Linus Torvalds
2026-03-01 18:52 ` Linus Torvalds [this message]
2026-03-01 20:26 ` Pedro Falcato
2026-03-01 21:16 ` Linus Torvalds
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='CAHk-=wgOxtAFf5XeYTcoUHSpWfMrgZaXKc_hrmqt6yKBdr=3Zw@mail.gmail.com' \
--to=torvalds@linuxfoundation.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@fromorbit.com \
--cc=david@kernel.org \
--cc=gladyshev.ilya1@h-partners.com \
--cc=gorbunov.ivan@h-partners.com \
--cc=harry.yoo@oracle.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=rppt@kernel.org \
--cc=surenb@google.com \
--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