From: Kiryl Shutsemau <kas@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>, Jan Kara <jack@suse.cz>,
Hugh Dickins <hughd@google.com>,
Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Harry Yoo <harry@kernel.org>, Miklos Szeredi <miklos@szeredi.hu>,
Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
Oscar Salvador <osalvador@suse.de>,
"Liam R. Howlett" <liam@infradead.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kairui Song <kasong@tencent.com>, Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
"Paul E. McKenney" <paulmck@kernel.org>,
Pedro Falcato <pfalcato@suse.de>,
Luis Chamberlain <mcgrof@kernel.org>,
Ilya Gladyshev <ilya.gladyshev@linux.dev>,
Jaegeuk Kim <jaegeuk@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, fuse-devel@lists.linux.dev,
kernel-team@meta.com
Subject: Re: [RFC PATCH v2 01/18] mm: free PG_rcu_free folios only after an RCU grace period
Date: Fri, 6 Nov 2026 10:23:22 +0000 [thread overview]
Message-ID: <au2lsbDkyWt-To0C@thinkstation> (raw)
In-Reply-To: <ecad7b3c-7244-425a-9413-04d49f221057@kernel.org>
On Thu, Nov 05, 2026 at 09:37:31PM +0100, David Hildenbrand (Arm) wrote:
> > diff --git a/mm/Kconfig b/mm/Kconfig
> > index 604c58199acb..6e5341b0bf64 100644
> > --- a/mm/Kconfig
> > +++ b/mm/Kconfig
> > @@ -718,6 +718,21 @@ config PCP_BATCH_SCALE_MAX
> > latency. This option sets the upper limit of scale factor to limit
> > the maximum latency.
> >
> > +config PAGE_RCU_FREE
>
> I think we really want to focus this only on folios (like the current code does).
>
> FOLIO_RCU_FREE ?
Sure.
> > + def_bool y
> > + depends on 64BIT
> > + depends on !PREEMPT_RT
> > + help
> > + Reads from the page cache can copy from folios that are read
> > + again and again without taking a reference on them, so small
> > + reads of one file from many CPUs do not contend on the folio's
> > + reference count. The cost is that memory freed from such
> > + folios becomes reusable only after an RCU grace period.
>
> While that description is helpful, that's not really what this patch, or rather
> the basic infrastructure in page_alloc, does.
>
> I'd suggest to have a dedicated FOLIO_RCU_FREE config and maybe another one
> (that selects/depends on) FOLIO_RCU_FREE that actually enables the pagecache use
> and documents the details.
I will make the help describe what this patch does. The page cache is
the only user, and both symbols would be def_bool without a prompt, so
I would rather add the second one with a second user.
Does that work for you?
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index 1e5d68acf62a..25082949a4ca 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -3743,6 +3743,7 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
> > #endif
> > (1L << PG_dirty) |
> > (1L << PG_dropbehind) |
> > + __PG_RCU_FREE |
>
> That looks a bit odd at first, as it's very different to the other once. But no
> easy way around assuming that the flag is not always around.
>
> Maybe we should just have this be a const mask constructed somewhere using BIT()
> and __PG_RCU_FREE etc, instead of having this growing list in this user here.
Makes sense. Something like the diff below, on top of this patch.
Introducing split_copy_flags would be a preparatory patch, and this one
would only add __PG_RCU_FREE to it.
> > @@ -1327,6 +1417,19 @@ static __always_inline bool __free_pages_prepare(struct page *page,
> >
> > VM_BUG_ON_PAGE(PageTail(page), page);
> >
> > + /*
> > + * Not for a hwpoisoned order-0 page: it never reaches the allocator,
> > + * and page_handle_poison() takes a reference right after this free.
> > + */
> > + if (unlikely(folio_test_rcu_free(folio)) &&
> > + !(PageHWPoison(page) && !order)) {
> > + VM_WARN_ON_ONCE(fpi_flags & FPI_NOLOCK);
> > + __folio_clear_rcu_free(folio);
> > + count_vm_events(PGFREE_RCU, 1 << order);
> > + rcu_free_defer(folio);
> > + return false;
> > + }
> I'm wondering whether we want to intercept on the folio freeing path instead?
> That would be __folio_put(), before we go into free_frozen_pages() used by other
> machinery that does not apply (slab etc).
Not all page cache folios are freed through __folio_put(). Reclaim
frees them with free_unref_folios() directly (shrink_folio_list(),
move_folios_to_lru()), and so do folios_put_refs() and the LRU batches.
__free_pages_prepare() is the one place they all pass.
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index a1e52a1f8a52..6d4e534c9ccc 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -1185,6 +1185,18 @@ static __always_inline void __ClearPageAnonExclusive(struct page *page)
#define __PG_MLOCKED 0
#endif
+#ifdef CONFIG_ARCH_USES_PG_ARCH_2
+#define __PG_ARCH_2 BIT(PG_arch_2)
+#else
+#define __PG_ARCH_2 0
+#endif
+
+#ifdef CONFIG_ARCH_USES_PG_ARCH_3
+#define __PG_ARCH_3 BIT(PG_arch_3)
+#else
+#define __PG_ARCH_3 0
+#endif
+
/*
* Flags checked when a page is freed. Pages being freed should not have
* these flags set. If they are, there is a problem.
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 25082949a4ca..44a1aaa3f834 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3689,6 +3689,23 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
const bool handle_hwpoison = folio_test_has_hwpoisoned(folio) && new_order;
long new_nr_pages = 1 << new_order;
long nr_pages = 1 << old_order;
+ const unsigned long split_copy_flags =
+ BIT(PG_referenced) |
+ BIT(PG_swapbacked) |
+ BIT(PG_swapcache) |
+ __PG_MLOCKED |
+ BIT(PG_uptodate) |
+ BIT(PG_active) |
+ BIT(PG_workingset) |
+ BIT(PG_locked) |
+ BIT(PG_unevictable) |
+ __PG_ARCH_2 |
+ __PG_ARCH_3 |
+ BIT(PG_dirty) |
+ BIT(PG_dropbehind) |
+ __PG_RCU_FREE |
+ LRU_GEN_MASK |
+ LRU_REFS_MASK;
long i;
folio_clear_has_hwpoisoned(folio);
@@ -3725,26 +3742,7 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
* PG_anon_exclusive (-> PG_mappedtodisk) for these here.
*/
new_folio->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP;
- new_folio->flags.f |= (folio->flags.f &
- ((1L << PG_referenced) |
- (1L << PG_swapbacked) |
- (1L << PG_swapcache) |
- (1L << PG_mlocked) |
- (1L << PG_uptodate) |
- (1L << PG_active) |
- (1L << PG_workingset) |
- (1L << PG_locked) |
- (1L << PG_unevictable) |
-#ifdef CONFIG_ARCH_USES_PG_ARCH_2
- (1L << PG_arch_2) |
-#endif
-#ifdef CONFIG_ARCH_USES_PG_ARCH_3
- (1L << PG_arch_3) |
-#endif
- (1L << PG_dirty) |
- (1L << PG_dropbehind) |
- __PG_RCU_FREE |
- LRU_GEN_MASK | LRU_REFS_MASK));
+ new_folio->flags.f |= folio->flags.f & split_copy_flags;
new_folio->mapping = folio->mapping;
new_folio->index = folio->index + i;
--
Kiryl Shutsemau / Kirill A. Shutemov
next prev parent reply other threads:[~2026-11-06 10:23 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 13:00 [RFC PATCH v2 00/18] mm: read the page cache without folio references Kiryl Shutsemau (Meta)
2026-11-04 13:00 ` [RFC PATCH v2 01/18] mm: free PG_rcu_free folios only after an RCU grace period Kiryl Shutsemau (Meta)
2026-11-05 20:37 ` David Hildenbrand (Arm)
2026-11-06 10:23 ` Kiryl Shutsemau [this message]
2026-11-04 13:00 ` [RFC PATCH v2 02/18] splice: don't steal page cache folios Kiryl Shutsemau (Meta)
2026-11-04 16:05 ` David Hildenbrand (Arm)
2026-11-05 14:55 ` Kiryl Shutsemau
2026-11-04 13:00 ` [RFC PATCH v2 03/18] fuse: don't move a folio with PG_rcu_free into a fuse file Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 04/18] mm: count the pages waiting for a grace period Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 05/18] mm: expedite the grace period when a CPU has many deferred frees Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 06/18] mm: free the pages waiting for a grace period before OOM Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 07/18] mm: free the pages waiting for a grace period before isolation fails Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 08/18] mm/compaction: free the migrated folios that wait for a grace period Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 09/18] mm/memory-failure: handle folios with PG_rcu_free Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 10/18] mm: have folio_mark_accessed() return whether the folio is hot Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 11/18] mm/filemap: mark a folio accessed in one place in filemap_read() Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 12/18] mm/filemap: set PG_rcu_free on the folios that reads keep coming back to Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 13/18] mm/filemap: read from the page cache without folio references Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 14/18] mm/filemap: read large folios " Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 15/18] mm/filemap: don't store f_ra.prev_pos for FMODE_RANDOM files Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 16/18] mm/shmem: count accesses to a folio the way filemap_read() does Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 17/18] mm/shmem: read without folio references Kiryl Shutsemau (Meta)
2026-11-04 13:01 ` [RFC PATCH v2 18/18] mm/filemap: add a debugfs switch for lockless page cache reads Kiryl Shutsemau (Meta)
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=au2lsbDkyWt-To0C@thinkstation \
--to=kas@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=brauner@kernel.org \
--cc=brendan.jackman@linux.dev \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=fuse-devel@lists.linux.dev \
--cc=hannes@cmpxchg.org \
--cc=harry@kernel.org \
--cc=hughd@google.com \
--cc=ilya.gladyshev@linux.dev \
--cc=jack@suse.cz \
--cc=jaegeuk@kernel.org \
--cc=kasong@tencent.com \
--cc=kernel-team@meta.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linmiaohe@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mcgrof@kernel.org \
--cc=mhocko@suse.com \
--cc=miklos@szeredi.hu \
--cc=nao.horiguchi@gmail.com \
--cc=nico.pache@linux.dev \
--cc=osalvador@suse.de \
--cc=paulmck@kernel.org \
--cc=pfalcato@suse.de \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=torvalds@linux-foundation.org \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=yuanchu@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®