From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97DA2606A325 for ; Tue, 1 Dec 2026 15:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=BG+AKrsZ; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=i9+sPGfW DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=NZirZQOliwfdI/VA4qoueHQKoRLI+p/Iu1qiZ1NHEX0=; b=BG+AKrsZKUOsS5U7MDgiZrue5n N78zlyHhCyzt9ETLNchA8e2it+wKlR7k2LHUsJuKnInW2sX1CaXFQi2GkQMcrUUeN2FJRXWVOkVrH KU55P+ylBnHy65YPte1wAvxno7IGZKVdz/JpJy/9HFIdS0vgn+mt+b3JVelO/J26/Smxeo3u25OVa AZCOhIH8EzkO0BSUVMF1BV/mvzRzKhVQAi/3iqz8gmDY5o5G9G+kPwaF3Wdw4oAvjQQc5CmPV6q8f 6A03mTSEUv5xiD9GcHdKbDveAfreN0Bhp4DZD265rqUJ+F3PVl+o+IR1rjL4BtBKs+7MytwJjzFsa tbmCCLSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPSs-00000008U8U-0IT8; Tue, 01 Dec 2026 15:08:18 +0000 Received: from mail-pj1-x1045.google.com ([2607:f8b0:4864:20::1045]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYPSp-00000008U3E-0Qu5 for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 15:08:16 +0000 Received: by mail-pj1-x1045.google.com with SMTP id 98e67ed59e1d1-3b42c3dba96so4448426a91.1 for ; Tue, 01 Dec 2026 07:08:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796137693; x=1796742493; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NZirZQOliwfdI/VA4qoueHQKoRLI+p/Iu1qiZ1NHEX0=; b=i9+sPGfW8LEO0j0BA7AMr4UMvHqz8aCs26s4i3zdWiOG9sX4BzS2esZ0y50CyBATar 45eiwI3LHhifZdbsmA9y6kyrryqQCdo4cP5nr2WMHfoZqNMeKzZky6mo3JUrlKt6Zd3n OhE0ke7KPsESgEoUx4zqwbCpMT3XSYGfaz3i6cyUE34YLa0qhi/Uq05BgmUnQ0H3svUc yRaNxgxoN23vBaDFnEckmgeBjjCmt7MkCGBpbf0awPiF0RomssHxXV+MSfBOoBIi/9uy xLnLmsWjKLB/dnEHQaRqQF1Tmtf4tMonObMSxcIb3AqlQ0F6kmNuXHg+t0JmxikvjLpG BWaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796137693; x=1796742493; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NZirZQOliwfdI/VA4qoueHQKoRLI+p/Iu1qiZ1NHEX0=; b=NcW0vZX9Qgk5zoXk/Zdff6Z9AxWACwbvRCl53jLWipwtKBTnQml3I8B/VEuF5YpsFA XWtDQpTH6EeH2Wot+UIfPtShE/0vTP/VuH7DXRzoY7VSTng7U13WRQpAZitdV8KO0wqY T7Q19mwMIiT/dWUo5fjefUL1yNhQ74fd2gCaL2IcmRmshh5hK/ulm9e9fUF0oGJEB3i1 9L1VbC2TfgPyXY2da+ueLXLwehXKoerotnUZeU/QeH9TD7Ch0icfCD1Fr/bGcthQ2aQ3 qZ4yQI3oBVv8LNCNWmppTVfVoI7Vm77bwRjC3CUKux/IqHGafe0bXKeu4K7Yu6voWqnj +8Ig== X-Forwarded-Encrypted: i=1; AL+hErFl8SHNZh8lFAqtYWiMeHFKHlDZ5lIcjoB8aLaEdzzpxsQiQutp2ycRfyzQAkMC0ukhce18HDfXmKpNgimfGKLB@lists.infradead.org X-Gm-Message-State: APuU4Z+9BPrVKODSKWuij8C+U0HgeEw3XLeMQdSCiDLD54xiWRFrxXAM 8nW0yzIyGUVizlLmV/4QJqfUHhJspzcPB0NieC/fT64IRWq5sq35oKhOQRz3QOPQjOda5k0HkN+ cy4jLPgkFyViJqhOWYcBh4Q== X-Received: from pjbmg4.prod.google.com ([2002:a17:90b:3704:b0:3b4:1351:6107]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3b52:b0:3b3:b9e4:e3f5 with SMTP id 98e67ed59e1d1-3b41c92a524mr36695543a91.30.1796137693033; Tue, 01 Dec 2026 07:08:13 -0800 (PST) Date: Tue, 1 Dec 2026 15:07:48 +0000 In-Reply-To: <20261201150801.2239894-1-jthoughton@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261201150801.2239894-1-jthoughton@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261201150801.2239894-7-jthoughton@google.com> Subject: [PATCH v4 06/18] hugetlb: Optimize bootmem folios that were not pre-HVOed From: James Houghton To: Will Deacon , Catalin Marinas , Muchun Song , Oscar Salvador , Andrew Morton Cc: Kefeng Wang , Nikos Nikoleris , Linu Cherian , Mark Rutland , David Hildenbrand , Ryan Roberts , Nanyong Sun , Yu Zhao , Frank van der Linden , David Rientjes , James Houghton , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_070815_190861_F575E396 X-CRM114-Status: GOOD ( 18.18 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Boot-time gigantic folios are expected to be pre-HVOed through the section-based vmemmap optimization, so the bulk optimization pass for bootmem folios was dropped. However, arch_supports_vmemmap_remap() may not yet return true when bootmem folios are allocated (e.g. on arm64, where support depends on a system-wide CPU capability), while it does return true by the time the bootmem folios are gathered. Such architectures disable the section-based vmemmap optimization in their vmemmap population path (see section_vmemmap_optimization_disable()), so the folios are not pre-HVOed and would never be optimized. Optimize such folios when gathering bootmem folios. Their tail struct pages have all been initialized by memmap_init_compound_page(), as they were not pre-HVOed. Pre-HVOed folios are skipped by vmemmap_should_optimize_folio(). Also restore the early return in hugetlb_vmemmap_optimize_folios() when no folio needs to be optimized, so that systems where all bootmem folios were optimized through the section-based optimization (or where HVO is disabled) do not take vmemmap_remap_rwsem for write and flush the TLB twice for nothing. Signed-off-by: James Houghton --- mm/hugetlb.c | 7 +++++++ mm/hugetlb_vmemmap.c | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6a4af46ddded..54c1dd955a29 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3364,6 +3364,13 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h, unsigned long flags; struct folio *folio, *tmp_f; + /* + * Some architectures do not support section-based vmemmap optimization, + * so their bootmem folios should be optimized here with folio-based + * optimization. + */ + hugetlb_vmemmap_optimize_folios(h, folio_list); + list_for_each_entry_safe(folio, tmp_f, folio_list, lru) { /* Subdivide locks to achieve better parallel performance */ spin_lock_irqsave(&hugetlb_lock, flags); diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 8ec80f450123..df145776aa6b 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -610,6 +610,7 @@ static int hugetlb_vmemmap_pteify_folio(const struct hstate *h, struct folio *fo void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list) { struct folio *folio; + unsigned long nr_to_optimize = 0; LIST_HEAD(vmemmap_pages); unsigned long flags = VMEMMAP_DEFER_TLB_FLUSH; @@ -618,7 +619,14 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l down_write(&vmemmap_remap_rwsem); list_for_each_entry(folio, folio_list, lru) { - int ret = hugetlb_vmemmap_pteify_folio(h, folio, flags); + int ret; + + if (!vmemmap_should_optimize_folio(h, folio)) + continue; + + nr_to_optimize++; + + ret = hugetlb_vmemmap_pteify_folio(h, folio, flags); /* * Splitting the PMD requires allocating a page, thus let's fail @@ -630,6 +638,11 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l break; } + if (!nr_to_optimize) { + up_write(&vmemmap_remap_rwsem); + return; + } + flush_tlb_all(); downgrade_write(&vmemmap_remap_rwsem); -- 2.56.1.839.g22a8290db9-goog