mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: "Liu, Yuan1" <yuan1.liu@intel.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
	David Hildenbrand <david@kernel.org>,
	Oscar Salvador <osalvador@suse.de>,
	Mike Rapoport <rppt@kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"Zou, Nanhai" <nanhai.zou@intel.com>,
	"Deng, Pan" <pan.deng@intel.com>,
	"Li, Tianyou" <tianyou.li@intel.com>,
	Chen Zhang <zhangchen.kidd@jd.com>,
	"Zeng, Jason" <jason.zeng@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks
Date: Thu, 30 Jul 2026 02:36:14 +0000	[thread overview]
Message-ID: <20260730023614.fasdjzfl5wz4tsfr@master> (raw)
In-Reply-To: <MW4PR11MB6936598686BD5FA7B2FE9181A3CC2@MW4PR11MB6936.namprd11.prod.outlook.com>

On Mon, Jul 27, 2026 at 09:49:39AM +0000, Liu, Yuan1 wrote:
>> -----Original Message-----
>> From: Wei Yang <richard.weiyang@gmail.com>
>> Sent: Saturday, July 25, 2026 10:50 AM
>> To: Liu, Yuan1 <yuan1.liu@intel.com>
>> Cc: David Hildenbrand <david@kernel.org>; Oscar Salvador
>> <osalvador@suse.de>; Mike Rapoport <rppt@kernel.org>; Wei Yang
>> <richard.weiyang@gmail.com>; linux-mm@kvack.org; Zou, Nanhai
>> <nanhai.zou@intel.com>; Deng, Pan <pan.deng@intel.com>; Li, Tianyou
>> <tianyou.li@intel.com>; Chen Zhang <zhangchen.kidd@jd.com>; Zeng, Jason
>> <jason.zeng@intel.com>; linux-kernel@vger.kernel.org
>> Subject: Re: [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span()
>> subsection boundary checks
>> 
>> On Thu, Jul 23, 2026 at 04:49:46AM -0400, Yuan Liu wrote:
>> >When shrinking a zone span after removing a PFN range,
>> >find_smallest_section_pfn() and find_biggest_section_pfn()
>> >only checked one edge PFN in each subsection for nid/zone matching.
>> >
>> >If a memory or hole boundary falls in the middle of a subsection,
>> >that edge PFN may belong to a different nid/zone, causing the helpers
>> >to miss a valid PFN within that subsection.
>> >
>> >Fix this by checking both subsection edge PFNs for nid/zone matching.
>> >Keep a single pfn_to_online_page() check per subsection, since online
>> >state is the same for all PFNs in a subsection.
>> >
>> >Reviewed-by: Jason Zeng <jason.zeng@intel.com>
>> >Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
>> >---
>> > mm/memory_hotplug.c | 42 +++++++++++++++++++++++++++---------------
>> > 1 file changed, 27 insertions(+), 15 deletions(-)
>> >
>> >diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
>> >index 4c699fd9c479..3a281d595207 100644
>> >--- a/mm/memory_hotplug.c
>> >+++ b/mm/memory_hotplug.c
>> >@@ -427,17 +427,24 @@ static unsigned long find_smallest_section_pfn(int
>> nid, struct zone *zone,
>> > 				     unsigned long start_pfn,
>> > 				     unsigned long end_pfn)
>> > {
>> >-	for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SUBSECTION) {
>> >-		if (unlikely(!pfn_to_online_page(start_pfn)))
>> >-			continue;
>> >+	unsigned long next_pfn;
>> >
>> >-		if (unlikely(pfn_to_nid(start_pfn) != nid))
>> >-			continue;
>> >+	for (; start_pfn < end_pfn; start_pfn = next_pfn) {
>> >+		unsigned long tail_pfn;
>> >
>> >-		if (zone != page_zone(pfn_to_page(start_pfn)))
>> >+		next_pfn = start_pfn + PAGES_PER_SUBSECTION;
>> >+		tail_pfn = next_pfn - 1;
>> >+
>> >+		if (unlikely(!pfn_to_online_page(start_pfn)))
>> > 			continue;
>> >
>> >-		return start_pfn;
>> >+		if (likely(pfn_to_nid(start_pfn) == nid) &&
>> >+		    zone == page_zone(pfn_to_page(start_pfn)))
>> >+			return start_pfn;
>> >+
>> >+		if (likely(pfn_to_nid(tail_pfn) == nid) &&
>> >+		    zone == page_zone(pfn_to_page(tail_pfn)))
>> >+			return start_pfn;
>> 
>> Here we are checking range [start_pfn, tail_pfn]. When we come here, it
>> means
>> start_pfn's nid or zone doesn't match our expectation. But if tail_pfn
>> does,
>> why it still return start_pfn?
>
>Hi Wei
>
>If start_pfn falls into a hole while tail_pfn still belongs to a valid
>memblock in this zone, skipping the subsection would cause
>shrink_zone_span() to shrink the zone span too aggressively, excluding
>valid PFNs from the zone.
>
>Since init_unavailable_range() initializes hole pages with the correct
>zone/nid, the start_pfn check always succeeds here, making the tail_pfn
>check redundant today.
>
>That said, I wonder if it is still worth keeping this check so that
>shrink_zone_span() does not depend on how hole pages are initialized.
>

Looks reasonable.

I search the discussion history, and found David suggest this fix in [1] with
following statement.

  Well, unless we have an odd case where the hole+memory starts in the
  middle of a "PAGES_PER_SUBSECTION". That would already be problematic if
  memory starts/ends in the middle of a PAGES_PER_SUBSECTION chunk. I
  don't such a case exists.
  
  We could improve shrink_zone_span() to let
  find_smallest_section_pfn/find_biggest_section_pfn test the pfn_to_nid()
  and page_zone() not on;y on the smallest/highest pfn, but also on the
  highest/smallest PFN in a PAGES_PER_SUBSECTION chunk.

I am trying to understand the exact case David described, but not fully get
it. Would you mind describing more, so we would make sure not missing the
point.

[1]: https://lore.kernel.org/all/e86fee84-08d8-4563-8596-e40d8e196799@kernel.org/T/#u

-- 
Wei Yang
Help you, Help me

  reply	other threads:[~2026-07-30  2:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23  8:49 [PATCH v6 0/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Yuan Liu
2026-07-23  8:49 ` [PATCH v6 1/2] " Yuan Liu
2026-08-05 11:53   ` David Hildenbrand (Arm)
2026-08-06  7:23     ` Liu, Yuan1
2026-08-06  8:45       ` David Hildenbrand (Arm)
2026-08-06  9:52         ` Liu, Yuan1
2026-08-07 11:29           ` David Hildenbrand (Arm)
2026-08-07 12:15             ` Liu, Yuan1
2026-08-09  3:12               ` Wei Yang
2026-08-10 14:04               ` David Hildenbrand (Arm)
2026-08-11 12:23                 ` David Hildenbrand (Arm)
2026-08-12  9:17                   ` Liu, Yuan1
2026-08-12 10:11                     ` David Hildenbrand (Arm)
2026-08-15  1:55                   ` Wei Yang
2026-08-19 15:57                     ` David Hildenbrand (Arm)
2026-07-23  8:49 ` [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Yuan Liu
2026-07-25  2:49   ` Wei Yang
2026-07-27  9:49     ` Liu, Yuan1
2026-07-30  2:36       ` Wei Yang [this message]
2026-07-30  7:57         ` Liu, Yuan1
2026-08-01  0:59           ` Wei Yang
2026-08-05 11:02   ` David Hildenbrand (Arm)
2026-08-06  7:14     ` Liu, Yuan1
2026-08-07  3:22     ` Wei Yang
2026-08-07 11:25       ` David Hildenbrand (Arm)
2026-08-05  9:40 ` [PATCH v6 0/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Liu, Yuan1

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=20260730023614.fasdjzfl5wz4tsfr@master \
    --to=richard.weiyang@gmail.com \
    --cc=david@kernel.org \
    --cc=jason.zeng@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nanhai.zou@intel.com \
    --cc=osalvador@suse.de \
    --cc=pan.deng@intel.com \
    --cc=rppt@kernel.org \
    --cc=tianyou.li@intel.com \
    --cc=yuan1.liu@intel.com \
    --cc=zhangchen.kidd@jd.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®