From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 13B853CB2E9 for ; Mon, 13 Apr 2026 13:06:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776085599; cv=none; b=PGtJqptU0u0+8ZtSWGla1CXDdqCl30GLhBw1++sfQUbziTqlBQtR60Ek7ZJTXh0VrChM4QAZxyF++N6Lt/dJXqyo2ZuVuoTeuriXhIVUuCxYS461U+4bGCT0KR0nEgtY8rk3SOMbEGQqFgLvbB5gvLxSVA0meWGJTmimcqgPpzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776085599; c=relaxed/simple; bh=hccnx1yH2HrytWXO5+SlhQ6hFw8LpDYqUUNfoWtV5pQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V2I5qfuvABNvYyOf4b2OWc3NLfaCFBLS+dyJzrNunU8jTTn/5qPbDtm3DBZA+QveM13xOPAWBPu1u9RqKfqqdTdWvO4i4kxMGrqzvYOL84tFSQgPN0FgXqRUtsBjcE+oCi4LQquYFUBiTFc0E8vCMtFWWKDOUFaw0+hjBZ9F1es= 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=pxyjkjZ/; arc=none smtp.client-ip=209.85.218.50 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="pxyjkjZ/" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-b9c04152730so663200066b.0 for ; Mon, 13 Apr 2026 06:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776085595; x=1776690395; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=gsK1P1os6YsOme6bbZbfr2u9YSSoYPTr268tXuAFbNY=; b=pxyjkjZ/Tf6ivwn/5d3p4Ne15egWY9SUmf63+mNxNj0I6TgTqORG/whrL74va28DEo iT4DoUywamr6tMfHanrqiaG1PzsqRa6Y3R2GRIC8n4pa7cwta919CfSlUDyNb0Gjw3Y8 joeZj0NEWK1bhOLDUlNjRGIlVNKnj/u/JOR+EaF0x1vbribcXynBr6yhsyaCERYzy5ZX 2xj1d6v85EWW4snq69m/FHSDjlyWjQLlSxrJ74QyT7y+eHrl6nWwUFKlBaIZQUdiluhG YBjfL+2I7573TPVfghXSpplfNGbVUZijqC6RegCTTg0LSlrbxUXukWyomsPRafbsHF/u dElw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776085595; x=1776690395; h=user-agent:in-reply-to:content-disposition: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; bh=gsK1P1os6YsOme6bbZbfr2u9YSSoYPTr268tXuAFbNY=; b=f9Ry+nA5OcYaiF/6UjjQl42lMDpyz8W/Oqz7bcK8Ax+MGIjMA+ezeFDlURjlnSmwaS UksajkvzjKl3qm/d3b9dbw6mtCkQ44x01tyfZrw4lzs4J/Xo2rkPT9kEoZcfMrl+EF1S 6SnmBQ2rml3QNGJ0V3qv1/Xs87RAjzbJBqxny9qUBxl3VA8FfpX00YWI0lwOPi1gadNs yfPLJBliWv/tL2Ja388VNMNB+s0Ddj4aq+T64q3PKnAtq1xbcKNN4Xk6SMpELe1rCBaj NarXXyRUeKSGQp1onLyV5DgZ2/0R8Wr+nVzNaGmV6hTKYk+aUaVWnS8z5mWTkAIi+5we VB/A== X-Forwarded-Encrypted: i=1; AFNElJ/DhuA+8qIjn6gVZq2gTonvM7aI7TZEutYktSDwZdJvTntTj70hSpBvBSqIgyvpCvKSF0P5QHoaBIIHuZk=@vger.kernel.org X-Gm-Message-State: AOJu0YxAWYnfFT32AERlPr3TX3/mvdKE/wIyx075RXENFlUCjHU75ckl SnDPmTSNP+2WsWo7vgUR+Jj+8O9VXjIT2CS1QcFdycXy9eqImbi3O1mE X-Gm-Gg: AeBDieu58+psh5bouJ4cOcE0ck78CdVBAfyLHGFg2CtiUuyJLMy8Upd79DUa3wUZssv dvyhcl96N5LUu3nYzxh9vtI+C1hr53r8j/mnmnwVquAPN0KIW6bvShTEg+G6ji3/JJW4cZ6dB/p /k5u8+DxiyzuOByiiEfvHjfVXNVnLFqLPY7K8i2d/Q2kBYQZlvwmIN3cFEjwzkn1qTDrWAZuDNE rlJmnrhE7+2eQafmmTXRlYpisjworoVGehaQwZz31SgGdsnK1V5tbxV1+HrV3fDjy/pgrAMszHC 3Ud0jBKfrzDO+9HC1yOPofQ5YJHpEcktS1NEbh+pfLpedyszebWlZ5y+kZej/jK6zCSxaF05l2t tQVn2G2Ma9sGqAi3mxWdb3Wh25vPeQmsi8ExRYc4laJyGOMjwbCWBhavkBPVcsVyZoF2yvHYaZU 5LAK+zFX5Bw0F4z06W2AGFFA== X-Received: by 2002:a17:906:6a2a:b0:b9d:75d7:fb74 with SMTP id a640c23a62f3a-b9d75d83c4fmr647758966b.20.1776085594797; Mon, 13 Apr 2026 06:06:34 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9d6de97e93sm305240866b.9.2026.04.13.06.06.33 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Apr 2026 06:06:33 -0700 (PDT) Date: Mon, 13 Apr 2026 13:06:33 +0000 From: Wei Yang To: Yuan Liu Cc: David Hildenbrand , Oscar Salvador , Mike Rapoport , Wei Yang , linux-mm@kvack.org, Yong Hu , Nanhai Zou , Tim Chen , Qiuxu Zhuo , Yu C Chen , Pan Deng , Tianyou Li , Chen Zhang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] mm/memory hotplug/unplug: Optimize zone contiguous check when changing pfn range Message-ID: <20260413130633.knzkliyqvjhuz2kd@master> Reply-To: Wei Yang References: <20260408031615.1831922-1-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: <20260408031615.1831922-1-yuan1.liu@intel.com> User-Agent: NeoMutt/20170113 (1.7.2) On Tue, Apr 07, 2026 at 11:16:15PM -0400, Yuan Liu wrote: [...] > >-void set_zone_contiguous(struct zone *zone) >-{ >- unsigned long block_start_pfn = zone->zone_start_pfn; >- unsigned long block_end_pfn; >- >- block_end_pfn = pageblock_end_pfn(block_start_pfn); >- for (; block_start_pfn < zone_end_pfn(zone); >- block_start_pfn = block_end_pfn, >- block_end_pfn += pageblock_nr_pages) { >- >- block_end_pfn = min(block_end_pfn, zone_end_pfn(zone)); >- >- if (!__pageblock_pfn_to_page(block_start_pfn, >- block_end_pfn, zone)) >- return; >- cond_resched(); >- } >- >- /* We confirm that there is no hole */ >- zone->contiguous = true; >-} >- Hi, I may see a behavioral change after this patch. * An originally non-contiguous zone would be detected as contiguous after this patch. My test setup: Did test in a qemu with 6G memory with memblock_debug enabled. And adjust the /proc/zoneinfo to display zone->contiguous field. Originally, memblock_dump shows: MEMBLOCK configuration: memory size = 0x000000017ff7dc00 reserved size = 0x0000000005a9d9c2 memory.cnt = 0x3 memory[0x0] [0x0000000000001000-0x000000000009efff], 0x000000000009e000 bytes on node 0 flags: 0x0 memory[0x1] [0x0000000000100000-0x00000000bffdefff], 0x00000000bfedf000 bytes on node 0 flags: 0x0 +- memory[0x2] [0x0000000100000000-0x00000001bfffffff], 0x00000000c0000000 bytes on node 1 flags: 0x0 And zone range shows: Zone ranges: DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000001bfffffff] <--- entire last memblock region With the last memblock region fits in Node 1 Zone Normal. Then I punch a hole in this region with 2M(subsection) size with following change, to mimic there is a hole in memory range: @@ -1372,5 +1372,8 @@ __init void e820__memblock_setup(void) /* Throw away partial pages: */ memblock_trim_memory(PAGE_SIZE); + memblock_remove(0x140000000, 0x200000); + memblock_dump_all(); } Then the memblock dump shows: MEMBLOCK configuration: memory size = 0x000000017fd7dc00 reserved size = 0x0000000005a97 9c2 memory.cnt = 0x4 memory[0x0] [0x0000000000001000-0x000000000009efff], 0x000000000009e000 bytes on node 0 flags: 0x0 memory[0x1] [0x0000000000100000-0x00000000bffdefff], 0x00000000bfedf000 bytes on node 0 flags: 0x0 +- memory[0x2] [0x0000000100000000-0x000000013fffffff], 0x0000000040000000 bytes on node 1 flags: 0x0 +- memory[0x3] [0x0000000140200000-0x00000001bfffffff], 0x000000007fe00000 bytes on node 1 flags: 0x0 We can see the original one memblock region is divided into two, with a hole of 2M in the middle. Not sure this is a reasonable mimic of memory hole. Also I tried to punch a larger hole, e.g. 10M, still see the behavioral change. The /proc/zoneinfo result: w/o patch Node 1, zone Normal pages free 469271 boost 0 min 8567 low 10708 high 12849 promo 14990 spanned 786432 present 785920 contigu 0 <--- zone is non-contiguous managed 766024 cma 0 with patch Node 1, zone Normal pages free 121098 boost 0 min 8665 low 10831 high 12997 promo 15163 spanned 786432 present 785920 contigu 1 <--- zone is contiguous managed 773041 cma 0 This shows we treat Node 1 Zone Normal as non-contiguous before, but treat it a contiguous zone after this patch. Reason: set_zone_contiguous() __pageblock_pfn_to_page() pfn_to_online_page() pfn_section_valid() <--- check subsection When SPARSEMEM_VMEMMEP is set, pfn_section_valid() checks subsection bit to decide if it is valid. For a hole, the corresponding bit is not set. So it is non-contiguous before the patch. After this patch, the memory map in this hole also contributes to pages_with_online_memmap, so it is treated as contiguous. Some question: I suspect with !SPARSEMEM_VMEMMEP, we always treat Zone Normal as contiguous, because we don't set subsection. So it looks the behavior is different from SPARSEMEM_VMEMMEP. But I didn't manage to build kernel with !SPARSEMEM_VMEMMEP to verify. I see the discussion on defining zone->contiguous as safe to use pfn_to_page() for the whole zone. For this purpose, current change looks good to me. Since we do allocate and init memory map for holes. But pageblock_pfn_to_page() is used for compaction and other. A pfn with memory map but no actual memory seems not guarantee to be a usable page. So the correct usage of pageblock_pfn_to_page() is after pageblock_pfn_to_page() return a page, we should validate each page in the range before using? I am a little lost here. > /* > * Check if a PFN range intersects multiple zones on one or more > * NUMA nodes. Specify the @nid argument if it is known that this >-- >2.47.3 -- Wei Yang Help you, Help me