From mboxrd@z Thu Jan 1 00:00:00 1970 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 BA3453164D8 for ; Fri, 24 Jul 2026 01:35:01 +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=1784856903; cv=none; b=mqt64Nj2cuvcoQRuYVDNsgyhZrCgNuyOflUWQDMb6eFQvmlKOTRV4beJb+kJcUDKw55lT0t9YdTFwbgseOmtwbxBZy+FHw7y8phT9Ia0x8s4Lmkx7RiiyCJ8VcuQ6uYZIvsFA0LEiwzGdwK1WbsDKgsJLzF2tSRUwZ1y5CPj/ek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784856903; c=relaxed/simple; bh=R8sXGjwypx3n8ig4lTMv4hsid/2uhu29oFnt/e3e2eE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OHbDCJmL2aGjoNgMhoe7KeeVqVL6bK9ggemOib0zjqFkhK3+XRAVgFTNqfZegOaMbyVWTtRmmg3aQZ5zava4mb7a3L3RZX3achSptJ9ckKQI29DtrvO9RAIxSwbIkLGD0DhgBSVkiRjARm/wbTNxO5cJSEx2QD+aUZbSd9rWwkk= 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=BePF9rf+; 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="BePF9rf+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784856900; 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=N4WgUO5f7tfhU5uYl7yr/DaojI1yjAABTuJfiV9y+mA=; b=BePF9rf+Y7G6SeZ/AWO/6gxLbJ85jQTpvu7SEmturQAtTIDNvtO1ik+4p4SKSM2IbawG4R ClDNr79NS1EGULDIrOB0B6W3SVWzl7LmjjkLVoAfBNANxTv+LRnHq5h5Mkr4Efl9QonRS1 HgGU79YgWDqtC7q9DEkHs0BOa5Gp5qA= Received: from mx-prod-mc-05.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-269-fwi8CE4PNeKcdg1fTCl4BQ-1; Thu, 23 Jul 2026 21:34:55 -0400 X-MC-Unique: fwi8CE4PNeKcdg1fTCl4BQ-1 X-Mimecast-MFC-AGG-ID: fwi8CE4PNeKcdg1fTCl4BQ_1784856891 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5E60919775E4; Fri, 24 Jul 2026 01:34:50 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.238]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 193EC1800594; Fri, 24 Jul 2026 01:34:45 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org, baolin.wang@linux.alibaba.com, ziy@nvidia.com, lance.yang@linux.dev Cc: corbet@lwn.net, tsbogend@alpha.franken.de, maddy@linux.ibm.com, mpe@ellerman.id.au, agordeev@linux.ibm.com, gerald.schaefer@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, x86@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, ira.weiny@intel.com, hughd@google.com, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, yintirui@huawei.com, ljs@kernel.org, dev.jain@arm.com Subject: [PATCH v6 03/14] mm: introduce pgtable_has_pmd_leaves() Date: Thu, 23 Jul 2026 21:34:07 -0400 Message-ID: <382fb2620d699aed276c8e21e3f5925082c4b5dd.1784856856.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: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=y 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 pgtable_leaf_support_init(). We call pgtable_leaf_support_init() early during boot from mm_core_init(). 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 | 16 ++++++++++++++++ mm/memory.c | 9 +++++++++ mm/mm_init.c | 1 + 3 files changed, 26 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 8c093c119e5a..4c00cf53e183 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -2313,6 +2314,21 @@ static inline const char *pgtable_level_to_str(enum pgtable_level level) } } +#ifdef CONFIG_MMU +DECLARE_STATIC_KEY_TRUE(__arch_has_pmd_leaves_key); +static inline bool pgtable_has_pmd_leaves(void) +{ + return static_branch_likely(&__arch_has_pmd_leaves_key); +} +void __init pgtable_leaf_support_init(void); +#else +static inline bool pgtable_has_pmd_leaves(void) +{ + return false; +} +static inline void __init pgtable_leaf_support_init(void) { } +#endif + #endif /* !__ASSEMBLER__ */ #if !defined(MAX_POSSIBLE_PHYSMEM_BITS) && !defined(CONFIG_64BIT) diff --git a/mm/memory.c b/mm/memory.c index 56b244552f13..d6540d6d4ef9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -164,6 +164,15 @@ __setup("norandmaps", disable_randmaps); unsigned long highest_memmap_pfn __read_mostly; +DEFINE_STATIC_KEY_TRUE(__arch_has_pmd_leaves_key); +EXPORT_SYMBOL(__arch_has_pmd_leaves_key); + +void __init pgtable_leaf_support_init(void) +{ + if (!has_transparent_hugepage()) + static_branch_disable(&__arch_has_pmd_leaves_key); +} + void mm_trace_rss_stat(struct mm_struct *mm, int member) { trace_rss_stat(mm, member); diff --git a/mm/mm_init.c b/mm/mm_init.c index 711f821f7b3c..dcc072db4558 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2699,6 +2699,7 @@ void __init mm_core_init(void) { arch_mm_preinit(); init_zero_page_pfn(); + pgtable_leaf_support_init(); /* Initializations relying on SMP setup */ BUILD_BUG_ON(MAX_ZONELISTS > 2); -- 2.55.0