From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796160415; b=JtMuju22ULJ/cef/5yPyyHRcneb46JP4S76EDWjKyYKV0V5T7tcmtx28MMkKK/DbLo/y OHxUZKUup29BnEoa6tJsN21dgadedt9EAmuj5KtLjdAKFsGA5WsoghRQV3GUhwdErsZSy UEZHM6CVUytrwr6u+4rFRvx4WkUNQ8UbzMvaKCwl2lJTdVmIRHFs3KMQcobVjwptAgHwQ Ehkh7PWXBUldn6CMqKrj8b1s8xHnliL6PVJHaGviJSMiG4xdTURvjfaW1b/6188LgdgFE hb4vdPrMJJWIveaoi9cMT64fUSZ5u8QW+33S5WLDntG+zneLOppTJuSUYtRrjrF6/XA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796160415; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=ucPQewLA2Go/QReA8K0Mxh4Babu7vXaYj0/dcMSR4jg=; b=Q2P7sAYlhXQnQSum333w+pwQOHRuBkf5QIA/6+pWFL1Hk3Y4xg49xNKibSuYk2eb4Hkv P5Zar3yT21jT6Bl9db0OBYXoWjztPTXFEh4UheL3EYq+3AFFHvu4Jc1+kO0Hudf8vzHoL cwGkeYHUcVNilwrfKm56vlAhPhPuosfl4UW3DPgrLhBw/4D2Iu4AnFaGtewLIU3/Ne8Re WwoVpDOLXmD5EcPJ4rsBISwYTonRvKvdYGn/tkyFuuKc+uYCaqSIm9tFi1KAwR62hcqpI H6KDQhhHTr/7mpleaqLHc+Hz8zxKoVeKaKg8E8+DdDcIbGxnRAfTChS/bs9lmG20glA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=y0+Xt7HY; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 090C5606A31A for ; Tue, 1 Dec 2026 21:26:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=y0+Xt7HY Received: by smtp.kernel.org (Postfix) with ESMTPSA id B97591F00893; Tue, 1 Dec 2026 21:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796160414; bh=ucPQewLA2Go/QReA8K0Mxh4Babu7vXaYj0/dcMSR4jg=; h=Date:To:From:In-Reply-To:References:Subject; b=y0+Xt7HY8Lv2xBBvBkyHwMDpgwnpkN9ycmOS4vAk1ibGrU64MEQaU2AuGXEbwTacY e725zypc66FtIyASc57XVfyHvQN7ecYIHenDxAQ5ozX0VNzEEdloEZgjPY2m/5B55Z WFW8sZarllVgbCe7Kuc12KLrX3/326+nUoQWRjpc= Date: Tue, 01 Dec 2026 13:26:54 -0800 To: mm-commits@vger.kernel.org,rppt@kernel.org,qi.zheng@linux.dev, osalvador@suse.de,nobody@kernel.org,lance.yang@linux.dev,david@kernel.org, songmuchun@bytedance.com,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261201095840.3034368-3-songmuchun@bytedance.com> References: <20261201095840.3034368-3-songmuchun@bytedance.com> Subject: + mm-hugetlb_vmemmap-fold-vmemmap_should_optimize-into-its-callers.patch added to mm-new branch Message-Id: <20261201212654.B97591F00893@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/hugetlb_vmemmap: fold vmemmap_should_optimize() into its callers has been added to the -mm mm-new branch. Its filename is mm-hugetlb_vmemmap-fold-vmemmap_should_optimize-into-its-callers.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb_vmemmap-fold-vmemmap_should_optimize-into-its-callers.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Muchun Song Subject: mm/hugetlb_vmemmap: fold vmemmap_should_optimize() into its callers Date: Tue, 01 Dec 2026 17:58:36 +0800 vmemmap_should_optimize_folio() combines the global HVO policy, per-hstate eligibility, and the already-optimized state. The latter two do not need to gate the normal flow: generic folio and section helpers check order eligibility, while optimization entry points only receive freshly initialized folios. Thus, only the global enable policy must be checked at every entry point. Fold the global enable check into each caller. Retain the per-hstate check in hugetlb_vmemmap_optimize_folios() only as an optimization, so an ineligible hstate is rejected before iterating the entire folio list. The batch path now reads the enable policy only once at entry instead of once per folio in both passes. Link: https://patch.msgid.link/20261201095840.3034368-3-songmuchun@bytedance.com Signed-off-by: Muchun Song Signed-off-by: Andrew Morton Reviewed-by: Lance Yang Cc: Oscar Salvador Cc: Mike Rapoport Cc: David Hildenbrand Cc: Qi Zheng Cc: nobody mm/hugetlb_vmemmap.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) --- a/mm/hugetlb_vmemmap.c~mm-hugetlb_vmemmap-fold-vmemmap_should_optimize-into-its-callers +++ a/mm/hugetlb_vmemmap.c @@ -488,21 +488,6 @@ long hugetlb_vmemmap_restore_folios(cons return ret; } -/* Return true iff a HugeTLB whose vmemmap should and can be optimized. */ -static bool vmemmap_should_optimize_folio(const struct hstate *h, struct folio *folio) -{ - if (folio_test_hugetlb_vmemmap_optimized(folio)) - return false; - - if (!READ_ONCE(vmemmap_optimize_enabled)) - return false; - - if (!hugetlb_vmemmap_optimizable(h)) - return false; - - return true; -} - static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio, struct list_head *vmemmap_pages, @@ -512,9 +497,6 @@ static int __hugetlb_vmemmap_optimize_fo VM_WARN_ON_ONCE_FOLIO(!folio_test_hugetlb(folio), folio); - if (!vmemmap_should_optimize_folio(h, folio)) - return 0; - /* * Very Subtle * If VMEMMAP_DEFER_TLB_FLUSH is set, TLB flushing is not performed @@ -548,32 +530,32 @@ void hugetlb_vmemmap_optimize_folio(cons { LIST_HEAD(vmemmap_pages); + if (!READ_ONCE(vmemmap_optimize_enabled)) + return; + guard(rwsem_read)(&vmemmap_remap_rwsem); __hugetlb_vmemmap_optimize_folio(h, folio, &vmemmap_pages, 0); free_vmemmap_page_list(&vmemmap_pages); } -static int hugetlb_vmemmap_pteify_folio(const struct hstate *h, struct folio *folio, - unsigned long flags) -{ - if (!vmemmap_should_optimize_folio(h, folio)) - return 0; - - return vmemmap_pteify_folio(folio, flags); -} - void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list) { struct folio *folio; LIST_HEAD(vmemmap_pages); unsigned long flags = VMEMMAP_DEFER_TLB_FLUSH; + if (!READ_ONCE(vmemmap_optimize_enabled)) + return; + + if (!hugetlb_vmemmap_optimizable(h)) + return; + if (list_empty(folio_list)) return; down_write(&vmemmap_remap_rwsem); list_for_each_entry(folio, folio_list, lru) { - int ret = hugetlb_vmemmap_pteify_folio(h, folio, flags); + int ret = vmemmap_pteify_folio(folio, flags); /* * Splitting the PMD requires allocating a page, thus let's fail _ Patches currently in -mm which might be from songmuchun@bytedance.com are powerpc-mm-make-vmemmap_populate_compound_pages-static.patch powerpc-mm-drop-powerpc-vmemmap_can_optimize.patch mm-sparse-vmemmap-drop-vmemmap_can_optimize.patch mm-sparse-vmemmap-drop-pgmap-from-vmemmap-population-apis.patch mm-hugetlb_vmemmap-fix-hwpoison-state-races-during-optimization.patch mm-hugetlb_vmemmap-fix-pmd-split-tlb-flush-race.patch mm-hugetlb_vmemmap-fix-deadlock-during-pmd-split.patch mm-list_lru-fix-potential-infinite-loop-on-xa-node-allocation-failure.patch mm-mm_init-verify-zones-for-template-initialized-pages.patch mm-mm_init-factor-out-common-struct-page-initialization.patch mm-mm_init-simplify-zone-device-page-initialization.patch mm-mm_init-factor-out-compound-page-initialization.patch mm-hugetlb-drop-boot-time-hvo-handling-for-gigantic-folios.patch mm-hugetlb-initialize-all-struct-pages-for-bootmem-hugepages.patch mm-hugetlb-use-common-compound-page-initialization-helper.patch mm-mm_init-make-__init_single_page-static.patch mm-cma-centralize-cma-pageblock-initialization.patch mm-cma-localize-init_cma_pageblock-to-cmac.patch mm-mm_init-move-pageblock-migratetype-init-to-memmap-helpers.patch kmsan-encapsulate-per-page-metadata-access.patch mm-page_ext-fix-client-data-alignment.patch mm-page_ext-always-use-vmalloc-for-section-page-extensions.patch mm-page_ext-use-common-allocation-and-initialization-entry-points.patch mm-page_ext-allocate-page-extensions-early-for-sparsemem.patch mm-page_ext-inline-unchecked-page-extension-lookup.patch kmsan-fix-metadata-loss-during-hugetlb-struct-page-reinitialization.patch mm-hugetlb_vmemmap-remove-the-vmemmap-savings-boot-message.patch mm-hugetlb_vmemmap-fold-vmemmap_should_optimize-into-its-callers.patch mm-hugetlb_vmemmap-drop-the-redundant-hstate-argument.patch mm-hugetlb_vmemmap-open-code-free_vmemmap_page.patch mm-hugetlb_vmemmap-drop-obsolete-restore-refcount-warning.patch mm-vmemmap-optimization-centralize-the-vmemmap-optimization-support-check.patch