mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dev Jain <dev.jain@arm.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Brendan Jackman <brendan.jackman@linux.dev>,
	Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
	Qi Zheng <qi.zheng@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH v2 2/3] mm/page_alloc: move the kswapd node skip check into a helper
Date: Wed, 18 Nov 2026 21:16:51 +0530	[thread overview]
Message-ID: <bf8692ab-f5b6-4ffe-b5ad-02ad59182cc0@arm.com> (raw)
In-Reply-To: <20261116232346.788145-3-joshua.hahnjy@gmail.com>



On 17/11/26 4:53 am, Joshua Hahn wrote:
> 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.
> 
> Reviewed-by: SJ Park <sj@kernel.org>
> Reviewed-by: Chris Down <chris@chrisdown.name>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Tested-by: Chris Down <chris@chrisdown.name>
> Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
> ---

Thanks looks better.

Reviewed-by: Dev Jain <dev.jain@arm.com>

But see below.


>  mm/page_alloc.c | 47 +++++++++++++++++++++++++++++------------------
>  1 file changed, 29 insertions(+), 18 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 4d829e5eac49d..43929faffb989 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3785,6 +3785,32 @@ 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 bool should_skip_kswapd_zone(struct zone *zone, unsigned int order,
> +				    const struct alloc_context *ac)

Make this inline? This is the very hot page allocator code that's why :)
I may be overthinking but in page_alloc.c I do see functions with similar
size being marked inline.



> +{
> +	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);
> +}
> +
>  /*
>   * get_page_from_freelist goes through the zonelist trying to allocate
>   * a page.
> @@ -3796,9 +3822,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 +3888,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)) {
> -				skipped_kswapd_nodes = true;
> -				continue;
> -			}
> +		    should_skip_kswapd_zone(zone, order, ac)) {
> +			skipped_kswapd_nodes = true;
> +			continue;
>  		}
>  
>  		cond_accept_memory(zone, order, alloc_flags);


  parent reply	other threads:[~2026-11-18 15:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 23:23 [PATCH v2 0/3] mm/page_alloc: get_page_from_freelist cleanups Joshua Hahn
2026-11-16 23:23 ` [PATCH v2 1/3] mm/page_alloc: drop unused gfp_mask from zone_watermark_fast() Joshua Hahn
2026-11-17  9:28   ` Gregory Price (Meta)
2026-11-18 14:59   ` Dev Jain
2026-11-18 15:42     ` Dev Jain
2026-11-16 23:23 ` [PATCH v2 2/3] mm/page_alloc: move the kswapd node skip check into a helper Joshua Hahn
2026-11-17  9:29   ` Gregory Price (Meta)
2026-11-18 15:46   ` Dev Jain [this message]
2026-11-16 23:23 ` [PATCH v2 3/3] mm/vmscan: consolidate promo vs. high watermark checks Joshua Hahn
2026-11-17  9:29   ` Gregory Price (Meta)
2026-11-18 15:57   ` Dev Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf8692ab-f5b6-4ffe-b5ad-02ad59182cc0@arm.com \
    --to=dev.jain@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.jackman@linux.dev \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®