From nobody Fri Dec 19 18:43:04 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 82367327207 for ; Mon, 15 Dec 2025 21:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765833437; cv=none; b=qXJ5hSrCc7C77j3fL7NXAbUIwcPL7zVH5Veb6T8VtLP2XuVHUBLHmSJYKYmBmlGpSmf+JfKcRKMRb5Ri1CGd6I8XaDsUkTU+iC4nzDDGhL4RbD/9jj4Rfb0tKgKSOnSywvDWouFwEPmeehpc7lddfdRit152rSkexaefzIAqtU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765833437; c=relaxed/simple; bh=mSF5GN1PeKR2lOKcFVUUGaIx/a1Z6dQfJOALKio5rYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=flCqTTUEQafUJwcWyR7bYHJ72YMDhI66/+CixI3iRrdFpRFBiktQUIp63Ubt1xOL9d9pVLUaKK3j2qwP/osH33ydl8WyV2zbDWYTt3SpuJwfwPzHeTe/vSt5rvWg6UyKejSrbBoKfzqte//JI2ZEXEDnDA6c7kh/EFWzELTgou8= 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=fXREHl3G; arc=none smtp.client-ip=170.10.129.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="fXREHl3G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765833433; 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=uBWmZRlwxYLUkN3nMvZH7vuWHOobDOQMbI5q/HfKJHo=; b=fXREHl3GykYDZ1TEMapESDezg7fiPECAk/ye0lHJaUtLYlAtJuyXRUQthGdbW3AG9nyLjC 4asA7qINbwA5v1tX/xxkuelWcnyW1d8D2DzieY9dup6w80UyHDMqk1l5GIVt40IbyBYCHe k5mSczrmQVnvoU0tMn/ISjzKk54MhjQ= Received: from mx-prod-mc-03.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-407-KOGv_7rUOSSmqMJug95OxA-1; Mon, 15 Dec 2025 16:17:10 -0500 X-MC-Unique: KOGv_7rUOSSmqMJug95OxA-1 X-Mimecast-MFC-AGG-ID: KOGv_7rUOSSmqMJug95OxA_1765833429 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A19AD1956061; Mon, 15 Dec 2025 21:17:08 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.180]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 798AB1955F21; Mon, 15 Dec 2025 21:17:07 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org Cc: ryan.roberts@arm.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH 02/11] mm: introduce pgtable_has_pmd_leaves() Date: Mon, 15 Dec 2025 16:16:44 -0500 Message-ID: <49e5272a3fb756d1ffee0e4308bc9fa42fcdb81e.1765833318.git.luizcap@redhat.com> 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.0 on 10.30.177.17 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_hugepages(): the name suggests it checks if THP is enabled, but it actually checks if the CPU supports PMD-sized pages. It may perform a hardware check, so it can't be used in fast paths - 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_hugepages(). This way, this helper can be called from fast paths This commit introduces a new helper called pgtable_has_pmd_leaves() which is intended to replace both has_transparent_hugepages() and thp_disable_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 that needs to be performed very early during boot because there are pgtable_has_pmd_leaves() users that want to call it from __setup() handlers. This initialization is performed by init_arch_has_pmd_leaves(), called early from start_kernel(). The next commits will convert users of both has_transparent_hugepages() and thp_disabled_by_hw() to pgtable_has_pmd_leaves(). Signed-off-by: Luiz Capitulino --- include/linux/pgtable.h | 7 +++++++ init/main.c | 1 + mm/memory.c | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 652f287c1ef6..6733f90a1da4 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2017,6 +2017,13 @@ static inline const char *pgtable_level_to_str(enum = pgtable_level level) } } =20 +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); + #endif /* !__ASSEMBLY__ */ =20 #if !defined(MAX_POSSIBLE_PHYSMEM_BITS) && !defined(CONFIG_64BIT) diff --git a/init/main.c b/init/main.c index b84818ad9685..ad1209fffcde 100644 --- a/init/main.c +++ b/init/main.c @@ -1036,6 +1036,7 @@ void start_kernel(void) smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ early_numa_node_init(); boot_cpu_hotplug_init(); + init_arch_has_pmd_leaves(); =20 print_kernel_cmdline(saved_command_line); /* parameters may set static keys */ diff --git a/mm/memory.c b/mm/memory.c index 2a55edc48a65..79bd59d5243f 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.52.0