mm/vmstat: simplify folio stat APIs
Subsystems (13)
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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 2/4 mm/vmstat: use zone_stat_add_folio/sub_folio for folio_nr_pages operations
In reply to Ye LiuFrom: 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
@@ -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
@@ -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
@@ -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
PATCH 3/4 mm/vmstat: remove unused __node_stat_* wrappers
In reply to Ye LiuFrom: 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
@@ -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
@@ -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
PATCH 4/4 mm/vmstat: remove unused __zone_stat_* wrappers
In reply to Ye LiuFrom: 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
@@ -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
@@ -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
@@ -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
Matthew Wilcox
maintainerQuoted 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.
Joshua Hahn
reviewerRe: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
In reply to Ye LiuQuoted 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()
withnode_stat_mod_folio(), and remove the dead inline __node_stat_* wrapper definitions frominclude/linux/vmstat.h.Signed-off-by Ye Liu <[email protected]>--- include/linux/vmstat.h | 18 ------------------ mm/page-writeback.c | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-)include/linux/vmstat.h +0
-18@@ -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
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
David Hildenbrand (Arm)
maintainerRe: [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations
In reply to Ye LiuQuoted 8 lines · Ye Liu
From: Ye Liu <[email protected]>
Replace
node_stat_mod_folio()calls that passfolio_nr_pages(folio)or -folio_nr_pages(folio) as the third argument with the more concisenode_stat_add_folio()andnode_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
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 functionsI'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
Re: [PATCH 1/4] mm/vmstat: use node_stat_add_folio/sub_folio for folio_nr_pages operations
In reply to David Hildenbrand (Arm)Quoted 7 lines · David Hildenbrand (Arm)
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
Replace
node_stat_mod_folio()calls that passfolio_nr_pages(folio)or -folio_nr_pages(folio) as the third argument with the more concisenode_stat_add_folio()andnode_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
Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
In reply to Joshua HahnQuoted 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()
withnode_stat_mod_folio(), and remove the dead inline __node_stat_* wrapper definitions frominclude/linux/vmstat.h.Signed-off-by Ye Liu <[email protected]>--- include/linux/vmstat.h | 18 ------------------ mm/page-writeback.c | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-)include/linux/vmstat.h +0
-18@@ -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
-0mm/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_folioand 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
Joshua Hahn
reviewerRe: [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()
withnode_stat_mod_folio(), and remove the dead inline __node_stat_* wrapper definitions frominclude/linux/vmstat.h.Signed-off-by Ye Liu <[email protected]>--- include/linux/vmstat.h | 18 ------------------ mm/page-writeback.c | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-)include/linux/vmstat.h +0
-18@@ -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
-0mm/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_folioand 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_folioandnode_stat_mod_folio: in the current implementation, both functions ultimately use__mod_node_page_state, asmod_node_page_stateis 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
Matthew Wilcox
maintainerQuoted 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 recomputingfolio_nr_pages()is minimal in most scenarios, and the improved readability and reduced argument passing outweigh this concern.
I disagree.
Re: [PATCH 3/4] mm/vmstat: remove unused __node_stat_* wrappers
In reply to Joshua HahnQuoted 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()
withnode_stat_mod_folio(), and remove the dead inline __node_stat_* wrapper definitions frominclude/linux/vmstat.h.Signed-off-by Ye Liu <[email protected]>--- include/linux/vmstat.h | 18 ------------------ mm/page-writeback.c | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-)include/linux/vmstat.h +0
-18@@ -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
-0mm/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_folioand 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!
JoshuaQuoted 6 lines
Thank you for your review, Joshua. Regarding the difference between
__node_stat_mod_folioandnode_stat_mod_folio: in the current implementation, both functions ultimately use__mod_node_page_state, asmod_node_page_stateis 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_LOCALinmm/vmstat.c, I can see thatmod_node_page_statecallsmod_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
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 recomputingfolio_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