From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70E21C021A0 for ; Thu, 13 Feb 2025 17:57:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAECF6B007B; Thu, 13 Feb 2025 12:57:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D37D36B0083; Thu, 13 Feb 2025 12:57:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD8726B0085; Thu, 13 Feb 2025 12:57:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9E4426B007B for ; Thu, 13 Feb 2025 12:57:02 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2621D121510 for ; Thu, 13 Feb 2025 17:57:02 +0000 (UTC) X-FDA: 83115677484.20.83D2336 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 6636C160003 for ; Thu, 13 Feb 2025 17:57:00 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739469420; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yBiCA7GTWlwZBiI1uNHcKTi/LdIiN7a/o0uUT4u6tw8=; b=aOEDTM5vtzruJl6/bfFXjwnmHQGxgXOiTq6OvfDLBEACXM1+NY57tEa2wuRDxzDu9lxiJq dXP7vibNZ88d0EG2WV+cVnyuaDjK7OCMXTBA3ieI5Q5NGgcAQhW8mQuGonKV3A7vv36Kyi 6PLbMUbUi2VdI8z2d3mKH8rMu/IRMwI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739469420; a=rsa-sha256; cv=none; b=ldSGxM0OELDGfuLI+yxj/IHV/c2E4J4LVNhvcgmuUt2qeyLNYbGqXw/LOYS59pHr6DHWrB iQOHu8ATZNiRsfrX8JCHPQZs2tCqfRy9wUuovNXqnnm5dSE9HvM66HdursC5kbw9JNzOqJ 6Vxv0pgoBD4HrL9TOPXlhlCbz0JOBms= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B6B9F5C58ED; Thu, 13 Feb 2025 17:56:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 220B4C4CED1; Thu, 13 Feb 2025 17:56:55 +0000 (UTC) Date: Thu, 13 Feb 2025 17:56:53 +0000 From: Catalin Marinas To: David Hildenbrand Cc: Zhenhua Huang , anshuman.khandual@arm.com, will@kernel.org, ardb@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, joey.gouly@arm.com, dave.hansen@linux.intel.com, akpm@linux-foundation.org, chenfeiyang@loongson.cn, chenhuacai@kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, quic_tingweiz@quicinc.com, stable@vger.kernel.org Subject: Re: [PATCH v6] arm64: mm: Populate vmemmap/linear at the page level for hotplugged sections Message-ID: References: <20250213075703.1270713-1-quic_zhenhuah@quicinc.com> <9bc91fe3-c590-48e2-b29f-736d0b056c34@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6636C160003 X-Stat-Signature: xsm69yqds4b6owd69s7rbb5i9dpejmet X-Rspam-User: X-HE-Tag: 1739469420-303298 X-HE-Meta: U2FsdGVkX1/Sxn8OksDK23E86Etwh+cISkE3I5iIs9q/azJ9QYGWi21y9FWRqeJOCM1KmftO6VD8w0Pues328EJkowtrx31C4VTIFEjmGOvERTotIfENF/QqDcDk+djTjcculPJ0kzNglKO6kw9Mzevj9EaRR2HY8EWJuP7VMePtAbVIsTwTPrqjIfNXlC23+j4Z2SQwdxNFY94p9mpjP/68Cs71JXT9wTacun5PtkwsdFeY4qeXx+ch/p7Sy/CduJGV8GODlI0QJiT5MPHsp+erm8FWoJQppLvQPYBh7FsJr0d1GsantGqw5JmObDP5bCT8UEm9F6mCzPdgI/pK5F9zNW9gloILimhQrIFjTbXfOcSZVaHToMoD6hIefoiGGCOW/7m4uz+FtGA1tke/zjFSHxe60eiRtpG3CH0GM2trfYVodjCvMrOl5dHidPDaIDYEhnmlgoRldlhV6zLL600v74O6aFuaEE/25aPilBi4VxvgyYhqzUWXzj3Spx/QcVkQkL24thRQ2fzomL3+vHdsNxTaykZ8ALnGAP07ysb9ecx04Sry/bTgj+XlTEMK8z7cwoHa79K+PAJpd1qOQn/TchaKAinh48hAcqLEXAF/1ImJqcnFEvzOViRI5XzUzCVMlQ6AY9tjORuToTiLs2wVf+xAKAJhyEik0kYovwMUHRX7GxXt/W0qmNwPsZnfS6NIbGmLdsupecG7vLh5c/txouY9Ufhv193iEkIvH7LQkwIPEBg/NbNBItbMwTydofRI2z85bIW58qB8qkmNMXXdxxhuWkr4kaRSXe50ojLIh0y6dJIodnHCIct08tOjb0OvtmQeE0BTf3ZX8UjtZ2NIClHET3I5r1EFGYIB+Am0zCZCoJk27+D+/6pXK3R3hMQKplekAK1P+/lfKtpSZZYxNtAON+/l+2C8KZ3NCDmpA219HtjfegT3b2k0ocIegwSkrTxABl1/nstsS6U xbfSGDrS 1J4m0RTPvJZHldGxtPx+brvP8J0pfxMn2sf2gYXnng4A6THpQkDnge+CqYUBgur00VdL5QDQ1aTB559Dhu8x1TKA3qbjKqH4rwFAa8YheEYuyZQkM921DCtAOqiBTcTocnY0Oqlak+0fvssih13WRroR0Xco9bSm/24o4fGltiuZUoKpAVaaXmahvP6KCbHn80QcUMOoI/UFrjGBgqULiwI9RY8QknIFYxnCFvi6Edzhr7A8QqF7ef3U4Rc9jVXMO+Wc6255BS1OgDT4yhqc/+7lqdxkhM8m/IXPubnazOf9VfBa59+M/BJ1mmtB4pgQAAmGpaC85tb2r0ULJZp8YGJIF7VGfNQ0aeBQOV1LOhFInz81ADZNtFQZMpTeDsRkhxypF3rYv5+GL9QjSPmywS1/Ug10lKeT5Ylzo78S+pI8P9AAkbZ13Q2PbLkzDNumNlAlqeNcC+8o8wzzd17rADFJkaFSzN0+BwPKhZlxYZnuNnvo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Feb 13, 2025 at 05:16:37PM +0100, David Hildenbrand wrote: > On 13.02.25 16:49, Catalin Marinas wrote: > > On Thu, Feb 13, 2025 at 01:59:25PM +0100, David Hildenbrand wrote: > > > On 13.02.25 08:57, Zhenhua Huang wrote: > > > > On the arm64 platform with 4K base page config, SECTION_SIZE_BITS is set > > > > to 27, making one section 128M. The related page struct which vmemmap > > > > points to is 2M then. > > > > Commit c1cc1552616d ("arm64: MMU initialisation") optimizes the > > > > vmemmap to populate at the PMD section level which was suitable > > > > initially since hot plug granule is always one section(128M). However, > > > > commit ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") > > > > introduced a 2M(SUBSECTION_SIZE) hot plug granule, which disrupted the > > > > existing arm64 assumptions. > > > > > > > > Considering the vmemmap_free -> unmap_hotplug_pmd_range path, when > > > > pmd_sect() is true, the entire PMD section is cleared, even if there is > > > > other effective subsection. For example page_struct_map1 and > > > > page_strcut_map2 are part of a single PMD entry and they are hot-added > > > > sequentially. Then page_struct_map1 is removed, vmemmap_free() will clear > > > > the entire PMD entry freeing the struct page map for the whole section, > > > > even though page_struct_map2 is still active. Similar problem exists > > > > with linear mapping as well, for 16K base page(PMD size = 32M) or 64K > > > > base page(PMD = 512M), their block mappings exceed SUBSECTION_SIZE. > > > > Tearing down the entire PMD mapping too will leave other subsections > > > > unmapped in the linear mapping. > > > > > > > > To address the issue, we need to prevent PMD/PUD/CONT mappings for both > > > > linear and vmemmap for non-boot sections if corresponding size on the > > > > given base page exceeds SUBSECTION_SIZE(2MB now). > > > > > > > > Cc: # v5.4+ > > > > Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") > > > > Reviewed-by: Catalin Marinas > > > > Signed-off-by: Zhenhua Huang > > > > > > Just so I understand correctly: for ordinary memory-sections-size hotplug > > > (NVDIMM, virtio-mem), we still get a large mapping where possible? > > > > Up to 2MB blocks only since that's the SUBSECTION_SIZE value. The > > vmemmap mapping is also limited to PAGE_SIZE mappings (we could use > > contiguous mappings for vmemmap but it's not wired up; I don't think > > it's worth the hassle). > > But that's messed up, no? > > If someone hotplugs a memory section, they have to hotunplug a memory > section, not parts of it. > > That's why x86 does in vmemmap_populate(): > > if (end - start < PAGES_PER_SECTION * sizeof(struct page)) > err = vmemmap_populate_basepages(start, end, node, NULL); > else if (boot_cpu_has(X86_FEATURE_PSE)) > err = vmemmap_populate_hugepages(start, end, node, altmap); > ... > > Maybe I'm missing something. Most importantly, why the weird subsection > stuff is supposed to degrade ordinary hotplug of dimms/virtio-mem etc. I think that's based on the discussion for a previous version assuming that the hotplug/unplug sizes are not guaranteed to be symmetric: https://lore.kernel.org/lkml/a720aaa5-a75e-481e-b396-a5f2b50ed362@quicinc.com/ If that's not the case, we can indeed ignore the SUBSECTION_SIZE altogether and just rely on the start/end of the hotplugged region. -- Catalin