From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 8618B4DD6CA for ; Wed, 13 May 2026 13:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778678530; cv=none; b=jVfAJSrb/xl+VpR3kDkiawa6ycKZJ88aHI3veOV9N1a2vtZtyUrGg1zDAIx8IT5iiIMQBUta79wnUEhD7epS9eCzo0USqEWSwene3A1HLP3DrH8TeMuqzwaNhEOpvouJ6ZECwQkO1tpmeSc7QdiBqrOzXl/7y0+vnnFAu/qDiUc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778678530; c=relaxed/simple; bh=ooeAdDrUUbPDoT0juCZ6NI0skRGEPxGOwxDltBtVaNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M7LMajXoX9Yjv3Bu9SW9omORfp6YghSJa+68LFvGS3eAclU0HZQFheWw4b52SHVhZdiCLBj2XkhRUmrjXVvOcPn3ZeCtxDJIKd5P4GK2A7GC6nI+6elYQr3lG6GlUDxOwFaGWsTshgKw8KxIzpLG/DfvIXUf/j8e4B5wvh2PR9I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=APnOmVZ2; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="APnOmVZ2" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3667cf0136fso4956352a91.2 for ; Wed, 13 May 2026 06:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778678528; x=1779283328; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gyY9SCyAZIGNdueTrW/y87O7+cp/ViobtWpZedyU1UI=; b=APnOmVZ2sBc5t08F41vosYxWuG8qJtzA+JXfW3YYmgu7++exG+ToM0QGPj94pnblFr +MywVgapvOh7vdm3S40B4lQ471gxlEU5HZ/WltuK/Z1dEdrnACgvRRop+0egEnBKcspZ NUvzBZxflpnPHiSAsbr80PWky466cLoKQVPFQT3xr1/2412zVXcJBAIYteuDQl6/y4/V U9z+vO3+nYMm65PrbsBAsi+iW1Yc6wiJQUhssWnnN+pIfKJItNwqubBQxoHvdhRP+AOj +W6BLUaT9H+asiP7Oe2lbJLAm+Krqk44VSUSZ7jQogfuVLXJ8OqjWisOjzIVxcJ5luQz 8veg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778678528; x=1779283328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gyY9SCyAZIGNdueTrW/y87O7+cp/ViobtWpZedyU1UI=; b=ANMYSV29jj+HEnwoA6NHkweEk8F3lt5sh4Xu4JIRmMB+hefasLUtTbL4kexKqaR2hV 9Ty50gpK2gt4W8EM8+QmnjHyRfoPymfSSkVSF4RRWFFaTRg8oCPbCCbv4mE5WAx3H67+ vgPpICHAfKALkym4BbGdmAuBf1rw4WRBOOGAr5BBfrpETaJ+jbcH2Ypv1T3T4AQANmu2 yt/ke36cBNTwuKYhdiUX4UKdxxJtuqyyaQY203IfsQyauxS+eMTDfZJj6U2Qm8g9f0hb jYy0/S8/uCfP5vNluWd89fa+RFRB4GI+PaM0U1pDT8aXmL3hsJuNIeN3qn8qlI0JgPZN xYNg== X-Forwarded-Encrypted: i=1; AFNElJ8pgyOB23RX+dzwqb5AErtpY8W7VjSV1EMgkEKefqYGuzKIzJU7pWu/lWDirRsW4naD9leezpBGKXRwonk=@vger.kernel.org X-Gm-Message-State: AOJu0YzIFZKOtD1dCcV3EhGh49/9/1gBp02Y/rgo7haOIcPjfmoZwkG9 sTVA1CO3nk7RebBgp/8XF+tPkbZv+yJ7gOSmSRtH0Q9rXwUOvOYk4B9U7Mi5hdZt/B4= X-Gm-Gg: Acq92OFBrZ6jxUN7Pz6OWBH5yindcEUT0mLJLslcbGFcXHeNM0r/26gG88Gn1KTdjO8 i7dym7fLZi1CgysIktIbkx2RBdCSeworIRI6R82PmvHdw0L7eOa+YFbmegenRL1WbRLbNKNHwuN CDDYgfnVkB/tjZXP7u1NI3HYJcfkV2lFU/TIePzFfv4VK1nhgLYiTIg8r2sA/tlcwIqQxp+JWXq AN0a2HKRrT4qkyvnNqXXzlke1y3AZgP0Gu1ubT0UyulgMPRhMX4XIFbK58JeaSW8orrSp/PIlkG VGW3+w+KMKPuJ5Jd3Kd58m20asP30r/TcTm3fMtIFmspgwvnStKD6smMjjBDGYgMZpvtod5vGpN xRf3pYPeB7UUsJYh4zQ87bDBIGWlBWDgG67f4sWqoc7+3LuNRKxT17eALtZND/tS5JQekre2dHy EdxdCoqez7Y0nmkXdPLxrnYeLLkASiBarfr/KNMZRuLKD9t0hl+jc5DETktK2h X-Received: by 2002:a17:90b:3bce:b0:35e:3b08:8fc4 with SMTP id 98e67ed59e1d1-368f398c9d1mr3681030a91.5.1778678527413; Wed, 13 May 2026 06:22:07 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-368edf7cbc2sm3098406a91.14.2026.05.13.06.22.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:22:06 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , Ackerley Tng , Frank van der Linden , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 58/69] mm/hugetlb: Make HVO optimizable checks depend on generic logic Date: Wed, 13 May 2026 21:20:23 +0800 Message-ID: <20260513132044.41690-12-songmuchun@bytedance.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513132044.41690-1-songmuchun@bytedance.com> References: <20260513130542.35604-1-songmuchun@bytedance.com> <20260513132044.41690-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Make hugetlb_vmemmap_optimizable() reuse the generic order_vmemmap_optimizable() logic, and switch hugetlb boolean call sites to use the dedicated helper directly. This keeps HugeTLB-specific optimizable checks aligned with the generic vmemmap optimization rules and avoids open-coding the size-based test. Signed-off-by: Muchun Song --- include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 4 ++-- mm/hugetlb_vmemmap.h | 43 ++++++++++++++++++++--------------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 82dbb9ebead8..2383adb22ce1 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -778,7 +778,7 @@ static inline unsigned long huge_page_mask(struct hstate *h) return h->mask; } -static inline unsigned int huge_page_order(struct hstate *h) +static inline unsigned int huge_page_order(const struct hstate *h) { return h->order; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 54ef7d12c585..bd136fc6aec0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3351,7 +3351,7 @@ static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, &node_states[N_MEMORY], NULL); if (!folio && !list_empty(&folio_list) && - hugetlb_vmemmap_optimizable_size(h)) { + hugetlb_vmemmap_optimizable(h)) { prep_and_add_allocated_folios(h, &folio_list); INIT_LIST_HEAD(&folio_list); folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, @@ -3420,7 +3420,7 @@ static void __init hugetlb_pages_alloc_boot_node(unsigned long start, unsigned l for (i = 0; i < num; ++i) { struct folio *folio; - if (hugetlb_vmemmap_optimizable_size(h) && + if (hugetlb_vmemmap_optimizable(h) && (si_mem_available() == 0) && !list_empty(&folio_list)) { prep_and_add_allocated_folios(h, &folio_list); INIT_LIST_HEAD(&folio_list); diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index dfd48be6b231..1765f8274220 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -18,22 +18,6 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h, void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio); void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list); void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_page *m); - -static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h) -{ - return pages_per_huge_page(h) * sizeof(struct page); -} - -/* - * Return how many vmemmap size associated with a HugeTLB page that can be - * optimized and can be freed to the buddy allocator. - */ -static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h) -{ - int size = hugetlb_vmemmap_size(h) - OPTIMIZED_FOLIO_VMEMMAP_SIZE; - - return size > 0 ? size : 0; -} #else static inline int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio) { @@ -56,11 +40,6 @@ static inline void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list { } -static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h) -{ - return 0; -} - static inline void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_page *m) { } @@ -68,6 +47,26 @@ static inline void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_pag static inline bool hugetlb_vmemmap_optimizable(const struct hstate *h) { - return hugetlb_vmemmap_optimizable_size(h) != 0; + if (!IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP)) + return false; + + return order_vmemmap_optimizable(huge_page_order(h)); +} + +static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h) +{ + return pages_per_huge_page(h) * sizeof(struct page); +} + +/* + * Return the size of the vmemmap area associated with a HugeTLB page + * that can be optimized. + */ +static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h) +{ + if (!hugetlb_vmemmap_optimizable(h)) + return 0; + + return hugetlb_vmemmap_size(h) - OPTIMIZED_FOLIO_VMEMMAP_SIZE; } #endif /* _LINUX_HUGETLB_VMEMMAP_H */ -- 2.54.0