Skip to contentSkip to conversation

mm/vmstat: simplify folio stat APIs

PATCH In review Ye Liu 4 participants 15 messages Apr 14 – Apr 15

Subsystems (13)
lore
Share & tools
lore

Ye Liu

author
#0 lore raw

cover mm/vmstat: simplify folio stat APIs

From: Ye Liu <[email protected]>

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(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/4 mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations

From: Ye Liu <[email protected]>

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.

---
 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(-)
fs/nfs/internal.h +1 -1
index fc5456377160..f5c52a2d2a1f 100644
@@ -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);
 	}
fs/nfs/write.c +1 -1
index cc02b57de3c7..a8700824a61b 100644
@@ -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);
 	}
 }
mm/compaction.c +2 -3
index 3648ce22c807..d7ce622aeed1 100644
@@ -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);
mm/gup.c +2 -3
index ad9ded39609c..2cb2efa20bff 100644
@@ -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;
mm/khugepaged.c +4 -6
index b8452dbdb043..f662de753305 100644
@@ -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);
 
mm/mempolicy.c +2 -3
index 4e4421b22b59..1c413f66b35f 100644
@@ -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
mm/migrate.c +5 -7
index 8a64291ab5b4..dc8cfee37a70 100644
@@ -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;
 }
 
mm/page-writeback.c +2 -2
index 833f743f309f..87e9ea41313a 100644
@@ -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;
 }
mm/swap_state.c +2 -2
index 1415a5c54a43..d08e923c9979 100644
@@ -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) {
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations

Quoted 8 lines · Ye Liu

From: Ye Liu <[email protected]>

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.

Signature · 3 lines
Cheers,

David
author
#3 lore raw

Re: [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations

Quoted 7 lines · David Hildenbrand (Arm)
Quoted 6 lines · Ye Liu

From: Ye Liu <[email protected]>

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.

Quoted 6 lines
Quoted 2 lines

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.

Signature · 2 lines
Thanks,
Ye Liu
author
#4 lore raw

PATCH 2/4 mm/vmstat: use zone_stat_add_folio/sub_folio for folio_nr_pages operations

In reply to Ye Liu

From: Ye Liu <[email protected]>

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.

---
 mm/mlock.c          | 4 ++--
 mm/page-writeback.c | 8 ++++----
 mm/page_alloc.c     | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
mm/mlock.c +2 -2
index 8c227fefa2df..0cafcb2f4e8d 100644
@@ -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);
mm/page-writeback.c +4 -4
index 87e9ea41313a..6f9b7b081ab7 100644
@@ -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);
 	/*
mm/page_alloc.c +1 -1
index 65e205111553..a81ceb4181ea 100644
@@ -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);
 	}
 
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH 3/4 mm/vmstat: remove unused __node_stat_* wrappers

In reply to Ye Liu

From: Ye Liu <[email protected]>

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.

---
 include/linux/vmstat.h | 18 ------------------
 mm/page-writeback.c    |  2 +-
 2 files changed, 1 insertion(+), 19 deletions(-)
include/linux/vmstat.h +0 -18
index 3c9c266cf782..54da7d820f78 100644
@@ -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)
 {
mm/page-writeback.c +1 -1
index 6f9b7b081ab7..ed3301753e89 100644
@@ -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);
Signature · 1 line
2.43.0
reviewer
#6 lore raw

Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers

Quoted 46 lines · On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <[email protected]> wrote:

From: Ye Liu <[email protected]>

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.

---
 include/linux/vmstat.h | 18 ------------------
 mm/page-writeback.c    |  2 +-
 2 files changed, 1 insertion(+), 19 deletions(-)
include/linux/vmstat.h +0 -18
index 3c9c266cf782..54da7d820f78 100644
@@ -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)
 {
mm/page-writeback.c +0 -0
index 6f9b7b081ab7..ed3301753e89 100644

mm/page-writeback.c static void folio_account_dirtied(struct folio *folio, · line 2630

Quoted 5 lines
mm/page-writeback.c +1 -1
@@ -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

author
#7 lore raw

Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers

Quoted 63 lines · Joshua Hahn
Quoted 46 lines · On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <[email protected]> wrote:

From: Ye Liu <[email protected]>

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.

---
 include/linux/vmstat.h | 18 ------------------
 mm/page-writeback.c    |  2 +-
 2 files changed, 1 insertion(+), 19 deletions(-)
include/linux/vmstat.h +0 -18
index 3c9c266cf782..54da7d820f78 100644
@@ -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)
 {
mm/page-writeback.c +0 -0
index 6f9b7b081ab7..ed3301753e89 100644

mm/page-writeback.c static void folio_account_dirtied(struct folio *folio, · line 2630

Quoted 5 lines
mm/page-writeback.c +1 -1
@@ -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).

Quoted 2 lines

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.

Signature · 2 lines
Thanks,
Ye Liu
reviewer
#8 lore raw

Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers

Quoted 69 lines · On Wed, 15 Apr 2026 08:50:54 +0800 Ye Liu <[email protected]> wrote:
Quoted 63 lines · Joshua Hahn
Quoted 46 lines · On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <[email protected]> wrote:

From: Ye Liu <[email protected]>

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.

---
 include/linux/vmstat.h | 18 ------------------
 mm/page-writeback.c    |  2 +-
 2 files changed, 1 insertion(+), 19 deletions(-)
include/linux/vmstat.h +0 -18
index 3c9c266cf782..54da7d820f78 100644
@@ -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)
 {
mm/page-writeback.c +0 -0
index 6f9b7b081ab7..ed3301753e89 100644

mm/page-writeback.c static void folio_account_dirtied(struct folio *folio, · line 2630

Quoted 5 lines
mm/page-writeback.c +1 -1
@@ -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).

Quoted 2 lines

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

Quoted 6 lines

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

author
#9 lore raw

Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers

Quoted 80 lines · Joshua Hahn
Quoted 69 lines · On Wed, 15 Apr 2026 08:50:54 +0800 Ye Liu <[email protected]> wrote:
Quoted 63 lines · Joshua Hahn
Quoted 46 lines · On Tue, 14 Apr 2026 17:15:20 +0800 Ye Liu <[email protected]> wrote:

From: Ye Liu <[email protected]>

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.

---
 include/linux/vmstat.h | 18 ------------------
 mm/page-writeback.c    |  2 +-
 2 files changed, 1 insertion(+), 19 deletions(-)
include/linux/vmstat.h +0 -18
index 3c9c266cf782..54da7d820f78 100644
@@ -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)
 {
mm/page-writeback.c +0 -0
index 6f9b7b081ab7..ed3301753e89 100644

mm/page-writeback.c static void folio_account_dirtied(struct folio *folio, · line 2630

Quoted 5 lines
mm/page-writeback.c +1 -1
@@ -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).

Quoted 2 lines

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

Quoted 6 lines

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,

Quoted 8 lines

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.

Signature · 2 lines
Thanks,
Ye Liu
author
#10 lore raw

PATCH 4/4 mm/vmstat: remove unused __zone_stat_* wrappers

In reply to Ye Liu

From: Ye Liu <[email protected]>

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.

---
 include/linux/vmstat.h | 18 ------------------
 mm/mlock.c             |  2 +-
 mm/page-writeback.c    |  2 +-
 3 files changed, 2 insertions(+), 20 deletions(-)
include/linux/vmstat.h +0 -18
index 54da7d820f78..009b80e3c048 100644
@@ -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)
 {
mm/mlock.c +1 -1
index 0cafcb2f4e8d..654487063fbb 100644
@@ -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
mm/page-writeback.c +1 -1
index ed3301753e89..dc15d775761e 100644
@@ -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);
Signature · 1 line
2.43.0
maintainer
#11 lore raw
In reply to Ye Liu
Quoted 6 lines · Ye Liu

From: Ye Liu <[email protected]>

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.

author
#12 lore raw
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Ye Liu

From: Ye Liu <[email protected]>

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.

Signature · 2 lines
Thanks,
Ye Liu
maintainer
#13 lore raw
Quoted 8 lines · Ye Liu

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.

author
#14 lore raw
Quoted 11 lines · Matthew Wilcox
Quoted 8 lines · Ye Liu

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.

Signature · 2 lines
Thanks,
Ye Liu