From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 8ABF53081BE for ; Sat, 25 Jul 2026 02:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784947798; cv=none; b=KZ++OmNiVr6jIPo6tlR7hWrpXt8qyborKqYpeiY93zCrowJBVYOJVtr5ImOCtsxY/PmYwjQXc+STLglD7bo/SJ0SmleiCtVxsGvacb6AyVZDHNcG5uglhZWZwjfuuFcSBM70Pjsaa9JUs9zkZGM/+dzNHqEan7Q0e9JMlRdY82A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784947798; c=relaxed/simple; bh=PgJz8d3ErY+IUhGpI8eYSWoQhmB7+MFX/ffV0zF2jik=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HTNz1vsCmDuAVO8F7bRddHbKhgquMQNByQV6QtZm8BFbch0VeSBMT1QuHGpBekNnbl8myMZqI/phIYi74hQowlEzCFmXP7fcDKYvK8mJ6tXAjUTEVuiPKZtPBhw5CFIKi38l1eLAC+pKwYY6bS6HChRDaA23idAomhlAEDdPwuQ= 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=GGyX2xLU; arc=none smtp.client-ip=209.85.208.51 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="GGyX2xLU" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-69f7fa1c548so1268845a12.2 for ; Fri, 24 Jul 2026 19:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784947795; x=1785552595; 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=SsKKexgC0epvBRSVKWwxi0Mvi0wE7H4ciHAWx7tMFGA=; b=GGyX2xLUuy86WcpYeUrMq6IOrR6fHZq/huZQW7MjUS0wfoJloKD1e0B+IEW8FRgLoU KxQL1h5ZU/D0FfVFWE7NKQC0k3u40+etlq9twR8NLPze60NXEmrGPNN9EsOHf2typGLF sHfER442Ct3SKLn0j3aZP8B5GuTBFG/STaMYCNmo9jgqMIK8r90sJjhuVFa3uKt+mdNS LSB/oIQ1sgbWxKwu75nzBE9pNyjcvIa8kbTaGyhcrgScPXkjeAsYUZMRN/WXdTVGvDlY E6bpQI9PWDj/htihDfKN/OEME607O2Y0L0Q/Ti2zXVhYyBnsPIXe5TiICH5VgxrvhV26 tLBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784947795; x=1785552595; 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=SsKKexgC0epvBRSVKWwxi0Mvi0wE7H4ciHAWx7tMFGA=; b=akbX4POhHPaG3zUsw43ltfMpuHoiGts4GgHKbPI/1JV+RzR5qmGDghSDiNySTAY+cQ rnWYa+8DOGWMqmx1cBDpHReylURxK8MFymi/HrIfhLX9PJZmXkSRbQLcdV/1+HIh6yc5 leAFohxBtorbgUecjdL5oCshN/4mbHOlSdOvF0tBwG4MLoGbBGIGS8IeyVcQdywP2k6j V0/LGPa3NNEeIfZSEX9c7Taxnts7YBgr9XGtuq1xUc9ypC2PNKdOvGZBCh5K0MjaJFMw RZSMumBu0zKgHUPIJ+OQs8NmkrzF6ORJYK9Tlc29dB7iCEq7UG4qC8BPM3m+RzCSEbs7 NOZg== X-Forwarded-Encrypted: i=1; AHgh+RrKMeQ0x3iuCV+A6x4MkaTVakWb7+taWKJaAG+EyhWF3+2pC3p1wd+WkKQ8mdOnT6PQ6+5eno9UwJEqYkU=@vger.kernel.org X-Gm-Message-State: AOJu0YzZVAu9fsMJDnvMuPoTl9jtkssn31AEpszdjqSB4t2gj5lRLy0N BAgrRPFU2e8LXz9ikhWg4noanYQ+nhs24oGICnIMSiJZ7t2DxKyIml34 X-Gm-Gg: AR+sD10Nb+ou6bmaiLM9Sw+zRyrIIcFEi1woUjA3ML5zMTE8CCu5mVIQgCxvm03n2lh cSGAsyZBDavYOyX/1nU+89GGzLEG2IF8a1Tm7HYGoYclctygyetqyDHYdKcSFDZIAmQRqcBms9k Novfw4EURfjrLR4BblwmxuLUxaF1i6TVhD4teL/bz01K+Vajtg8IUFHdt1NNg8Vtp25LNTbRdt6 U7JRLwp0Q5mvMZTyvaNMVZflz7i8Zjc12Xctq70Krll1A+pyoLYElEu3P1+Los0hM5oIGOK60/X uwARPPciqz+gEFU0sc81Bt7e52EGUSKy2gP/CPC3Be/ayyZ9rk9ZrMRH77idFSdVAoYGldoJ3qv /fzdT/Koz0B+OtEEdsHseZu0KJrRzOxw6mf18i6RDDZ4BMlmlEo/5Kc/E3Vhw1y21a5JM+WWyGd YQMRWs64YDZRY= X-Received: by 2002:a17:906:6a20:b0:c16:1227:e3d8 with SMTP id a640c23a62f3a-c1f1ea8f9bdmr34720166b.13.1784947794614; Fri, 24 Jul 2026 19:49:54 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32c8f7a2sm416650666b.37.2026.07.24.19.49.52 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 19:49:53 -0700 (PDT) Date: Sat, 25 Jul 2026 02:49:52 +0000 From: Wei Yang To: Yuan Liu Cc: David Hildenbrand , Oscar Salvador , Mike Rapoport , Wei Yang , linux-mm@kvack.org, Nanhai Zou , Pan Deng , Tianyou Li , Chen Zhang , Jason Zeng , linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 2/2] mm/memory_hotplug: improve shrink_zone_span() subsection boundary checks Message-ID: <20260725024952.65lfm2s676obpoue@master> Reply-To: Wei Yang References: <20260723084946.189392-1-yuan1.liu@intel.com> <20260723084946.189392-3-yuan1.liu@intel.com> 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: <20260723084946.189392-3-yuan1.liu@intel.com> User-Agent: NeoMutt/20170113 (1.7.2) 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? > } > > return 0; >@@ -448,21 +455,26 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone, > unsigned long start_pfn, > unsigned long end_pfn) > { >- unsigned long pfn; >+ unsigned long pfn, prev_pfn; > > /* pfn is the end pfn of a memory section. */ > pfn = end_pfn - 1; >- for (; pfn >= start_pfn; pfn -= PAGES_PER_SUBSECTION) { >- if (unlikely(!pfn_to_online_page(pfn))) >- continue; >+ for (; pfn >= start_pfn; pfn = prev_pfn) { >+ unsigned long head_pfn; > >- if (unlikely(pfn_to_nid(pfn) != nid)) >- continue; >+ prev_pfn = pfn - PAGES_PER_SUBSECTION; >+ head_pfn = prev_pfn + 1; > >- if (zone != page_zone(pfn_to_page(pfn))) >+ if (unlikely(!pfn_to_online_page(pfn))) > continue; > >- return pfn; >+ if (likely(pfn_to_nid(pfn) == nid) && >+ zone == page_zone(pfn_to_page(pfn))) >+ return pfn; >+ >+ if (likely(pfn_to_nid(head_pfn) == nid) && >+ zone == page_zone(pfn_to_page(head_pfn))) >+ return pfn; > } > > return 0; >-- >2.47.3 -- Wei Yang Help you, Help me