Skip to contentSkip to conversation

mm-page-flags-check-page-folio-private-instead-of-pg_private.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Oct 9

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled

     Subject: mm/page-flags: check page/folio->private instead of PG_private

has been removed from the -mm tree. Its filename was
mm-page-flags-check-page-folio-private-instead-of-pg_private.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Zi Yan <[email protected]>
Subject: mm/page-flags: check page/folio->private instead of PG_private
Date: Sun, 20 Sep 2026 22:28:06 -0400

After the changes of the prior commits, page/folio->private != NULL is now equivalent to checking PG_private.

Stop checking PG_private on pages and folios and use page/folio->private instead, except swapcache and hugetlb folios, because the former uses a field (swp_entry_t swap) overlapping with ->private and the latter sets its flags in ->private. Exclude swapcache and hugetlb when the code is meant to check PG_private only. PG_swapcache and folio->swap.val cannot be set/clear as a whole, so excluding swapcache with folio_test_swapcache() is not reliable. Instead, use folio_test_swapbacked(), since PG_swapbacked is stable when a folio is added to/removed from swapcache. Add a helper, folio_has_attached_private(), for this check.

folio_test_private() and PagePrivate() now read folio/page->private plainly instead of an atomic read of PG_private bit, so KCSAN complains about possible data races. Annotate them with data_race().

folio_expected_ref_count() can be called without the folio lock, so annotate folio->mapping with data_race() while at it.

folio_set/clear_private() and Set/ClearPagePrivate() become no-ops. PG_private is no longer checked at page free time. They will be removed in an upcoming commit.

Remove KPF_PRIVATE since PG_private is no longer used.

Assisted-by LLM
Cc Steven Rostedt <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc "Matthew Wilcox (Oracle)" <[email protected]>
Cc Jan Kara <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>
Cc Lance Yang <[email protected]>
Cc Usama Arif <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Joshua Hahn <[email protected]>
Cc Rakie Kim <[email protected]>
Cc Byungchul Park <[email protected]>
Cc Gregory Price <[email protected]>
Cc Ying Huang <[email protected]>
Cc Alistair Popple <[email protected]>
Cc Qi Zheng <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Kairui Song <[email protected]>
Cc Axel Rasmussen <[email protected]>
Cc Yuanchu Xie <[email protected]>
Cc Wei Xu <[email protected]>

---

 fs/proc/page.c                    |    1 
 include/linux/kernel-page-flags.h |    1 
 include/linux/mm.h                |   19 +++++----
 include/linux/page-flags.h        |   57 +++++++++++++++++++++++++---
 include/trace/events/pagemap.h    |    2 
 mm/huge_memory.c                  |    2 
 mm/migrate.c                      |    2 
 mm/page-writeback.c               |    2 
 mm/vmscan.c                       |    2 
 tools/mm/page-types.c             |    2 
 10 files changed, 68 insertions(+), 22 deletions(-)
fs/proc/page.c renamed from fs/proc/page.c~mm-page-flags-check-page-folio-private-instead-of-pg_private +0 -1
@@ -232,7 +232,6 @@ u64 stable_page_flags(const struct page
 
 	u |= kpf_copy_bit(k, KPF_RESERVED,	PG_reserved);
 	u |= kpf_copy_bit(k, KPF_OWNER_2,	PG_owner_2);
-	u |= kpf_copy_bit(k, KPF_PRIVATE,	PG_private);
 	u |= kpf_copy_bit(k, KPF_PRIVATE_2,	PG_private_2);
 	u |= kpf_copy_bit(k, KPF_OWNER_PRIVATE,	PG_owner_priv_1);
 	u |= kpf_copy_bit(k, KPF_ARCH,		PG_arch_1);
include/linux/kernel-page-flags.h renamed from include/linux/kernel-page-flags.h~mm-page-flags-check-page-folio-private-instead-of-pg_private +0 -1
@@ -11,7 +11,6 @@
 #define KPF_RESERVED		32
 #define KPF_MLOCKED		33
 #define KPF_OWNER_2		34
-#define KPF_PRIVATE		35
 #define KPF_PRIVATE_2		36
 #define KPF_OWNER_PRIVATE	37
 #define KPF_ARCH		38
include/linux/mm.h renamed from include/linux/mm.h~mm-page-flags-check-page-folio-private-instead-of-pg_private +12 -7
@@ -3005,9 +3005,9 @@ static inline bool folio_maybe_mapped_sh
  * @folio: the folio
  *
  * Calculate the expected folio refcount, taking references from the pagecache,
- * swapcache, PG_private and page table mappings into account. Useful in
- * combination with folio_ref_count() to detect unexpected references (e.g.,
- * GUP or other temporary references).
+ * swapcache, private data (folio->private != NULL) and page table mappings into
+ * account. Useful in combination with folio_ref_count() to detect unexpected
+ * references (e.g., GUP or other temporary references).
  *
  * Does currently not consider references from the LRU cache. If the folio
  * was isolated from the LRU (which is the case during migration or split),
@@ -3045,10 +3045,15 @@ static inline int folio_expected_ref_cou
 	ref_count += folio_test_swapcache(folio) << order;
 
 	if (!folio_test_anon(folio)) {
-		/* One reference per page from the pagecache. */
-		ref_count += !!folio->mapping << order;
-		/* One reference from PG_private. */
-		ref_count += folio_test_private(folio);
+		/*
+		 * One reference per page from the pagecache.
+		 * Use data_race() since folio might not be locked.
+		 */
+		ref_count += !!data_race(folio->mapping) << order;
+		/*
+		 * One reference from filesystem private data.
+		 */
+		ref_count += folio_has_attached_private(folio);
 	}
 
 	/* One reference per page table mapping. */
include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-page-flags-check-page-folio-private-instead-of-pg_private +51 -6

82 lines not on this page · raw message

include/trace/events/pagemap.h renamed from include/trace/events/pagemap.h~mm-page-flags-check-page-folio-private-instead-of-pg_private +1 -1
@@ -22,7 +22,7 @@
 	(folio_test_swapcache(folio)	? PAGEMAP_SWAPCACHE  : 0) | \
 	(folio_test_swapbacked(folio)	? PAGEMAP_SWAPBACKED : 0) | \
 	(folio_test_mappedtodisk(folio)	? PAGEMAP_MAPPEDDISK : 0) | \
-	(folio_test_private(folio)	? PAGEMAP_BUFFERS    : 0) \
+	(folio_has_attached_private(folio)	? PAGEMAP_BUFFERS    : 0) \
 	)
 
 TRACE_EVENT(mm_lru_insertion,
mm/huge_memory.c renamed from mm/huge_memory.c~mm-page-flags-check-page-folio-private-instead-of-pg_private +1 -1
@@ -4845,7 +4845,7 @@ static int split_huge_pages_pid(int pid,
 		 * will try to drop it before split and then check if the folio
 		 * can be split or not. So skip the check here.
 		 */
-		if (!folio_test_private(folio) &&
+		if (!folio_has_attached_private(folio) &&
 		    folio_expected_ref_count(folio) != folio_ref_count(folio))
 			goto next;
 
mm/migrate.c renamed from mm/migrate.c~mm-page-flags-check-page-folio-private-instead-of-pg_private +1 -1
@@ -1327,7 +1327,7 @@ static int migrate_folio_unmap(new_folio
 	 * free the metadata, so the page can be freed.
 	 */
 	if (!src->mapping) {
-		if (folio_test_private(src)) {
+		if (folio_has_attached_private(src)) {
 			try_to_free_buffers(src);
 			goto out;
 		}
mm/page-writeback.c renamed from mm/page-writeback.c~mm-page-flags-check-page-folio-private-instead-of-pg_private +1 -1
@@ -2705,7 +2705,7 @@ bool filemap_dirty_folio(struct address_
 	if (folio_test_set_dirty(folio))
 		return false;
 
-	__folio_mark_dirty(folio, mapping, !folio_test_private(folio));
+	__folio_mark_dirty(folio, mapping, !folio_has_attached_private(folio));
 
 	if (mapping->host) {
 		/* !PageAnon && !swapper_space */
mm/vmscan.c renamed from mm/vmscan.c~mm-page-flags-check-page-folio-private-instead-of-pg_private +1 -1
@@ -1029,7 +1029,7 @@ static void folio_check_dirty_writeback(
 	*writeback = folio_test_writeback(folio);
 
 	/* Verify dirty/writeback state if the filesystem supports it */
-	if (!folio_test_private(folio))
+	if (!folio_has_attached_private(folio))
 		return;
 
 	mapping = folio_mapping(folio);
tools/mm/page-types.c renamed from tools/mm/page-types.c~mm-page-flags-check-page-folio-private-instead-of-pg_private +0 -2
@@ -73,7 +73,6 @@
 #define KPF_RESERVED		32
 #define KPF_MLOCKED		33
 #define KPF_OWNER_2		34
-#define KPF_PRIVATE		35
 #define KPF_PRIVATE_2		36
 #define KPF_OWNER_PRIVATE	37
 #define KPF_ARCH		38
@@ -131,7 +130,6 @@ static const char * const page_flag_name
 	[KPF_RESERVED]		= "r:reserved",
 	[KPF_MLOCKED]		= "m:mlocked",
 	[KPF_OWNER_2]		= "d:owner_2",
-	[KPF_PRIVATE]		= "P:private",
 	[KPF_PRIVATE_2]		= "p:private_2",
 	[KPF_OWNER_PRIVATE]	= "O:owner_private",
 	[KPF_ARCH]		= "h:arch",

_

Patches currently in -mm which might be from [email protected] are