linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] mm/vmstat: simplify folio stat APIs
@ 2026-04-14  9:15 Ye Liu
  2026-04-14  9:15 ` [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations Ye Liu
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Ye Liu @ 2026-04-14  9:15 UTC (permalink / raw)
  To: Andrew Morton, linux-mm
  Cc: Ye Liu, Matthew Wilcox (Oracle), Vlastimil Babka, linux-kernel

From: Ye Liu <liuye@kylinos.cn>

This series simplifies folio statistics accounting by:
1. Replacing node_stat_mod_folio/zone_stat_mod_folio with more semantic
   add_folio/sub_folio functions
2. Removing unused __node_stat_* and __zone_stat_* wrapper functions

Ye Liu (4):
  mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages
    operations
  mm/vmstat: use zone_stat_add_folio/sub_folio for folio_nr_pages
    operations
  mm/vmstat: remove unused __node_stat_* wrappers
  mm/vmstat: remove unused __zone_stat_* wrappers

 fs/nfs/internal.h      |  2 +-
 fs/nfs/write.c         |  2 +-
 include/linux/vmstat.h | 36 ------------------------------------
 mm/compaction.c        |  5 ++---
 mm/gup.c               |  5 ++---
 mm/khugepaged.c        | 10 ++++------
 mm/mempolicy.c         |  5 ++---
 mm/migrate.c           | 12 +++++-------
 mm/mlock.c             |  6 +++---
 mm/page-writeback.c    | 16 ++++++++--------
 mm/page_alloc.c        |  2 +-
 mm/swap_state.c        |  4 ++--
 12 files changed, 31 insertions(+), 74 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations
  2026-04-14  9:15 [PATCH 0/4] mm/vmstat: simplify folio stat APIs Ye Liu
@ 2026-04-14  9:15 ` Ye Liu
  2026-04-14 17:52   ` David Hildenbrand (Arm)
  2026-04-14  9:15 ` [PATCH 2/4] mm/vmstat: use zone_stat_add_folio/sub_folio " Ye Liu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Ye Liu @ 2026-04-14  9:15 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, Andrew Morton, Vlastimil Babka,
	David Hildenbrand, Lorenzo Stoakes, Matthew Wilcox (Oracle),
	Chris Li, Kairui Song
  Cc: Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, Jason Gunthorpe, John Hubbard, Peter Xu,
	Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
	Barry Song, Lance Yang, Matthew Brost, Joshua Hahn, Rakie Kim,
	Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
	Kemeng Shi, Nhat Pham, Baoquan He, Youngjun Park, linux-nfs,
	linux-kernel, linux-mm, linux-fsdevel

From: Ye Liu <liuye@kylinos.cn>

Replace node_stat_mod_folio() calls that pass folio_nr_pages(folio) or
-folio_nr_pages(folio) as the third argument with the more concise
node_stat_add_folio() and node_stat_sub_folio() functions respectively.

This makes the code more readable and reduces the number of arguments
passed to these functions.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 fs/nfs/internal.h   |  2 +-
 fs/nfs/write.c      |  2 +-
 mm/compaction.c     |  5 ++---
 mm/gup.c            |  5 ++---
 mm/khugepaged.c     | 10 ++++------
 mm/mempolicy.c      |  5 ++---
 mm/migrate.c        | 12 +++++-------
 mm/page-writeback.c |  4 ++--
 mm/swap_state.c     |  4 ++--
 9 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index fc5456377160..f5c52a2d2a1f 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -858,7 +858,7 @@ static inline void nfs_folio_mark_unstable(struct folio *folio,
 		/* This page is really still in write-back - just that the
 		 * writeback is happening on the server now.
 		 */
-		node_stat_mod_folio(folio, NR_WRITEBACK, nr);
+		node_stat_add_folio(folio, NR_WRITEBACK);
 		bdi_wb_stat_mod(inode, WB_WRITEBACK, nr);
 		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
 	}
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index cc02b57de3c7..a8700824a61b 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -871,7 +871,7 @@ static void nfs_folio_clear_commit(struct folio *folio)
 	if (folio) {
 		long nr = folio_nr_pages(folio);
 
-		node_stat_mod_folio(folio, NR_WRITEBACK, -nr);
+		node_stat_sub_folio(folio, NR_WRITEBACK);
 		bdi_wb_stat_mod(folio->mapping->host, WB_WRITEBACK, -nr);
 	}
 }
diff --git a/mm/compaction.c b/mm/compaction.c
index 3648ce22c807..d7ce622aeed1 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1215,9 +1215,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 
 		/* Successfully isolated */
 		lruvec_del_folio(lruvec, folio);
-		node_stat_mod_folio(folio,
-				NR_ISOLATED_ANON + folio_is_file_lru(folio),
-				folio_nr_pages(folio));
+		node_stat_add_folio(folio,
+				NR_ISOLATED_ANON + folio_is_file_lru(folio));
 
 isolate_success:
 		list_add(&folio->lru, &cc->migratepages);
diff --git a/mm/gup.c b/mm/gup.c
index ad9ded39609c..2cb2efa20bff 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2304,9 +2304,8 @@ static unsigned long collect_longterm_unpinnable_folios(
 			continue;
 
 		list_add_tail(&folio->lru, movable_folio_list);
-		node_stat_mod_folio(folio,
-				    NR_ISOLATED_ANON + folio_is_file_lru(folio),
-				    folio_nr_pages(folio));
+		node_stat_add_folio(folio,
+				    NR_ISOLATED_ANON + folio_is_file_lru(folio));
 	}
 
 	return collected;
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b8452dbdb043..f662de753305 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -502,9 +502,8 @@ void __khugepaged_exit(struct mm_struct *mm)
 
 static void release_pte_folio(struct folio *folio)
 {
-	node_stat_mod_folio(folio,
-			NR_ISOLATED_ANON + folio_is_file_lru(folio),
-			-folio_nr_pages(folio));
+	node_stat_sub_folio(folio,
+			NR_ISOLATED_ANON + folio_is_file_lru(folio));
 	folio_unlock(folio);
 	folio_putback_lru(folio);
 }
@@ -650,9 +649,8 @@ static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma,
 			result = SCAN_DEL_PAGE_LRU;
 			goto out;
 		}
-		node_stat_mod_folio(folio,
-				NR_ISOLATED_ANON + folio_is_file_lru(folio),
-				folio_nr_pages(folio));
+		node_stat_add_folio(folio,
+				NR_ISOLATED_ANON + folio_is_file_lru(folio));
 		VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
 		VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
 
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 4e4421b22b59..1c413f66b35f 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1259,9 +1259,8 @@ static bool migrate_folio_add(struct folio *folio, struct list_head *foliolist,
 	if ((flags & MPOL_MF_MOVE_ALL) || !folio_maybe_mapped_shared(folio)) {
 		if (folio_isolate_lru(folio)) {
 			list_add_tail(&folio->lru, foliolist);
-			node_stat_mod_folio(folio,
-				NR_ISOLATED_ANON + folio_is_file_lru(folio),
-				folio_nr_pages(folio));
+			node_stat_add_folio(folio,
+				NR_ISOLATED_ANON + folio_is_file_lru(folio));
 		} else {
 			/*
 			 * Non-movable folio may reach here.  And, there may be
diff --git a/mm/migrate.c b/mm/migrate.c
index 8a64291ab5b4..dc8cfee37a70 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -268,8 +268,8 @@ void putback_movable_pages(struct list_head *l)
 		if (unlikely(page_has_movable_ops(&folio->page))) {
 			putback_movable_ops_page(&folio->page);
 		} else {
-			node_stat_mod_folio(folio, NR_ISOLATED_ANON +
-					folio_is_file_lru(folio), -folio_nr_pages(folio));
+			node_stat_sub_folio(folio, NR_ISOLATED_ANON +
+					folio_is_file_lru(folio));
 			folio_putback_lru(folio);
 		}
 	}
@@ -2272,9 +2272,8 @@ static int __add_folio_for_migration(struct folio *folio, int node,
 			return 1;
 	} else if (folio_isolate_lru(folio)) {
 		list_add_tail(&folio->lru, pagelist);
-		node_stat_mod_folio(folio,
-			NR_ISOLATED_ANON + folio_is_file_lru(folio),
-			folio_nr_pages(folio));
+		node_stat_add_folio(folio,
+			NR_ISOLATED_ANON + folio_is_file_lru(folio));
 		return 1;
 	}
 	return -EBUSY;
@@ -2726,8 +2725,7 @@ int migrate_misplaced_folio_prepare(struct folio *folio,
 	if (!folio_isolate_lru(folio))
 		return -EAGAIN;
 
-	node_stat_mod_folio(folio, NR_ISOLATED_ANON + folio_is_file_lru(folio),
-			    nr_pages);
+	node_stat_add_folio(folio, NR_ISOLATED_ANON + folio_is_file_lru(folio));
 	return 0;
 }
 
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 833f743f309f..87e9ea41313a 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2750,7 +2750,7 @@ bool folio_redirty_for_writepage(struct writeback_control *wbc,
 
 		wb = unlocked_inode_to_wb_begin(inode, &cookie);
 		current->nr_dirtied -= nr;
-		node_stat_mod_folio(folio, NR_DIRTIED, -nr);
+		node_stat_sub_folio(folio, NR_DIRTIED);
 		wb_stat_mod(wb, WB_DIRTIED, -nr);
 		unlocked_inode_to_wb_end(inode, &cookie);
 	}
@@ -2981,7 +2981,7 @@ bool __folio_end_writeback(struct folio *folio)
 
 	lruvec_stat_mod_folio(folio, NR_WRITEBACK, -nr);
 	zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
-	node_stat_mod_folio(folio, NR_WRITTEN, nr);
+	node_stat_add_folio(folio, NR_WRITTEN);
 
 	return ret;
 }
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 1415a5c54a43..d08e923c9979 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -160,7 +160,7 @@ void __swap_cache_add_folio(struct swap_cluster_info *ci,
 	folio_set_swapcache(folio);
 	folio->swap = entry;
 
-	node_stat_mod_folio(folio, NR_FILE_PAGES, nr_pages);
+	node_stat_add_folio(folio, NR_FILE_PAGES);
 	lruvec_stat_mod_folio(folio, NR_SWAPCACHE, nr_pages);
 }
 
@@ -265,7 +265,7 @@ void __swap_cache_del_folio(struct swap_cluster_info *ci, struct folio *folio,
 
 	folio->swap.val = 0;
 	folio_clear_swapcache(folio);
-	node_stat_mod_folio(folio, NR_FILE_PAGES, -nr_pages);
+	node_stat_sub_folio(folio, NR_FILE_PAGES);
 	lruvec_stat_mod_folio(folio, NR_SWAPCACHE, -nr_pages);
 
 	if (!folio_swapped) {
-- 
2.43.0



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 2/4] mm/vmstat: use zone_stat_add_folio/sub_folio for folio_nr_pages operations
  2026-04-14  9:15 [PATCH 0/4] mm/vmstat: simplify folio stat APIs Ye Liu
  2026-04-14  9:15 ` [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations Ye Liu
@ 2026-04-14  9:15 ` Ye Liu
  2026-04-14  9:15 ` [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers Ye Liu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Ye Liu @ 2026-04-14  9:15 UTC (permalink / raw)
  To: Andrew Morton, Liam R. Howlett, Lorenzo Stoakes,
	Matthew Wilcox (Oracle),
	Vlastimil Babka
  Cc: Ye Liu, Jann Horn, Pedro Falcato, Suren Baghdasaryan,
	Michal Hocko, Brendan Jackman, Johannes Weiner, Zi Yan, linux-mm,
	linux-kernel, linux-fsdevel

From: Ye Liu <liuye@kylinos.cn>

Replace zone_stat_mod_folio() calls that pass folio_nr_pages(folio) or
-folio_nr_pages(folio) as the third argument with the more concise
zone_stat_add_folio() and zone_stat_sub_folio() functions respectively.

This makes the code more readable and reduces the number of arguments
passed to these functions.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 mm/mlock.c          | 4 ++--
 mm/page-writeback.c | 8 ++++----
 mm/page_alloc.c     | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/mlock.c b/mm/mlock.c
index 8c227fefa2df..0cafcb2f4e8d 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -249,7 +249,7 @@ void mlock_folio(struct folio *folio)
 	if (!folio_test_set_mlocked(folio)) {
 		int nr_pages = folio_nr_pages(folio);
 
-		zone_stat_mod_folio(folio, NR_MLOCK, nr_pages);
+		zone_stat_add_folio(folio, NR_MLOCK);
 		__count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages);
 	}
 
@@ -273,7 +273,7 @@ void mlock_new_folio(struct folio *folio)
 	fbatch = this_cpu_ptr(&mlock_fbatch.fbatch);
 	folio_set_mlocked(folio);
 
-	zone_stat_mod_folio(folio, NR_MLOCK, nr_pages);
+	zone_stat_add_folio(folio, NR_MLOCK);
 	__count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages);
 
 	folio_get(folio);
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 87e9ea41313a..6f9b7b081ab7 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2647,7 +2647,7 @@ void folio_account_cleaned(struct folio *folio, struct bdi_writeback *wb)
 	long nr = folio_nr_pages(folio);
 
 	lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, -nr);
-	zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
+	zone_stat_sub_folio(folio, NR_ZONE_WRITE_PENDING);
 	wb_stat_mod(wb, WB_RECLAIMABLE, -nr);
 	task_io_account_cancelled_write(nr * PAGE_SIZE);
 }
@@ -2916,7 +2916,7 @@ bool folio_clear_dirty_for_io(struct folio *folio)
 		if (folio_test_clear_dirty(folio)) {
 			long nr = folio_nr_pages(folio);
 			lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, -nr);
-			zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
+			zone_stat_sub_folio(folio, NR_ZONE_WRITE_PENDING);
 			wb_stat_mod(wb, WB_RECLAIMABLE, -nr);
 			ret = true;
 		}
@@ -2980,7 +2980,7 @@ bool __folio_end_writeback(struct folio *folio)
 	}
 
 	lruvec_stat_mod_folio(folio, NR_WRITEBACK, -nr);
-	zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, -nr);
+	zone_stat_sub_folio(folio, NR_ZONE_WRITE_PENDING);
 	node_stat_add_folio(folio, NR_WRITTEN);
 
 	return ret;
@@ -3032,7 +3032,7 @@ void __folio_start_writeback(struct folio *folio, bool keep_write)
 	}
 
 	lruvec_stat_mod_folio(folio, NR_WRITEBACK, nr);
-	zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
+	zone_stat_add_folio(folio, NR_ZONE_WRITE_PENDING);
 
 	access_ret = arch_make_folio_accessible(folio);
 	/*
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 65e205111553..a81ceb4181ea 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1327,7 +1327,7 @@ __always_inline bool __free_pages_prepare(struct page *page,
 		long nr_pages = folio_nr_pages(folio);
 
 		__folio_clear_mlocked(folio);
-		zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		zone_stat_sub_folio(folio, NR_MLOCK);
 		count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages);
 	}
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
  2026-04-14  9:15 [PATCH 0/4] mm/vmstat: simplify folio stat APIs Ye Liu
  2026-04-14  9:15 ` [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations Ye Liu
  2026-04-14  9:15 ` [PATCH 2/4] mm/vmstat: use zone_stat_add_folio/sub_folio " Ye Liu
@ 2026-04-14  9:15 ` Ye Liu
  2026-04-14 14:59   ` Joshua Hahn
  2026-04-14  9:15 ` [PATCH 4/4] mm/vmstat: remove unused __zone_stat_* wrappers Ye Liu
  2026-04-14 13:18 ` [PATCH 0/4] mm/vmstat: simplify folio stat APIs Matthew Wilcox
  4 siblings, 1 reply; 15+ messages in thread
From: Ye Liu @ 2026-04-14  9:15 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Matthew Wilcox (Oracle)
  Cc: Ye Liu, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, linux-mm,
	linux-kernel, linux-fsdevel

From: Ye Liu <liuye@kylinos.cn>

Replace the single call to __node_stat_mod_folio()
with node_stat_mod_folio(), and remove the dead inline __node_stat_*
wrapper definitions from include/linux/vmstat.h.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 include/linux/vmstat.h | 18 ------------------
 mm/page-writeback.c    |  2 +-
 2 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index 3c9c266cf782..54da7d820f78 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -440,24 +440,6 @@ static inline void zone_stat_sub_folio(struct folio *folio,
 	mod_zone_page_state(folio_zone(folio), item, -folio_nr_pages(folio));
 }
 
-static inline void __node_stat_mod_folio(struct folio *folio,
-		enum node_stat_item item, long nr)
-{
-	__mod_node_page_state(folio_pgdat(folio), item, nr);
-}
-
-static inline void __node_stat_add_folio(struct folio *folio,
-		enum node_stat_item item)
-{
-	__mod_node_page_state(folio_pgdat(folio), item, folio_nr_pages(folio));
-}
-
-static inline void __node_stat_sub_folio(struct folio *folio,
-		enum node_stat_item item)
-{
-	__mod_node_page_state(folio_pgdat(folio), item, -folio_nr_pages(folio));
-}
-
 static inline void node_stat_mod_folio(struct folio *folio,
 		enum node_stat_item item, long nr)
 {
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 6f9b7b081ab7..ed3301753e89 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2627,7 +2627,7 @@ static void folio_account_dirtied(struct folio *folio,
 
 		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, nr);
 		__zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
-		__node_stat_mod_folio(folio, NR_DIRTIED, nr);
+		node_stat_mod_folio(folio, NR_DIRTIED, nr);
 		wb_stat_mod(wb, WB_RECLAIMABLE, nr);
 		wb_stat_mod(wb, WB_DIRTIED, nr);
 		task_io_account_write(nr * PAGE_SIZE);
-- 
2.43.0



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 4/4] mm/vmstat: remove unused __zone_stat_* wrappers
  2026-04-14  9:15 [PATCH 0/4] mm/vmstat: simplify folio stat APIs Ye Liu
                   ` (2 preceding siblings ...)
  2026-04-14  9:15 ` [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers Ye Liu
@ 2026-04-14  9:15 ` Ye Liu
  2026-04-14 13:18 ` [PATCH 0/4] mm/vmstat: simplify folio stat APIs Matthew Wilcox
  4 siblings, 0 replies; 15+ messages in thread
From: Ye Liu @ 2026-04-14  9:15 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Liam R. Howlett,
	Lorenzo Stoakes, Matthew Wilcox (Oracle)
  Cc: Ye Liu, Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan,
	Michal Hocko, Jann Horn, Pedro Falcato, linux-mm, linux-kernel,
	linux-fsdevel

From: Ye Liu <liuye@kylinos.cn>

Replace the remaining __zone_stat_mod_folio() call with
zone_stat_mod_folio(), and remove the dead inline
__zone_stat_* wrappers definitions from include/linux/vmstat.h.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 include/linux/vmstat.h | 18 ------------------
 mm/mlock.c             |  2 +-
 mm/page-writeback.c    |  2 +-
 3 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index 54da7d820f78..009b80e3c048 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -404,24 +404,6 @@ static inline void drain_zonestat(struct zone *zone,
 			struct per_cpu_zonestat *pzstats) { }
 #endif		/* CONFIG_SMP */
 
-static inline void __zone_stat_mod_folio(struct folio *folio,
-		enum zone_stat_item item, long nr)
-{
-	__mod_zone_page_state(folio_zone(folio), item, nr);
-}
-
-static inline void __zone_stat_add_folio(struct folio *folio,
-		enum zone_stat_item item)
-{
-	__mod_zone_page_state(folio_zone(folio), item, folio_nr_pages(folio));
-}
-
-static inline void __zone_stat_sub_folio(struct folio *folio,
-		enum zone_stat_item item)
-{
-	__mod_zone_page_state(folio_zone(folio), item, -folio_nr_pages(folio));
-}
-
 static inline void zone_stat_mod_folio(struct folio *folio,
 		enum zone_stat_item item, long nr)
 {
diff --git a/mm/mlock.c b/mm/mlock.c
index 0cafcb2f4e8d..654487063fbb 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -141,7 +141,7 @@ static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec
 
 munlock:
 	if (folio_test_clear_mlocked(folio)) {
-		__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
 		if (isolated || !folio_test_unevictable(folio))
 			__count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
 		else
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index ed3301753e89..dc15d775761e 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2626,7 +2626,7 @@ static void folio_account_dirtied(struct folio *folio,
 		wb = inode_to_wb(inode);
 
 		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, nr);
-		__zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
+		zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
 		node_stat_mod_folio(folio, NR_DIRTIED, nr);
 		wb_stat_mod(wb, WB_RECLAIMABLE, nr);
 		wb_stat_mod(wb, WB_DIRTIED, nr);
-- 
2.43.0



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 0/4] mm/vmstat: simplify folio stat APIs
  2026-04-14  9:15 [PATCH 0/4] mm/vmstat: simplify folio stat APIs Ye Liu
                   ` (3 preceding siblings ...)
  2026-04-14  9:15 ` [PATCH 4/4] mm/vmstat: remove unused __zone_stat_* wrappers Ye Liu
@ 2026-04-14 13:18 ` Matthew Wilcox
  2026-04-15  0:47   ` Ye Liu
  4 siblings, 1 reply; 15+ messages in thread
From: Matthew Wilcox @ 2026-04-14 13:18 UTC (permalink / raw)
  To: Ye Liu; +Cc: Andrew Morton, linux-mm, Ye Liu, Vlastimil Babka, linux-kernel

On Tue, Apr 14, 2026 at 05:15:17PM +0800, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
> 
> This series simplifies folio statistics accounting by:
> 1. Replacing node_stat_mod_folio/zone_stat_mod_folio with more semantic
>    add_folio/sub_folio functions
> 2. Removing unused __node_stat_* and __zone_stat_* wrapper functions

I'm not convinced this is the right approach.  We've often computed
folio_nr_pages() for use by several different functions, and you're
making us recompute it.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
  2026-04-14  9:15 ` [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers Ye Liu
@ 2026-04-14 14:59   ` Joshua Hahn
  2026-04-15  0:50     ` Ye Liu
  0 siblings, 1 reply; 15+ messages in thread
From: Joshua Hahn @ 2026-04-14 14:59 UTC (permalink / raw)
  To: Ye Liu
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox (Oracle),
	Ye Liu, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, linux-mm,
	linux-kernel, linux-fsdevel

On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <ye.liu@linux.dev> wrote:

> From: Ye Liu <liuye@kylinos.cn>
> 
> Replace the single call to __node_stat_mod_folio()
> with node_stat_mod_folio(), and remove the dead inline __node_stat_*
> wrapper definitions from include/linux/vmstat.h.
> 
> Signed-off-by: Ye Liu <liuye@kylinos.cn>
> ---
>  include/linux/vmstat.h | 18 ------------------
>  mm/page-writeback.c    |  2 +-
>  2 files changed, 1 insertion(+), 19 deletions(-)
> 
> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> index 3c9c266cf782..54da7d820f78 100644
> --- a/include/linux/vmstat.h
> +++ b/include/linux/vmstat.h
> @@ -440,24 +440,6 @@ static inline void zone_stat_sub_folio(struct folio *folio,
>  	mod_zone_page_state(folio_zone(folio), item, -folio_nr_pages(folio));
>  }
>  
> -static inline void __node_stat_mod_folio(struct folio *folio,
> -		enum node_stat_item item, long nr)
> -{
> -	__mod_node_page_state(folio_pgdat(folio), item, nr);
> -}
> -
> -static inline void __node_stat_add_folio(struct folio *folio,
> -		enum node_stat_item item)
> -{
> -	__mod_node_page_state(folio_pgdat(folio), item, folio_nr_pages(folio));
> -}
> -
> -static inline void __node_stat_sub_folio(struct folio *folio,
> -		enum node_stat_item item)
> -{
> -	__mod_node_page_state(folio_pgdat(folio), item, -folio_nr_pages(folio));
> -}
> -
>  static inline void node_stat_mod_folio(struct folio *folio,
>  		enum node_stat_item item, long nr)
>  {
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 6f9b7b081ab7..ed3301753e89 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -2627,7 +2627,7 @@ static void folio_account_dirtied(struct folio *folio,
>  
>  		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, nr);
>  		__zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
> -		__node_stat_mod_folio(folio, NR_DIRTIED, nr);
> +		node_stat_mod_folio(folio, NR_DIRTIED, nr);

Hi Ye, thank you for the patch,

In addition to what Matthew has pointed out, I also wanted to note that this
substitution isn't trivial; there are differences between the __ prefixed
version of node_stat_mod_folio and the one without. Even though the correctness
of the two versions might be the same, I think that a change like this should
be supplemented by a description of what side effects this change has
(i.e. introducing additional overhead from the cmpxchg loop).

Thank you, I hope you have a great day!
Joshua


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations
  2026-04-14  9:15 ` [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations Ye Liu
@ 2026-04-14 17:52   ` David Hildenbrand (Arm)
  2026-04-15  0:48     ` Ye Liu
  0 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand (Arm) @ 2026-04-14 17:52 UTC (permalink / raw)
  To: Ye Liu, Trond Myklebust, Anna Schumaker, Andrew Morton,
	Vlastimil Babka, Lorenzo Stoakes, Matthew Wilcox (Oracle),
	Chris Li, Kairui Song
  Cc: Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, Jason Gunthorpe, John Hubbard, Peter Xu,
	Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
	Barry Song, Lance Yang, Matthew Brost, Joshua Hahn, Rakie Kim,
	Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
	Kemeng Shi, Nhat Pham, Baoquan He, Youngjun Park, linux-nfs,
	linux-kernel, linux-mm, linux-fsdevel

On 4/14/26 11:15, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
> 
> Replace node_stat_mod_folio() calls that pass folio_nr_pages(folio) or
> -folio_nr_pages(folio) as the third argument with the more concise
> node_stat_add_folio() and node_stat_sub_folio() functions respectively.
> 
> This makes the code more readable and reduces the number of arguments
> passed to these functions.

Also, that makes it clearer that we always account the full folio, never
parts of it.

-- 
Cheers,

David


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 0/4] mm/vmstat: simplify folio stat APIs
  2026-04-14 13:18 ` [PATCH 0/4] mm/vmstat: simplify folio stat APIs Matthew Wilcox
@ 2026-04-15  0:47   ` Ye Liu
  2026-04-15  3:59     ` Matthew Wilcox
  0 siblings, 1 reply; 15+ messages in thread
From: Ye Liu @ 2026-04-15  0:47 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Andrew Morton, linux-mm, Ye Liu, Vlastimil Babka, linux-kernel



在 2026/4/14 21:18, Matthew Wilcox 写道:
> On Tue, Apr 14, 2026 at 05:15:17PM +0800, Ye Liu wrote:
>> From: Ye Liu <liuye@kylinos.cn>
>>
>> This series simplifies folio statistics accounting by:
>> 1. Replacing node_stat_mod_folio/zone_stat_mod_folio with more semantic
>>    add_folio/sub_folio functions
>> 2. Removing unused __node_stat_* and __zone_stat_* wrapper functions
> 
> I'm not convinced this is the right approach.  We've often computed
> folio_nr_pages() for use by several different functions, and you're
> making us recompute it.


Thank you for your feedback, Matthew. I acknowledge that this change may
introduce additional calls to folio_nr_pages() in some cases where the
value was previously computed once and reused. However, the new
add_folio/sub_folio functions provide clearer semantics, explicitly
indicating that we're accounting for the entire folio rather than
potentially partial pages. The overhead of recomputing folio_nr_pages()
is minimal in most scenarios, and the improved readability and reduced
argument passing outweigh this concern.

-- 
Thanks,
Ye Liu



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations
  2026-04-14 17:52   ` David Hildenbrand (Arm)
@ 2026-04-15  0:48     ` Ye Liu
  0 siblings, 0 replies; 15+ messages in thread
From: Ye Liu @ 2026-04-15  0:48 UTC (permalink / raw)
  To: David Hildenbrand (Arm),
	Trond Myklebust, Anna Schumaker, Andrew Morton, Vlastimil Babka,
	Lorenzo Stoakes, Matthew Wilcox (Oracle),
	Chris Li, Kairui Song
  Cc: Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Johannes Weiner, Zi Yan, Jason Gunthorpe, John Hubbard, Peter Xu,
	Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
	Barry Song, Lance Yang, Matthew Brost, Joshua Hahn, Rakie Kim,
	Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
	Kemeng Shi, Nhat Pham, Baoquan He, Youngjun Park, linux-nfs,
	linux-kernel, linux-mm, linux-fsdevel



在 2026/4/15 01:52, David Hildenbrand (Arm) 写道:
> On 4/14/26 11:15, Ye Liu wrote:
>> From: Ye Liu <liuye@kylinos.cn>
>>
>> Replace node_stat_mod_folio() calls that pass folio_nr_pages(folio) or
>> -folio_nr_pages(folio) as the third argument with the more concise
>> node_stat_add_folio() and node_stat_sub_folio() functions respectively.
>>
>> This makes the code more readable and reduces the number of arguments
>> passed to these functions.
> 
> Also, that makes it clearer that we always account the full folio, never
> parts of it.
> 

Thank you, David, for your support. I agree that the new functions make
the intent more explicit.

-- 
Thanks,
Ye Liu



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
  2026-04-14 14:59   ` Joshua Hahn
@ 2026-04-15  0:50     ` Ye Liu
  2026-04-15  2:29       ` Joshua Hahn
  0 siblings, 1 reply; 15+ messages in thread
From: Ye Liu @ 2026-04-15  0:50 UTC (permalink / raw)
  To: Joshua Hahn
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox (Oracle),
	Ye Liu, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, linux-mm,
	linux-kernel, linux-fsdevel



在 2026/4/14 22:59, Joshua Hahn 写道:
> On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <ye.liu@linux.dev> wrote:
> 
>> From: Ye Liu <liuye@kylinos.cn>
>>
>> Replace the single call to __node_stat_mod_folio()
>> with node_stat_mod_folio(), and remove the dead inline __node_stat_*
>> wrapper definitions from include/linux/vmstat.h.
>>
>> Signed-off-by: Ye Liu <liuye@kylinos.cn>
>> ---
>>  include/linux/vmstat.h | 18 ------------------
>>  mm/page-writeback.c    |  2 +-
>>  2 files changed, 1 insertion(+), 19 deletions(-)
>>
>> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
>> index 3c9c266cf782..54da7d820f78 100644
>> --- a/include/linux/vmstat.h
>> +++ b/include/linux/vmstat.h
>> @@ -440,24 +440,6 @@ static inline void zone_stat_sub_folio(struct folio *folio,
>>  	mod_zone_page_state(folio_zone(folio), item, -folio_nr_pages(folio));
>>  }
>>  
>> -static inline void __node_stat_mod_folio(struct folio *folio,
>> -		enum node_stat_item item, long nr)
>> -{
>> -	__mod_node_page_state(folio_pgdat(folio), item, nr);
>> -}
>> -
>> -static inline void __node_stat_add_folio(struct folio *folio,
>> -		enum node_stat_item item)
>> -{
>> -	__mod_node_page_state(folio_pgdat(folio), item, folio_nr_pages(folio));
>> -}
>> -
>> -static inline void __node_stat_sub_folio(struct folio *folio,
>> -		enum node_stat_item item)
>> -{
>> -	__mod_node_page_state(folio_pgdat(folio), item, -folio_nr_pages(folio));
>> -}
>> -
>>  static inline void node_stat_mod_folio(struct folio *folio,
>>  		enum node_stat_item item, long nr)
>>  {
>> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
>> index 6f9b7b081ab7..ed3301753e89 100644
>> --- a/mm/page-writeback.c
>> +++ b/mm/page-writeback.c
>> @@ -2627,7 +2627,7 @@ static void folio_account_dirtied(struct folio *folio,
>>  
>>  		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, nr);
>>  		__zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
>> -		__node_stat_mod_folio(folio, NR_DIRTIED, nr);
>> +		node_stat_mod_folio(folio, NR_DIRTIED, nr);
> 
> Hi Ye, thank you for the patch,
> 
> In addition to what Matthew has pointed out, I also wanted to note that this
> substitution isn't trivial; there are differences between the __ prefixed
> version of node_stat_mod_folio and the one without. Even though the correctness
> of the two versions might be the same, I think that a change like this should
> be supplemented by a description of what side effects this change has
> (i.e. introducing additional overhead from the cmpxchg loop).
> 
> Thank you, I hope you have a great day!
> Joshua

Thank you for your review, Joshua. Regarding the difference between
__node_stat_mod_folio and node_stat_mod_folio: in the current implementation,
both functions ultimately use __mod_node_page_state, as mod_node_page_state
is defined as __mod_node_page_state. There is no functional difference
between them in terms of atomicity or overhead. The __ prefixed versions
were wrappers that are now unused, which is why we're removing them.

-- 
Thanks,
Ye Liu



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
  2026-04-15  0:50     ` Ye Liu
@ 2026-04-15  2:29       ` Joshua Hahn
  2026-04-15  5:51         ` Ye Liu
  0 siblings, 1 reply; 15+ messages in thread
From: Joshua Hahn @ 2026-04-15  2:29 UTC (permalink / raw)
  To: Ye Liu
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox (Oracle),
	Ye Liu, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, linux-mm,
	linux-kernel, linux-fsdevel

On Wed, 15 Apr 2026 08:50:54 +0800 Ye Liu <ye.liu@linux.dev> wrote:

> 
> 
> 在 2026/4/14 22:59, Joshua Hahn 写道:
> > On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <ye.liu@linux.dev> wrote:
> > 
> >> From: Ye Liu <liuye@kylinos.cn>
> >>
> >> Replace the single call to __node_stat_mod_folio()
> >> with node_stat_mod_folio(), and remove the dead inline __node_stat_*
> >> wrapper definitions from include/linux/vmstat.h.
> >>
> >> Signed-off-by: Ye Liu <liuye@kylinos.cn>
> >> ---
> >>  include/linux/vmstat.h | 18 ------------------
> >>  mm/page-writeback.c    |  2 +-
> >>  2 files changed, 1 insertion(+), 19 deletions(-)
> >>
> >> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> >> index 3c9c266cf782..54da7d820f78 100644
> >> --- a/include/linux/vmstat.h
> >> +++ b/include/linux/vmstat.h
> >> @@ -440,24 +440,6 @@ static inline void zone_stat_sub_folio(struct folio *folio,
> >>  	mod_zone_page_state(folio_zone(folio), item, -folio_nr_pages(folio));
> >>  }
> >>  
> >> -static inline void __node_stat_mod_folio(struct folio *folio,
> >> -		enum node_stat_item item, long nr)
> >> -{
> >> -	__mod_node_page_state(folio_pgdat(folio), item, nr);
> >> -}
> >> -
> >> -static inline void __node_stat_add_folio(struct folio *folio,
> >> -		enum node_stat_item item)
> >> -{
> >> -	__mod_node_page_state(folio_pgdat(folio), item, folio_nr_pages(folio));
> >> -}
> >> -
> >> -static inline void __node_stat_sub_folio(struct folio *folio,
> >> -		enum node_stat_item item)
> >> -{
> >> -	__mod_node_page_state(folio_pgdat(folio), item, -folio_nr_pages(folio));
> >> -}
> >> -
> >>  static inline void node_stat_mod_folio(struct folio *folio,
> >>  		enum node_stat_item item, long nr)
> >>  {
> >> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> >> index 6f9b7b081ab7..ed3301753e89 100644
> >> --- a/mm/page-writeback.c
> >> +++ b/mm/page-writeback.c
> >> @@ -2627,7 +2627,7 @@ static void folio_account_dirtied(struct folio *folio,
> >>  
> >>  		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, nr);
> >>  		__zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
> >> -		__node_stat_mod_folio(folio, NR_DIRTIED, nr);
> >> +		node_stat_mod_folio(folio, NR_DIRTIED, nr);
> > 
> > Hi Ye, thank you for the patch,
> > 
> > In addition to what Matthew has pointed out, I also wanted to note that this
> > substitution isn't trivial; there are differences between the __ prefixed
> > version of node_stat_mod_folio and the one without. Even though the correctness
> > of the two versions might be the same, I think that a change like this should
> > be supplemented by a description of what side effects this change has
> > (i.e. introducing additional overhead from the cmpxchg loop).
> > 
> > Thank you, I hope you have a great day!
> > Joshua
> 
> Thank you for your review, Joshua. Regarding the difference between
> __node_stat_mod_folio and node_stat_mod_folio: in the current implementation,
> both functions ultimately use __mod_node_page_state, as mod_node_page_state
> is defined as __mod_node_page_state. There is no functional difference
> between them in terms of atomicity or overhead. The __ prefixed versions
> were wrappers that are now unused, which is why we're removing them.

Hello Ye,

Thanks for the quick response. However, I'm not sure that's true.
For #ifdef CONFIG_HAVE_CMPXCHG_LOCAL in mm/vmstat.c, I can see that
mod_node_page_state calls mod_node_state, which includes the cmpxchg loop.
I think many users enalbe this config, including x86. IMHO, we should document
this effect of the changes.

Thank you, I hope you have a great day!
Joshua


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 0/4] mm/vmstat: simplify folio stat APIs
  2026-04-15  0:47   ` Ye Liu
@ 2026-04-15  3:59     ` Matthew Wilcox
  2026-04-15  5:54       ` Ye Liu
  0 siblings, 1 reply; 15+ messages in thread
From: Matthew Wilcox @ 2026-04-15  3:59 UTC (permalink / raw)
  To: Ye Liu; +Cc: Andrew Morton, linux-mm, Ye Liu, Vlastimil Babka, linux-kernel

On Wed, Apr 15, 2026 at 08:47:24AM +0800, Ye Liu wrote:
> Thank you for your feedback, Matthew. I acknowledge that this change may
> introduce additional calls to folio_nr_pages() in some cases where the
> value was previously computed once and reused. However, the new
> add_folio/sub_folio functions provide clearer semantics, explicitly
> indicating that we're accounting for the entire folio rather than
> potentially partial pages. The overhead of recomputing folio_nr_pages()
> is minimal in most scenarios, and the improved readability and reduced
> argument passing outweigh this concern.

I disagree.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
  2026-04-15  2:29       ` Joshua Hahn
@ 2026-04-15  5:51         ` Ye Liu
  0 siblings, 0 replies; 15+ messages in thread
From: Ye Liu @ 2026-04-15  5:51 UTC (permalink / raw)
  To: Joshua Hahn
  Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox (Oracle),
	Ye Liu, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, linux-mm,
	linux-kernel, linux-fsdevel



在 2026/4/15 10:29, Joshua Hahn 写道:
> On Wed, 15 Apr 2026 08:50:54 +0800 Ye Liu <ye.liu@linux.dev> wrote:
> 
>>
>>
>> 在 2026/4/14 22:59, Joshua Hahn 写道:
>>> On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <ye.liu@linux.dev> wrote:
>>>
>>>> From: Ye Liu <liuye@kylinos.cn>
>>>>
>>>> Replace the single call to __node_stat_mod_folio()
>>>> with node_stat_mod_folio(), and remove the dead inline __node_stat_*
>>>> wrapper definitions from include/linux/vmstat.h.
>>>>
>>>> Signed-off-by: Ye Liu <liuye@kylinos.cn>
>>>> ---
>>>>  include/linux/vmstat.h | 18 ------------------
>>>>  mm/page-writeback.c    |  2 +-
>>>>  2 files changed, 1 insertion(+), 19 deletions(-)
>>>>
>>>> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
>>>> index 3c9c266cf782..54da7d820f78 100644
>>>> --- a/include/linux/vmstat.h
>>>> +++ b/include/linux/vmstat.h
>>>> @@ -440,24 +440,6 @@ static inline void zone_stat_sub_folio(struct folio *folio,
>>>>  	mod_zone_page_state(folio_zone(folio), item, -folio_nr_pages(folio));
>>>>  }
>>>>  
>>>> -static inline void __node_stat_mod_folio(struct folio *folio,
>>>> -		enum node_stat_item item, long nr)
>>>> -{
>>>> -	__mod_node_page_state(folio_pgdat(folio), item, nr);
>>>> -}
>>>> -
>>>> -static inline void __node_stat_add_folio(struct folio *folio,
>>>> -		enum node_stat_item item)
>>>> -{
>>>> -	__mod_node_page_state(folio_pgdat(folio), item, folio_nr_pages(folio));
>>>> -}
>>>> -
>>>> -static inline void __node_stat_sub_folio(struct folio *folio,
>>>> -		enum node_stat_item item)
>>>> -{
>>>> -	__mod_node_page_state(folio_pgdat(folio), item, -folio_nr_pages(folio));
>>>> -}
>>>> -
>>>>  static inline void node_stat_mod_folio(struct folio *folio,
>>>>  		enum node_stat_item item, long nr)
>>>>  {
>>>> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
>>>> index 6f9b7b081ab7..ed3301753e89 100644
>>>> --- a/mm/page-writeback.c
>>>> +++ b/mm/page-writeback.c
>>>> @@ -2627,7 +2627,7 @@ static void folio_account_dirtied(struct folio *folio,
>>>>  
>>>>  		lruvec_stat_mod_folio(folio, NR_FILE_DIRTY, nr);
>>>>  		__zone_stat_mod_folio(folio, NR_ZONE_WRITE_PENDING, nr);
>>>> -		__node_stat_mod_folio(folio, NR_DIRTIED, nr);
>>>> +		node_stat_mod_folio(folio, NR_DIRTIED, nr);
>>>
>>> Hi Ye, thank you for the patch,
>>>
>>> In addition to what Matthew has pointed out, I also wanted to note that this
>>> substitution isn't trivial; there are differences between the __ prefixed
>>> version of node_stat_mod_folio and the one without. Even though the correctness
>>> of the two versions might be the same, I think that a change like this should
>>> be supplemented by a description of what side effects this change has
>>> (i.e. introducing additional overhead from the cmpxchg loop).
>>>
>>> Thank you, I hope you have a great day!
>>> Joshua
>>
>> Thank you for your review, Joshua. Regarding the difference between
>> __node_stat_mod_folio and node_stat_mod_folio: in the current implementation,
>> both functions ultimately use __mod_node_page_state, as mod_node_page_state
>> is defined as __mod_node_page_state. There is no functional difference
>> between them in terms of atomicity or overhead. The __ prefixed versions
>> were wrappers that are now unused, which is why we're removing them.
> 
> Hello Ye,
> 
> Thanks for the quick response. However, I'm not sure that's true.
> For #ifdef CONFIG_HAVE_CMPXCHG_LOCAL in mm/vmstat.c, I can see that
> mod_node_page_state calls mod_node_state, which includes the cmpxchg loop.
> I think many users enalbe this config, including x86. IMHO, we should document
> this effect of the changes.
> 
> Thank you, I hope you have a great day!
> Joshua

Thank you for your review, Joshua. You are correct that there is a difference.
The __node_stat_mod_folio call goes directly to __mod_node_page_state, which
assumes the caller already has the necessary serialization. By contrast,
node_stat_mod_folio goes through mod_node_page_state, which on systems with
CONFIG_HAVE_CMPXCHG_LOCAL uses a this_cpu_try_cmpxchg() loop and on other
systems serializes via local_irq_save/restore.

That means the wrapper removal is not purely cosmetic: it changes the
update path from a direct per-cpu diff update to a serializing update
path, and therefore incurs extra overhead.

-- 
Thanks,
Ye Liu



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 0/4] mm/vmstat: simplify folio stat APIs
  2026-04-15  3:59     ` Matthew Wilcox
@ 2026-04-15  5:54       ` Ye Liu
  0 siblings, 0 replies; 15+ messages in thread
From: Ye Liu @ 2026-04-15  5:54 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Andrew Morton, linux-mm, Ye Liu, Vlastimil Babka, linux-kernel



在 2026/4/15 11:59, Matthew Wilcox 写道:
> On Wed, Apr 15, 2026 at 08:47:24AM +0800, Ye Liu wrote:
>> Thank you for your feedback, Matthew. I acknowledge that this change may
>> introduce additional calls to folio_nr_pages() in some cases where the
>> value was previously computed once and reused. However, the new
>> add_folio/sub_folio functions provide clearer semantics, explicitly
>> indicating that we're accounting for the entire folio rather than
>> potentially partial pages. The overhead of recomputing folio_nr_pages()
>> is minimal in most scenarios, and the improved readability and reduced
>> argument passing outweigh this concern.
> 
> I disagree.

Thanks for the direct feedback.

-- 
Thanks,
Ye Liu



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-04-15  5:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-14  9:15 [PATCH 0/4] mm/vmstat: simplify folio stat APIs Ye Liu
2026-04-14  9:15 ` [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations Ye Liu
2026-04-14 17:52   ` David Hildenbrand (Arm)
2026-04-15  0:48     ` Ye Liu
2026-04-14  9:15 ` [PATCH 2/4] mm/vmstat: use zone_stat_add_folio/sub_folio " Ye Liu
2026-04-14  9:15 ` [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers Ye Liu
2026-04-14 14:59   ` Joshua Hahn
2026-04-15  0:50     ` Ye Liu
2026-04-15  2:29       ` Joshua Hahn
2026-04-15  5:51         ` Ye Liu
2026-04-14  9:15 ` [PATCH 4/4] mm/vmstat: remove unused __zone_stat_* wrappers Ye Liu
2026-04-14 13:18 ` [PATCH 0/4] mm/vmstat: simplify folio stat APIs Matthew Wilcox
2026-04-15  0:47   ` Ye Liu
2026-04-15  3:59     ` Matthew Wilcox
2026-04-15  5:54       ` Ye Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox