From nobody Thu Apr 9 10:36:10 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 543593914F0 for ; Wed, 8 Apr 2026 20:24:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775679888; cv=none; b=iBY49hoL4msnDW74M9ESQsVP5uRB9lCqTv1ewEzooJlY6MEFWkp+o9i6WVJeMaz/QssMq8TeGY00g5UNHRDbv9ih/yWps/6kVpOslyKBf5F0j924n2PtZ/97oo3/UJZh8p3tKchRpG8Tg2smZsRcRMdDQKXnkCFn9Iu/Y/qtMoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775679888; c=relaxed/simple; bh=WgkWPNzZ6WrMMJYY/tvvEUQikW+isoaT0eNS17u6Fvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HfLZJ86dneywBI71yS0JjiuZWZjmWgWNC2KNl5umYDuKjnFqOBz9zd5nlDTsrKj98SOmJwpGDS/4V4VR/s+tF8koU2BnbuOG+GsF3S/V3qnFpBmszNuis/V/2vXTidbTE7KX/ZKxjIYDwu1vAvpitrIeJQOaYHGPq7Xhz9CzTk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DMgs2VZK; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DMgs2VZK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775679886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JFnc/hoWnWNjlce2sdwxKTuBgL3PkWnTdvy+3P6vOl8=; b=DMgs2VZKv3vUGvwWF9Yo7p1mjgHmZ2ly7E7RcB2dUUMoF7lDZVboEhA32xapmYX6UoYj64 1Mdm/97YON2QOS9Zum0HgZ0vZEZNbFaXEqaFLRBQTtCusMn2AL+fCoxoFAxhtSKr7fhwAI 0VtQD1mtj0rjqEYBRQKlkMo+rWpbzqM= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-322-t3WLZ3LtOAihF6-7EypfWg-1; Wed, 08 Apr 2026 16:23:20 -0400 X-MC-Unique: t3WLZ3LtOAihF6-7EypfWg-1 X-Mimecast-MFC-AGG-ID: t3WLZ3LtOAihF6-7EypfWg_1775679799 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A1A681956060; Wed, 8 Apr 2026 20:23:18 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.88.140]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1A62D1800671; Wed, 8 Apr 2026 20:23:16 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org, baolin.wang@linux.alibaba.com Cc: ryan.roberts@arm.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v3 02/10] mm: introduce pgtable_has_pmd_leaves() Date: Wed, 8 Apr 2026 16:22:57 -0400 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Currently, we have two helpers that check for PMD-sized pages but have different names and slightly different semantics: - has_transparent_hugepage(): the name suggests it checks if THP is enabled, but when CONFIG_TRANSPARENT_HUGEPAGE=3Dy and the architecture implements this helper, it actually checks if the CPU supports PMD-sized pages - thp_disabled_by_hw(): the name suggests it checks if THP is disabled by the hardware, but it just returns a cached value acquired with has_transparent_hugepage(). This helper is used in fast paths This commit introduces a new helper called pgtable_has_pmd_leaves() which is intended to replace both has_transparent_hugepage() and thp_disabled_by_hw(). pgtable_has_pmd_leaves() has very clear semantics: it returns true if the CPU supports PMD-sized pages and false otherwise. It always returns a cached value, so it can be used in fast paths. The new helper requires an initialization step which is performed by init_arch_has_pmd_leaves(). We call init_arch_has_pmd_leaves() early during boot in start_kernel() right after parse_early_param() but before parse_args(). This allows early_param() handlers to change CPU flags if needed (eg. parse_memopt() in x86-32) while also allowing users to use the API from __setup() handlers. The next commits will convert users of both has_transparent_hugepage() and thp_disabled_by_hw() to pgtable_has_pmd_leaves(). Signed-off-by: Luiz Capitulino --- include/linux/pgtable.h | 15 +++++++++++++++ init/main.c | 1 + mm/memory.c | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index a50df42a893f..c4c5282f795c 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2192,6 +2192,21 @@ static inline const char *pgtable_level_to_str(enum = pgtable_level level) } } =20 +#ifdef CONFIG_MMU +extern bool __arch_has_pmd_leaves; +static inline bool pgtable_has_pmd_leaves(void) +{ + return __arch_has_pmd_leaves; +} +void __init init_arch_has_pmd_leaves(void); +#else +static inline bool pgtable_has_pmd_leaves(void) +{ + return false; +} +static inline void __init init_arch_has_pmd_leaves(void) { } +#endif + #endif /* !__ASSEMBLY__ */ =20 #if !defined(MAX_POSSIBLE_PHYSMEM_BITS) && !defined(CONFIG_64BIT) diff --git a/init/main.c b/init/main.c index 1cb395dd94e4..07f2ddbf9677 100644 --- a/init/main.c +++ b/init/main.c @@ -1044,6 +1044,7 @@ void start_kernel(void) print_kernel_cmdline(saved_command_line); /* parameters may set static keys */ parse_early_param(); + init_arch_has_pmd_leaves(); after_dashes =3D parse_args("Booting kernel", static_command_line, __start___param, __stop___param - __start___param, diff --git a/mm/memory.c b/mm/memory.c index c65e82c86fed..5ee312c30f2d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -177,6 +177,14 @@ static int __init init_zero_pfn(void) } early_initcall(init_zero_pfn); =20 +bool __arch_has_pmd_leaves __read_mostly; +EXPORT_SYMBOL(__arch_has_pmd_leaves); + +void __init init_arch_has_pmd_leaves(void) +{ + __arch_has_pmd_leaves =3D has_transparent_hugepage(); +} + void mm_trace_rss_stat(struct mm_struct *mm, int member) { trace_rss_stat(mm, member); --=20 2.53.0