The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Kiryl Shutsemau <kas@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	 Andrew Morton <akpm@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, 13 Nov 2026 14:17:52 +0000	[thread overview]
Message-ID: <avcbg96XgusgAlfS@thinkstation> (raw)
In-Reply-To: <fa90c536-3b3a-417e-a09f-011a12e73048@kernel.org>

On Thu, Nov 12, 2026 at 01:32:02PM +0100, David Hildenbrand (Arm) wrote:
> On 11/12/26 13:26, Kiryl Shutsemau wrote:
> > On Wed, Nov 11, 2026 at 11:03:38AM +0100, David Hildenbrand (Arm) wrote:
> >> So I might be completely off, but what I imagine is that the memdescs will get
> >> RCU-freed (these are not pages), and once they are then getting freed, they will
> >> probably take the physical page with them.
> >>
> >> And freeing memdescs through RCU will likely be memdesc specific.
> >>
> >> I really don't know, Willy might know more about these plans.
> > 
> > Right: once the folio is allocated separately, the lockless read
> > dereferences it too, so it has to wait for the grace period along with
> > its pages.  The per-CPU batching and the waits in the allocator later
> > in the series do not depend on where the check sits.
> > 
> > Until then the folio is the struct page, and __free_pages_prepare() is
> > the one place every page cache folio passes, so v3 keeps the check
> > there. 
> 
> If we go that way, don't make it effectively folio-centric in the
> implementation. That's what triggered my response in the first place.

Is something like this what you mean?

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d3862d68a8d9..5b9ac91d25ae 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1314,7 +1314,7 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
 
 /*
  * Each CPU has at most one grace period in flight (@queued), covering
- * @batch.  Folios freed meanwhile wait on @pending for the next one.
+ * @batch.  Pages freed meanwhile wait on @pending for the next one.
  */
 struct rcu_free_pcpu {
 	spinlock_t lock;
@@ -1354,28 +1354,26 @@ static void rcu_free_take(struct rcu_free_pcpu *r, struct list_head *list)
 
 static unsigned long rcu_free_pages(struct list_head *list, bool direct)
 {
-	struct folio_batch fbatch;
-	struct folio *folio, *next;
+	struct page *page, *next;
 	unsigned long nr = 0;
 
-	folio_batch_init(&fbatch);
-	list_for_each_entry_safe(folio, next, list, lru) {
-		nr += folio_nr_pages(folio);
-		mod_zone_page_state(folio_zone(folio), NR_FREE_RCU_PAGES,
-				    -folio_nr_pages(folio));
+	list_for_each_entry_safe(page, next, list, lru) {
+		unsigned int order = page_private(page);
+
+		set_page_private(page, 0);
+		nr += 1 << order;
+		mod_zone_page_state(page_zone(page), NR_FREE_RCU_PAGES,
+				    -(1 << order));
 		/* Atomic: memory_failure() may set PG_hwpoison meanwhile */
-		folio_clear_rcu_free(folio);
+		folio_clear_rcu_free(page_folio(page));
 		if (direct) {
-			__free_pages_ok(&folio->page, folio_order(folio),
-					FPI_NONE);
+			__free_pages_ok(page, order, FPI_NONE);
 			cond_resched();
-		} else if (!folio_batch_add(&fbatch, folio)) {
-			free_unref_folios(&fbatch);
+		} else {
+			free_frozen_pages(page, order);
 			cond_resched_tasks_rcu_qs();
 		}
 	}
-	if (folio_batch_count(&fbatch))
-		free_unref_folios(&fbatch);
 	return nr;
 }
 
@@ -1421,17 +1419,20 @@ static void rcu_free_expedite_workfn(struct work_struct *work)
 		count_vm_event(PGFREE_RCU_EXPEDITE);
 }
 
-static void rcu_free_defer(struct folio *folio)
+static void rcu_free_defer(struct page *page, unsigned int order)
 {
 	struct rcu_free_pcpu *r = raw_cpu_ptr(&rcu_free_pcpu);
-	struct zone *zone = folio_zone(folio);
+	struct zone *zone = page_zone(page);
 	unsigned long free, waiting;
 	unsigned long flags;
 
+	/* For rcu_free_pages(): not every high-order page is compound */
+	set_page_private(page, order);
+
 	spin_lock_irqsave(&r->lock, flags);
-	__mod_zone_page_state(zone, NR_FREE_RCU_PAGES, folio_nr_pages(folio));
-	list_add_tail(&folio->lru, &r->pending);
-	r->nr_pending += folio_nr_pages(folio);
+	__mod_zone_page_state(zone, NR_FREE_RCU_PAGES, 1 << order);
+	list_add_tail(&page->lru, &r->pending);
+	r->nr_pending += 1 << order;
 	rcu_free_start(r);
 	spin_unlock_irqrestore(&r->lock, flags);
 
@@ -1452,7 +1453,7 @@ static void rcu_free_defer(struct folio *folio)
 }
 
 /*
- * Free every waiting folio now, straight to the buddy lists, where the
+ * Free every waiting page now, straight to the buddy lists, where the
  * callers look for the pages next.  A concurrent drain holds the lock
  * until it has freed what it took.
  */
@@ -1528,7 +1529,7 @@ static __always_inline bool __free_pages_prepare(struct page *page,
 	    !(PageHWPoison(page) && !order)) {
 		VM_WARN_ON_ONCE(fpi_flags & FPI_NOLOCK);
 		count_vm_events(PGFREE_RCU, 1 << order);
-		rcu_free_defer(folio);
+		rcu_free_defer(page, order);
 		return false;
 	}
 
-- 
  Kiryl Shutsemau / Kirill A. Shutemov

  reply	other threads:[~2026-11-13 14:18 UTC|newest]

Thread overview: 37+ 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
2026-11-09 14:42       ` David Hildenbrand (Arm)
2026-11-09 15:56         ` Linus Torvalds
2026-11-09 17:23           ` David Hildenbrand (Arm)
2026-11-09 18:01             ` Linus Torvalds
2026-11-11 10:03               ` David Hildenbrand (Arm)
2026-11-12 12:26                 ` Kiryl Shutsemau
2026-11-12 12:32                   ` David Hildenbrand (Arm)
2026-11-13 14:17                     ` 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-09 14:46   ` David Hildenbrand (Arm)
2026-11-09 16:28     ` Linus Torvalds
2026-11-09 16:35       ` Linus Torvalds
2026-11-09 17:48         ` David Hildenbrand (Arm)
2026-11-10 13:58           ` Kiryl Shutsemau
2026-11-04 13:01 ` [RFC PATCH v2 04/18] mm: count the pages waiting for a grace period Kiryl Shutsemau (Meta)
2026-11-09 14:48   ` David Hildenbrand (Arm)
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=avcbg96XgusgAlfS@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