From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DC5F37106D for ; Thu, 30 Jul 2026 02:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785378982; cv=none; b=Z2/hcw5T0ggAo+aV7zJ4VB1tLUFpZrn1fAvlP75Qutm8SZUqm4i6RnGgfCepEU11W93jG9XNw8bpgf9iH8iNGj+FOFwdLYsG18FmOZN8sTtyrhCO1wfOm+djiipCghl0TOUiJE1d7H8A9UyevjpmEBI0UMceLfO39qbhM8ibI7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785378982; c=relaxed/simple; bh=0Oz9pemNKpLaBJkTEEs1v65pIYh+g4xzHGo9BwhIr4k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Js7Ojphp8xuoKNN6hHHlXzgjHvYb944lPQF88LEQwVjNXhR/74gmZelAfCSLNo/cl9CXZulhxYuDQ2+CmLxBJ4dkM7kN8F5l9qbRuoXgQw6pOaUYyAUUxpOryLE9OzoUrD7LZl51boH3yf8ZvLRCN5J2j1G+fEeCtVD96E7QD84= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QVaZPrr8; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QVaZPrr8" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-69c108fee7fso2264037a12.3 for ; Wed, 29 Jul 2026 19:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785378977; x=1785983777; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:reply-to:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to:content-type; bh=4cMQizCo6RK2ppBslsu0qkK2klwa/3pjLSR8m78mm9U=; b=QVaZPrr8CnTC2PpQRTr8+p3RZWfGUIkYjLiRUiBXFOqdk4KqXHzH0AM9gTvB3ancwB /fqodOQrwgS2L5dveY4DevDPsmVBB0I7wkTYapmWz4JLudgtvCtDsXkHLj2NI0zOT4qm vB9D6KC8MOa2sj1Cvv0+sqiFXAsicSNi4G58cWLHsJMKoUARdYQJSFtQ9E3WUOMJiOlk dfop55MLUix8xoUKoej+unpZumKU5WOFxVEUduNpqyZQjRIbz4odh2ktgVRVSFKDS+Z2 VtHkiYhoDE3PnWA+sD4rBwAiCwk7wPlwHo+HBbQOrYlQHBa7l2ySN3FfbBvUFGjUogLO yOXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785378977; x=1785983777; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:reply-to:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=4cMQizCo6RK2ppBslsu0qkK2klwa/3pjLSR8m78mm9U=; b=HLAOWZARl4eIL42CfnKzYa1oGVeYKMi5ZJ2Bj3Jo6VP0JL4ucedq79MINWXLMOFYug GE2BDnzxe6EJc1e09JE1fqMMjfmI8DkG9l2EMROBUQyRli7OUI5cO7tB/BgkpkRc8kIk H1/3JhoGhzkycEU/sjOd3+hSV2HQGCTvA3lxwZYWHHqwqSL2qsgfDjrNjEKlYCSvCPdX 2rapolFmHSerlSkcqO2G7uSrrX0cRod0Bf7iEZ5RhpL1F/Bmj4XdmlPHpFyfT3aKPFPU RBz1UaSkxpWRhoAb/shHb++ip7x7/Vj0zifrMllKpl+EV8l4j30KgStPoH+M6LaBrOnp KjWA== X-Forwarded-Encrypted: i=1; AHgh+RqJ/wnNt7eKRkvZCMohiW3x3pz0XN3BjARiB8yTNi59nS0+E+JiYJ7b0Gwf3z23VkRiXefso79Du97Qifo=@vger.kernel.org X-Gm-Message-State: AOJu0YwEz2a08N3fkD0Vd4C7EFiLDw7QxocHN9lP7uHnTVmyy7sdW/u5 oqBDzC1qiJRJZltl2BxdsCPGSpkCBerOJPCdVk2RdHDS9vpnu5fiq0jx X-Gm-Gg: AR+sD138Cv0rwoZTqlokvGMkU+Xtb2aEy2oddcLj+zcg6rwMxQL2hVb36pgKYBT3Tdw dY81LTKKG8bn8EZmgAX3Bd9yC2rZUHk2e7W2Zp+6RwjHhvStK1wy+W6+A2w2uq3UNZwqrnZyDxN XpQEaacbV8PCPTCxhBglCUTuZiFEjqu867OhhvvYE5XiTWBanuXhfNnEm2QDCBY0UBY9hoszD8d H3nId0X7t6Wsj5sHf8YuNFt8WDEn+gOOHAr109DY8mZyCTGg8N2CY95w1vw5YPQiEQcZWBPUhKn WiSa2rihw9jylhfROKRrIgwLu62E1vQ/2GqRWk9mNYGXt6Qr31NT8ZvSdvVztxzo9xs0qeAAQe+ 5xqVXwQjkY8YJ9VTmNbdXHDHmfayRfH5rjU/JakWWzlVQuWgX8W9B48vOZSqF7aKdRmmTs9zIxP 4NpjBv6vbqw/cpcvAVNoRaIafaypF1tjrsBMPxzX7lvNbLyz1UoEAC+NciehbN X-Received: by 2002:a17:907:3cd5:b0:c16:36ef:d437 with SMTP id a640c23a62f3a-c1fa55ce077mr39208166b.34.1785378976749; Wed, 29 Jul 2026 19:36:16 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1fa851b723sm16110366b.12.2026.07.29.19.36.15 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jul 2026 19:36:16 -0700 (PDT) Date: Thu, 30 Jul 2026 02:36:14 +0000 From: Wei Yang To: "Liu, Yuan1" Cc: Wei Yang , David Hildenbrand , Oscar Salvador , Mike Rapoport , "linux-mm@kvack.org" , "Zou, Nanhai" , "Deng, Pan" , "Li, Tianyou" , Chen Zhang , "Zeng, Jason" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Message-ID: <20260730023614.fasdjzfl5wz4tsfr@master> Reply-To: Wei Yang References: <20260723084946.189392-1-yuan1.liu@intel.com> <20260723084946.189392-3-yuan1.liu@intel.com> <20260725024952.65lfm2s676obpoue@master> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) On Mon, Jul 27, 2026 at 09:49:39AM +0000, Liu, Yuan1 wrote: >> -----Original Message----- >> From: Wei Yang >> Sent: Saturday, July 25, 2026 10:50 AM >> To: Liu, Yuan1 >> Cc: David Hildenbrand ; Oscar Salvador >> ; Mike Rapoport ; Wei Yang >> ; linux-mm@kvack.org; Zou, Nanhai >> ; Deng, Pan ; Li, Tianyou >> ; Chen Zhang ; Zeng, Jason >> ; 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 >> >Signed-off-by: Yuan Liu >> >--- >> > 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