From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 E0B67187346 for ; Sun, 9 Aug 2026 03:12:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786245131; cv=none; b=AKXSyalTAVl5H4aay0eMPyAf9gF8gqtpht2CcLNIMqVHhIe2UViCNaXCjx+96Yvo9vkOhxi+YjcekyKMtyYqdCB4lQvT8Stxk4pZ6Cwc5NEhYlNlraI8m9CuOJ1USbJ7H52SaJflhVdeo5qFi376KYj1lKK0vR5rCprTAZB1828= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786245131; c=relaxed/simple; bh=emIZmQkfG4RHRX3yKWe1ftlQQS6/OLD6WarrxlJDY2M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pCz9ufBVSePGtWdDcPWx1BE9h0gAshCkGduo0GM8S7eKwEFiYJzBTvMyj6MNk+w/9oY6fKH3D5TOMch1vU+H6DUO3SK9JeI9NcMFYtSwpwo9TzOg7VFONFRq4T1dQzx5o96ivoYN6ARcYPiy2K+H7ARe21ChUJRhKGM+l/a/slk= 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=BaCGOwpo; arc=none smtp.client-ip=209.85.218.48 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="BaCGOwpo" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-c15d47266baso64154966b.3 for ; Sat, 08 Aug 2026 20:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786245128; x=1786849928; darn=vger.kernel.org; h=user-agent:in-reply-to:content-transfer-encoding :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=gb4FrJ3xdhpqkyi3C55lynZ/symBerXShmcXNlDSbiM=; b=BaCGOwpotYZIL2B7IQApzM4URo+zun5TkRIN63S251Ax6EA+vO3MDgDyyiMnj9QeLi XAZDQdv/xymy44dSiRN0bILHX9jkjL9ep3BBRie6bdC+1yMAxNYDZH2n6+LLjwpPT9T4 2n4bKu2mnzrLq8350bR+kQ7fIjREYFNljj6tFx+FcJ7oLFDmcUQRFY8AkxK6igCDEs+c JrYIk1A1S5CPQrECmL2k7IltVtj+flVuCQUw8FSoWNLJUBEP41SJoR2Vy0HrIxRYI7kc 8eU1LndFd5ku4X+Gt107F2C/Hg7/H6GIZ8cfwZmKb8O5IBmo5J0sqi1kHN9u+xhT8gzH pwjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786245128; x=1786849928; h=user-agent:in-reply-to:content-transfer-encoding :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=gb4FrJ3xdhpqkyi3C55lynZ/symBerXShmcXNlDSbiM=; b=Y6emEISfFZvgnJi561bc/bBwIpXEvmTWxfA8l2ougpkRyGThfuet/QhpcH6IQgDsjX ud37z0q9+x9WqMXqVEpwU+SU7aGEwSKyXX9SYWHc7PpCe/bkyuowkweFcSgbvL/EaoQw mcs65GszHa/KQZo4E7a8vtcWJNRY+0sgHluXYLNwKdAp7QSq6EnORIWory2qpJmga/Vp werWfOdq3u509JmTtneY8ccs+c0j9YbsKT/NIelfLLeVUwaaGfcdJX0sUaoLWCXsecqg DzRN5bNKmCtMNxXKnkJ8gkqYFdO+TJDiy+jZy7keDdcLK89WU5wJ+9MaQxM32YvZbdV9 TjWw== X-Forwarded-Encrypted: i=1; AHgh+RruUd+nfOPxDIriA3KoiesN3FI5Hl5MytoRmYrj5YWQQLH18zOfR6sFLnK/SO96ykUkoyNqVVB7+MFbgP4=@vger.kernel.org X-Gm-Message-State: AOJu0YxY/6aPNZMVkw5V4acAoZkRM6lH6rVEyhRl81v4TlSMoCFB4wx7 /dKaJDm5+T16NfbzUg05KekXwtXVBXLExD9k+LejOvrfzn/lB6PaYxrw X-Gm-Gg: AR+sD13mFat/FFp50cMs/ETPfWfjalHrHn/ca+RLcFlbN6GgpxuJ8DNt9sGUEgn/R4W 0mHB7eoFvW0qivzjKajBnhxMNJPSa8tpqUEyHOrsvH8D0k6sOvnU1w3fQBAUbp1lNlojhjA9ART MPGJmq3+OK0G5B8qxEcHJysN6Twu5FjyRvd0jtvw19DJeObbZXewC3TW6aavwepFuyPs9xNlJb1 xoizT3ILsDzBI0RZz8VRpn3N3fQo3mDaKN6ECad2wN7DIduuLzaROMIllpE7LVBhnLHdBQfIWF8 IMtt5QJh0SClG47nrwY1ahlKj/T5C8XLwCIXIPshVf+SIrwXXB8C1TMkQgmSr32RONazfN4D3On sUOTCLu5e82R8wmQy1sNckvtPzQ09M7k8xnAYk5MO95vCFnjlf3W7BluqUGen7MSLr0NN7DmVDO A8qtiKbAYQblj2Sf7EA2ZpHfaZxH55cjHVs+LNOGQqT+Z0N0ia2MDsxf6eWZY= X-Received: by 2002:a17:907:3c93:b0:c16:769b:9838 with SMTP id a640c23a62f3a-c20731a9d01mr981067166b.5.1786245127750; Sat, 08 Aug 2026 20:12:07 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c2080cff006sm216562366b.63.2026.08.08.20.12.05 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Aug 2026 20:12:06 -0700 (PDT) Date: Sun, 9 Aug 2026 03:12:05 +0000 From: Wei Yang To: "Liu, Yuan1" Cc: "David Hildenbrand (Arm)" , 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 1/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range Message-ID: <20260809031205.h6skr3uluj3cnn7t@master> Reply-To: Wei Yang References: <20260723084946.189392-1-yuan1.liu@intel.com> <20260723084946.189392-2-yuan1.liu@intel.com> <2cbd42e1-b5bb-474c-b0e7-ce3f46541891@kernel.org> <0b02ef3e-363f-4b49-a208-54cdfea56c75@kernel.org> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) On Fri, Aug 07, 2026 at 12:15:42PM +0000, Liu, Yuan1 wrote: >> -----Original Message----- >> From: David Hildenbrand (Arm) >> Sent: Friday, August 7, 2026 7:30 PM >> To: Liu, Yuan1 ; Oscar Salvador ; >> Mike Rapoport ; Wei Yang >> Cc: linux-mm@kvack.org; Zou, Nanhai ; Deng, Pan >> ; Li, Tianyou ; Chen Zhang >> ; Zeng, Jason ; linux- >> kernel@vger.kernel.org >> Subject: Re: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous >> check when changing pfn range >> >> On 8/6/26 11:52, Liu, Yuan1 wrote: >> >> -----Original Message----- >> >> From: David Hildenbrand (Arm) >> >> Sent: Thursday, August 6, 2026 4:46 PM >> >> To: Liu, Yuan1 ; Oscar Salvador >> ; >> >> Mike Rapoport ; Wei Yang >> >> Cc: linux-mm@kvack.org; Zou, Nanhai ; Deng, Pan >> >> ; Li, Tianyou ; Chen Zhang >> >> ; Zeng, Jason ; linux- >> >> kernel@vger.kernel.org >> >> Subject: Re: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous >> >> check when changing pfn range >> >> >> >> >> >>> >> >>> Will do. >> >>> >> >>> >> >>> pages_with_online_memmap counts all PFNs where pfn_to_online_page() is >> >>> valid. With CONFIG_SPARSEMEM_VMEMMAP, pfn_section_valid() operates at >> >>> PAGES_PER_SUBSECTION granularity — when any page in a subsection has >> >>> memory, the entire subsection is valid/online. So we align to >> subsection >> >>> boundaries to include hole pages within partially-populated >> subsections. >> >> >> >> But we must never account exceeding the zone range. So I don't >> understand >> >> why we >> >> would have to care about PAGES_PER_SUBSECTION here at all? >> > >> > We never account beyond the zone range, because `sub_start` and >> > `sub_end` are still clamped to the zone boundaries after the >> > alignment. >> > >> > The subsection alignment is needed for hole PFNs between memblocks >> > within the zone. These hole PFNs are valid for >> > `pfn_to_online_page()`, because they sit in a subsection that has >> > memory, so the whole subsection's memmap is online. >> > >> > |----------- zone range -----------| >> > >> > +-----------+---------+------------+ >> > + memblock 1| hole | memblock 2 | >> > +-----------+---------+------------+ >> > ^ >> > | >> > | >> > subsection boundary >> >> Right, but init_unavailable_range() can just return how many were actually >> initalized? Why can't we piggy-back on that? >> >> I think we had something similar previously, why can't we use that? >> >> We know the zone span, so we can just account all the mmap in the zone >> span >> that we initialize. >> >> What is the problem with that? > >Hi David > >My understanding is that init_unavailable_range() initializes all >PFNs that satisfy pfn_valid(), but not all of them satisfy >pfn_to_online_page(), since some PFNs belong to subsections that are >not online. > >You previously mentioned: > > pfn_valid() says early sections always have a full memmap, so even invalid > subsections have a memmap. pfn_to_online_page() says an invalid subsection > cannot be online and its content must be stale. for_each_valid_pfn() follows > pfn_valid() semantics, and we use it to initialize memmap that is not going > to be online and account it as pages_with_online_memmap, which is wrong. > > The cleanest approach is to avoid allocating memmap for subsections, which > also removes the special early-section handling from pfn_valid() and > for_each_valid_pfn(). > >I also share the concerns raised by Sashiko in the analysis below [1]: > > Scanners like isolate_migratepages_block() will then blindly iterate through > the pageblock and access the completely uninitialized struct pages of the hole, > leading to functional errors or kernel panics when reading these zero-filled > structures via macros like PageHuge() or page_zone(). > >That's why we went with the current approach in v6 instead of your >earlier suggestion. I'd really appreciate your guidance on which >direction you think would be more appropriate. > >[1] https://sashiko.dev/#/patchset/20260520093457.3719960-1-yuan1.liu%40intel.com > Hi, Yuan & David One thing I found is __pageblock_pfn_to_page() is ambiguous when pageblock contains 2 subsections. The subsection size is fixed, which is 2^21=2M. But pageblock is not fixed size. If !CONFIG_HUGETLB_PAGE && !CONFIG_TRANSPARENT_HUGEPAGE, default pageblock size is 4K * 2 ^ 10 = 4M, which contains 2 subsection. For a pageblock in early section, __paeblock_pfn_to_page() result is different when the hole is at the beginning or at the end. Like what I did in [1], I punch a hole in Zone Normal with 2M size. If the hole is at the beginning of the pageblock, the zone is non-contiguous. [ 0.004079] memory[0x2] [0x0000000100000000-0x000000013fffffff], 0x0000000040000000 bytes on node 0 flags: 0x0 [ 0.004080] memory[0x3] [0x0000000140200000-0x00000001bfffffff], 0x000000007fe00000 bytes on node 0 flags: 0x0 If the hole is at the end of the pageblock, the zone is contiguous. [ 0.004068] memory[0x2] [0x0000000100000000-0x00000001401fffff], 0x0000000040200000 bytes on node 0 flags: 0x0 [ 0.004068] memory[0x3] [0x0000000140400000-0x00000001bfffffff], 0x000000007fc00000 bytes on node 0 flags: 0x0 The reason is in __pageblock_pfn_to_page() we have different requirement for start_pfn and end_pfn. Hmm... and things would be complicated as pageblock is PAGE based but subsection is size based. If we have large PAGE_SIZE... Also when pageblock_pfn_to_page() is introduced in commit 7d49d8868336 ("mm, compaction: reduce zone checking frequency in the migration scanner"), we assume there won't be [node0 node1 node0] interleave within a single pageblock. Would this still stand for large PAGE_SIZE? [1]: https://lore.kernel.org/all/20260408031615.1831922-1-yuan1.liu@intel.com/T/#u >Best Regards, >Liu, Yuan > >> Cheers, >> >> David -- Wei Yang Help you, Help me