mm/page_alloc: get_page_from_freelist cleanups
Subsystems (4)
v4 cover mm/page_alloc: get_page_from_freelist cleanups
v3 --> v4:
==========
- Make kswapd_wmark_pages() static inline, as suggested by Vlastimil.
2 cleanups for vmscan and page_alloc code. The primary goal is to make get_page_from_freelist a bit easier to read, especially after the new kswapd zone skip conditions [1].
Based on the latest page_alloc/for-next branch as of 11/18/2026. Notably, there is a dependency on the aforementioned kswapd zone skip, 677dfdfad244a "mm/page_alloc: only skip kswapd nodes below their kswapd watermark".
No functional changes intended.
[1] https://lore.kernel.org/all/CAN+CAwNsqWpPoag_XE6bxbrfi6m71xw1NS_wc3h_ShZjNspSjg@mail.gmail.com/
Joshua Hahn (2):
mm/page_alloc: move the kswapd node skip check into a helper mm/vmscan: consolidate promo vs. high watermark checks
mm/page_alloc.c | 47 ++++++++++++++++++++++++++++------------------- mm/page_alloc.h | 12 ++++++++++++ mm/vmscan.c | 11 ++--------- 3 files changed, 42 insertions(+), 28 deletions(-)
base-commit: 3a99594e62fce8c646e8aac01d38af16d6833a40
Signature · 1 line
2.53.1-Meta
PATCH v4 1/2 mm/page_alloc: move the kswapd node skip check into a helper
get_page_from_freelist() checks many conditions for each zone, often with a big comment block explaining the conditions.
Move the kswapd check and its comment into should_skip_kswapd_zone() to make the zone iteration cleaner to read.
While moving this, also resolve a checkpatch warning which complains of a waitqueue_active() call with no corresponding comment explaining why the lockless use is OK in this case.
No functional change intended.
--- mm/page_alloc.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-)
mm/page_alloc.c +31 -18
@@ -3785,6 +3785,34 @@ static inline unsigned int alloc_flags_cma(gfp_t gfp_mask)return ALLOC_DEFAULT ; } +/* +* If kswapd is already active on a node and the zone is below its kswapd +* watermark for this request, keep looking for other nodes that might be idle. +* This can happen if another process has NUMA bindings and is causing kswapd +* wakeups on only some nodes. Avoid accidental "node_reclaim_mode"-like +* behavior in this case. +*/ +static inline bool +should_skip_kswapd_zone (struct zone *zone,unsigned int order, +const struct alloc_context *ac,gfp_t gfp_mask) +{ +unsigned long mark; + +/* +* This means kswapd is asleep, so don't skip the zone. This is a +* lockless check, since a stale result only affects zone selection. +*/ +if (waitqueue_active (&zone->zone_pgdat->kswapd_wait)) +return false; + +if (sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ) + mark =promo_wmark_pages (zone); +else + mark =high_wmark_pages (zone); +return !zone_watermark_fast (zone, order, mark, ac->highest_zoneidx, +0 , gfp_mask); +} +/* * get_page_from_freelist goes through the zonelist trying to allocate * a page.
@@ -3796,9 +3824,6 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,struct zoneref *z;struct zone *zone;struct pglist_data *last_pgdat =NULL ; -enum zone_watermarks kswapd_watermark = - sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ? -WMARK_PROMO :WMARK_HIGH ;bool last_pgdat_dirty_ok = false;bool no_fallback;bool skip_kswapd_nodes = nr_online_nodes >1 ;
@@ -3865,22 +3890,10 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, } } -/* -* If kswapd is already active on a node and the zone is below -* its kswapd watermark for this request, keep looking for -* other nodes that might be idle. This can happen if another -* process has NUMA bindings and is causing kswapd wakeups on -* only some nodes. Avoid accidental "node_reclaim_mode"-like -* behavior in this case. -*/ if (skip_kswapd_nodes && - !waitqueue_active (&zone->zone_pgdat->kswapd_wait)) { - mark =wmark_pages (zone, kswapd_watermark); -if (!zone_watermark_fast (zone, order, mark, - ac->highest_zoneidx,0 , gfp_mask)) { - skipped_kswapd_nodes = true; -continue ; - } +should_skip_kswapd_zone (zone, order, ac, gfp_mask)) { + skipped_kswapd_nodes = true; +continue ; }cond_accept_memory (zone, order, alloc_flags);
Signature · 1 line
2.53.1-Meta
Re: [PATCH v4 1/2] mm/page_alloc: move the kswapd node skip check into a helper
Quoted 12 lines · Joshua Hahn
get_page_from_freelist()checks many conditions for each zone, often with a big comment block explaining the conditions.Move the kswapd check and its comment into
should_skip_kswapd_zone()to make the zone iteration cleaner to read.While moving this, also resolve a checkpatch warning which complains of a
waitqueue_active()call with no corresponding comment explaining why the lockless use is OK in this case.No functional change intended.
Quoted 8 lines
Reviewed-by SJ Park <[email protected]>Reviewed-by Chris Down <[email protected]>Reviewed-by Zi Yan <[email protected]>Reviewed-by Gregory Price <[email protected]>Reviewed-by Dev Jain <[email protected]>Tested-by Chris Down <[email protected]>Signed-off-by Joshua Hahn <[email protected]>---
Looks good to me,
Signature · 2 lines
Cheers, Harry / Hyeonggon
PATCH v4 2/2 mm/vmscan: consolidate promo vs. high watermark checks
In reply to Joshua HahnThere are three sites which all check the watermark that kswapd reclaims zones up to, which is the promo watermark when NUMA balancing memory tiering is enabled, and the high watermark otherwise.
Consolidate the pattern into an inline helper and move the dependency on the sysctl.h header into page_alloc.h.
No functional changes intended.
--- mm/page_alloc.c | 6 +----- mm/page_alloc.h | 12 ++++++++++++ mm/vmscan.c | 11 ++--------- 3 files changed, 15 insertions(+), 14 deletions(-)
mm/page_alloc.c +1 -5
@@ -45,7 +45,6 @@#include <linux/mmu_notifier.h> #include <linux/migrate.h> #include <linux/sched/mm.h> -#include <linux/sched/sysctl.h> #include <linux/page_owner.h> #include <linux/page_table_check.h> #include <linux/memcontrol.h>
@@ -3805,10 +3804,7 @@ should_skip_kswapd_zone(struct zone *zone, unsigned int order,if (waitqueue_active (&zone->zone_pgdat->kswapd_wait))return false; -if (sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ) - mark =promo_wmark_pages (zone); -else - mark =high_wmark_pages (zone); + mark =kswapd_wmark_pages (zone);return !zone_watermark_fast (zone, order, mark, ac->highest_zoneidx,0 , gfp_mask); }
mm/page_alloc.h +12 -0
@@ -9,6 +9,7 @@#include <linux/mm.h> #include <linux/mmzone.h> #include <linux/nodemask.h> +#include <linux/sched/sysctl.h> #include <linux/types.h> #define ALLOC_DEFAULT 0
@@ -304,6 +305,17 @@ static inline int gfp_migratetype(const gfp_t gfp_flags)#undef GFP_MOVABLE_MASK#undef GFP_MOVABLE_SHIFT +/* +* The watermark kswapd reclaims zones up to. With NUMA balancing memory +* tiering, kswapd keeps room above the high watermark for promotions. +*/ +static inline unsigned long kswapd_wmark_pages (const struct zone *zone) +{ +if (sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ) +return promo_wmark_pages (zone); +return high_wmark_pages (zone); +} +bool decay_pcp_high (struct zone *zone,struct per_cpu_pages *pcp);void drain_zone_pages (struct zone *zone,struct per_cpu_pages *pcp);void drain_all_pages (struct zone *zone);
mm/vmscan.c +2 -9
@@ -5212,7 +5212,6 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,static bool should_abort_scan (struct lruvec *lruvec,struct scan_control *sc) {int i; -enum zone_watermarks mark;if (unlikely (sc->proactive &&signal_pending (current)))return true;
@@ -5224,12 +5223,9 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)if (!current_is_kswapd () || sc->order)return false; - mark = sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ? -WMARK_PROMO :WMARK_HIGH ; -for (i =0 ; i <= sc->reclaim_idx; i++) {struct zone *zone =lruvec_pgdat (lruvec)->node_zones + i; -unsigned long size =wmark_pages (zone, mark) +MIN_LRU_BATCH ; +unsigned long size =kswapd_wmark_pages (zone) +MIN_LRU_BATCH ;if (managed_zone (zone) && !zone_watermark_ok (zone,0 , size, sc->reclaim_idx,0 ))return false;
@@ -7131,10 +7127,7 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int highest_zoneidx)enum zone_stat_item item;unsigned long free_pages; -if (sysctl_numa_balancing_mode &NUMA_BALANCING_MEMORY_TIERING ) - mark =promo_wmark_pages (zone); -else - mark =high_wmark_pages (zone); + mark =kswapd_wmark_pages (zone);/* * In defrag_mode, watermarks must be met in whole
Signature · 1 line
2.53.1-Meta
Re: [PATCH v4 2/2] mm/vmscan: consolidate promo vs. high watermark checks
Quoted 9 lines · Joshua Hahn
There are three sites which all check the watermark that kswapd reclaims zones up to, which is the promo watermark when NUMA balancing memory tiering is enabled, and the high watermark otherwise.
Consolidate the pattern into an inline helper and move the dependency on the
sysctl.hheader intopage_alloc.h.No functional changes intended.
Quoted 8 lines
Reviewed-by SJ Park <[email protected]>Reviewed-by Chris Down <[email protected]>Reviewed-by Zi Yan <[email protected]>Reviewed-by Gregory Price <[email protected]>Reviewed-by Dev Jain <[email protected]>Tested-by Chris Down <[email protected]>Signed-off-by Joshua Hahn <[email protected]>---
Looks good to me,
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 13 lines · Joshua Hahn
v3 --> v4:
==========
- Makekswapd_wmark_pages()static inline, as suggested by Vlastimil.2 cleanups for vmscan and
page_alloccode. The primary goal is to makeget_page_from_freelista bit easier to read, especially after the new kswapd zone skip conditions [1].Based on the latest page_alloc/for-next branch as of 11/18/2026. Notably, there is a dependency on the aforementioned kswapd zone skip,
677dfdfad244a"mm/page_alloc: only skip kswapd nodes below their kswapd watermark".
Quoted 7 lines
No functional changes intended.
[1] https://lore.kernel.org/all/CAN+CAwNsqWpPoag_XE6bxbrfi6m71xw1NS_wc3h_ShZjNspSjg@mail.gmail.com/
Joshua Hahn (2):
mm/page_alloc: move the kswapd node skip check into a helper mm/vmscan: consolidate promo vs. high watermark checks
Applied to page_alloc/for-next, thanks!
Quoted 8 lines
mm/page_alloc.c | 47 ++++++++++++++++++++++++++++------------------- mm/page_alloc.h | 12 ++++++++++++ mm/vmscan.c | 11 ++--------- 3 files changed, 42 insertions(+), 28 deletions(-)base-commit:
3a99594e62fce8c646e8aac01d38af16d6833a40