From nobody Sun Jun 14 07:34:35 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 CB87222F74A for ; Fri, 1 May 2026 19:20:05 +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=1777663207; cv=none; b=AWjF/Y41sA/vmL1Xpn5HxaEk/ikP6YV8AOsRlgrUgdo9HcD0ieW1A+xLtTVigPfkrnaRkjeTDHo2W4ngTkbGLoRaWdlxabNlPxtmQcqAUsXFfqb4GYbH8kfmfzi7gPqHbSkZ4rFb16OGt4ICm4T6dSTyQDZLbwIk97Qjg6qfk6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663207; c=relaxed/simple; bh=F+qRujSejiqXNRd8BAe6lUCM4/XjtLH/n4blKV7Suso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PBBGW8E/oexQcbjwRM5xMI1RBDDQgOMuAL/i9yTxUHjqrOmBbnJSc1W4EmrEMeIQcxGIyhIFEck6haJFuEhBQ7keOeQM4si20aXRQf2gaNixbls/a2dBxI+7qvxTIiM+PUEiZnq3CtHJBcN72r7vpZ05pHGp+8XhEN7vsuu6wCM= 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=bJRBbSdu; 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="bJRBbSdu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663204; 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=CaWIkKYdLR4Z1vH/dlH7TEwhtG6xeVazXkNWF/UUsyA=; b=bJRBbSduBa3TXqvcOP1TzeokyJ6i0QrdA2ErMf1gmBGCYuONDGCWW8Q+vY4BEtUkB2Tc5Q bjU+hbxDACwT5v02rdj9mP4v9PGZE7l5DGNT7MGJgodSu0wq+gQAvdMvzwnG60hhGZUVwu gzi5DrSEFe4u/6rpkGMwKdMjr813cT4= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-PR0FWLzPN6O1XuyJt8pdzQ-1; Fri, 01 May 2026 15:20:03 -0400 X-MC-Unique: PR0FWLzPN6O1XuyJt8pdzQ-1 X-Mimecast-MFC-AGG-ID: PR0FWLzPN6O1XuyJt8pdzQ_1777663201 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2983C1800473; Fri, 1 May 2026 19:20:00 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4E9771800345; Fri, 1 May 2026 19:19:56 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 1/9] docs: tmpfs: remove implementation detail reference Date: Fri, 1 May 2026 15:18:43 -0400 Message-ID: <041c4d9a9d57a9acba90324819bce6fc804b87a7.1777663129.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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The tmpfs.rst doc references the has_transparent_hugepage() helper, which is an implementation detail in the kernel and not relevant for users wishing to properly configure THP support for tmpfs. Remove it. Acked-by: David Hildenbrand (Red Hat) Reviewed-by: Baolin Wang Reviewed-by: Lance Yang Reviewed-by: Zi Yan Signed-off-by: Luiz Capitulino --- Documentation/filesystems/tmpfs.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystem= s/tmpfs.rst index d677e0428c3f..46fc986c3388 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -109,9 +109,8 @@ noswap Disables swap. Remounts must respect the origin= al settings. =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 tmpfs also supports Transparent Huge Pages which requires a kernel -configured with CONFIG_TRANSPARENT_HUGEPAGE and with huge supported for -your system (has_transparent_hugepage(), which is architecture specific). -The mount options for this are: +configured with CONFIG_TRANSPARENT_HUGEPAGE and with huge pages +supported for your system. The mount options for this are: =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D huge=3Dnever Do not allocate huge pages. This is the default. --=20 2.53.0 From nobody Sun Jun 14 07:34:35 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 7C6D022F74A for ; Fri, 1 May 2026 19:20:12 +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=1777663213; cv=none; b=DAFwFocd07p6fPvoz5JDllspw5xjEVUU0IpgSY7Kgb4dZa5BKJmOt65IYrX4MXbPVf5y6iDuLbcjdasybJpysAEFcyy0FGdOq2Mi5F7ocE0hKqtWqVttm8dQX7jzgHi5hkKFI1aSH7nW/H8DSWm7pygDWGjNXUz2nbJ2Cks2+Lw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663213; c=relaxed/simple; bh=kNi+A3EXVIa4kqYnoxI9MSr7lrqwHIEixTG8lQVV5r8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fswdNHE3iDAOScKlNZRu5S7+EHwrvBnq0wsupbrjE3B7gO/neG3TAGvmbfM33X0yG2yET7PVVTtK0jnon7/HEupQyREnf7rM569KzHHD20rA4T11Lxm9QprH7ByHcpqUGOBIxMMIFD04GiRk73uYHvM1xnNjKlNLAjlL3jpezwU= 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=GHgqArs1; 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="GHgqArs1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663211; 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=wm/3tKpS1+bbbkiWPW54qthE5IZvUCs3az7WMfHFyEE=; b=GHgqArs1zKPccLUSMs7rmLUTeWqTshQ7wIceRuwvY8moNWA3rGLv0nWnp90uZQk4fa6bJD l+dt/hUm87I9Ojcd8+ENE6L84qMzZlI08IVCrtu37vU0qged8uXruqcDvldJohPvDiZW8F vZes7hGVkFA3gu8HTGmWcYFaiWyUhk8= 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-558-EPxmSzN4OfyvKHGpT8koQQ-1; Fri, 01 May 2026 15:20:06 -0400 X-MC-Unique: EPxmSzN4OfyvKHGpT8koQQ-1 X-Mimecast-MFC-AGG-ID: EPxmSzN4OfyvKHGpT8koQQ_1777663204 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B63AD19560B5; Fri, 1 May 2026 19:20:03 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4CD791800577; Fri, 1 May 2026 19:20:00 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 2/9] mm: introduce pgtable_has_pmd_leaves() Date: Fri, 1 May 2026 15:18:44 -0400 Message-ID: <2a0bae00cdd2b6ef6b962610b523ebfc97806ba7.1777663129.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.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 | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index cdd68ed3ae1a..b365be3516bf 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2243,6 +2243,21 @@ static inline const char *pgtable_level_to_str(enum = pgtable_level level) } } =20 +#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 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 96f93bb06c49..eea7c5bdddf7 100644 --- a/init/main.c +++ b/init/main.c @@ -1053,6 +1053,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 ea6568571131..90b2d9e84320 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -164,6 +164,15 @@ __setup("norandmaps", disable_randmaps); =20 unsigned long highest_memmap_pfn __read_mostly; =20 +DEFINE_STATIC_KEY_TRUE(__arch_has_pmd_leaves_key); +EXPORT_SYMBOL(__arch_has_pmd_leaves_key); + +void __init init_arch_has_pmd_leaves(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); --=20 2.53.0 From nobody Sun Jun 14 07:34:35 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 6428C3F6610 for ; Fri, 1 May 2026 19:20:14 +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=1777663215; cv=none; b=FnhYGiTCFSZwGjwVHQKCG2V/iT2BxSQ20gMj0pRBH0iGFkgulVS51+aKatGEbt9Rjt7ZrqRYeDZnd0mQxCwqw0gaNnf2E+ccH9B+6KQ/coJgA6Cezex+lYOWSJKvaPgOf5H+bwse26uKdrN+67GZqbEBDyzTTLwH9faZq5JR5kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663215; c=relaxed/simple; bh=GVCtff24R79vIj5+UwhohiTKndjKqE5LXcIcZxVaZBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KpcBMyhZoa9Q9TuRF3nPiwmI66HcWc+Q8p3xzBV/XPXhBWV5erxhA5pNscrDn9+iZlLtolQrJfentRL8OvMQeWlE1K/0NK3UhjB/u4cloS8hWwNwig3wR9k5D+VBnSeDEGUIpy6YY1fqaFZoDmGQhkWma4g/UoXLja8U7QBU3Ko= 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=LXEOP2cb; 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="LXEOP2cb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663213; 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=EauujQ6AF4QZsCC6h7PNtICr/KSSJa0IrR5B8rHLzgA=; b=LXEOP2cbfjGzbo7ojaUGCd8TwiUzHqpZWmYXu6QuzHID5reNnuv+FIbl+JdESOLUScQvi5 qrqRtcJtHMj9InfDPg0xo49FnI/nXAM5ZFrqpm5TMWJYEacuH0+c/oKf9LIU8ymHiAeX+z usp+WLCR0mnxec2lB7sIKZiwtVT2kG4= 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-244-ww1WItWvPve97Gvphk8GoA-1; Fri, 01 May 2026 15:20:09 -0400 X-MC-Unique: ww1WItWvPve97Gvphk8GoA-1 X-Mimecast-MFC-AGG-ID: ww1WItWvPve97Gvphk8GoA_1777663207 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 2E2651956089; Fri, 1 May 2026 19:20:07 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC7D41800480; Fri, 1 May 2026 19:20:03 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 3/9] drivers: dax: use pgtable_has_pmd_leaves() Date: Fri, 1 May 2026 15:18:45 -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" dax_align_valid() uses has_transparent_hugepage() to check if PMD-sized pages are supported, use pgtable_has_pmd_leaves() instead. Acked-by: David Hildenbrand (Red Hat) Signed-off-by: Luiz Capitulino --- drivers/dax/dax-private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index 81e4af49e39c..35744ff6592a 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -123,7 +123,7 @@ static inline bool dax_align_valid(unsigned long align) { if (align =3D=3D PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGE= PAGE_PUD)) return true; - if (align =3D=3D PMD_SIZE && has_transparent_hugepage()) + if (align =3D=3D PMD_SIZE && pgtable_has_pmd_leaves()) return true; if (align =3D=3D PAGE_SIZE) return true; --=20 2.53.0 From nobody Sun Jun 14 07:34:35 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 0854641C2F5 for ; Fri, 1 May 2026 19:20:15 +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=1777663217; cv=none; b=P/nCfhpXQgeatpU5nP5Yf93BkBsxddZEmR0gZmhUw/FWPyAsYfChHHegUC8vRzPGZayJgmeIYRS2CD9Qn1VrKkZcYZXB0DYPkIoZAnof1xQZRzVnR0Y4VUAX/7dPXIZT0fUlyBDAeIj2Bt3Mm7pVNbduSv4lBgkkZKnqALjhQjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663217; c=relaxed/simple; bh=KYB1CkATONosFNu/v3QggaJNeeQvJP2JZFt/BzPYkvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=niL7l4XKh7SZgHyw9s9CKnzexVWDE0ThKu/hyiDYk1pROtI/+jWCdRrstFkvyEy3thijYuUsv+9hSL5BZ14rm4XjnWgSriKuXal3mGil24tDYBwgSWDMEzmWOQZGtiFdkqC6M3FehIpf5R9dvjI3FYi5dndMA/ShRihGkv8WYSE= 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=gc+dsnXO; 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="gc+dsnXO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663215; 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=Xb2/giZWWd2hyINscaxoEoYNnNswP7F4+7wCydf367o=; b=gc+dsnXOopbxuVGJcXxYsNe/mi4/wxqApPV5qO+JHBtmfT0qW6r+4mfSbaa0qZFhAvQE8p bnyH9UcmTez7nb4OeewWC7g/3BvuDojK+bBvVZ/0R97vaKlRmIPHd90Ti9kBAOYO8NUzJp ClczpSNagY6S3qTX9MzxQprgmCRwa9I= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-7RBVcRMkMaiUK3kM9GQc1Q-1; Fri, 01 May 2026 15:20:13 -0400 X-MC-Unique: 7RBVcRMkMaiUK3kM9GQc1Q-1 X-Mimecast-MFC-AGG-ID: 7RBVcRMkMaiUK3kM9GQc1Q_1777663211 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F222E1800473; Fri, 1 May 2026 19:20:10 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7971D1800345; Fri, 1 May 2026 19:20:07 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 4/9] drivers: nvdimm: use pgtable_has_pmd_leaves() Date: Fri, 1 May 2026 15:18:46 -0400 Message-ID: <080c40bdcb145bc9162503a3e09144d444991770.1777663129.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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" nd_pfn_supported_alignments() and nd_pfn_default_alignment() use has_transparent_hugepage() to check if THP is supported with PMD-sized pages. Use pgtable_has_pmd_leaves() instead. Also, check for IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) to preserve the current implementation semantics. Acked-by: Zi Yan Signed-off-by: Luiz Capitulino --- drivers/nvdimm/pfn_devs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 8fa9c16aba7e..457eb54e7ab6 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -94,7 +94,8 @@ static unsigned long *nd_pfn_supported_alignments(unsigne= d long *alignments) =20 alignments[0] =3D PAGE_SIZE; =20 - if (has_transparent_hugepage()) { + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && + pgtable_has_pmd_leaves()) { alignments[1] =3D HPAGE_PMD_SIZE; if (has_transparent_pud_hugepage()) alignments[2] =3D HPAGE_PUD_SIZE; @@ -109,7 +110,8 @@ static unsigned long *nd_pfn_supported_alignments(unsig= ned long *alignments) static unsigned long nd_pfn_default_alignment(void) { =20 - if (has_transparent_hugepage()) + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && + pgtable_has_pmd_leaves()) return HPAGE_PMD_SIZE; return PAGE_SIZE; } --=20 2.53.0 From nobody Sun Jun 14 07:34:35 2026 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 5CAAA41B366 for ; Fri, 1 May 2026 19:20:21 +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=1777663222; cv=none; b=pWfe4+hXAubhUNlpaIKAbU1LQoPEEAjsIoFKkE0KdbbyEaA5SbWk7gK5DXGALl+1MKkz0p5/aU68uOcY7irxd2139mfld1qWJuItOJwn46+vfRW4Ya0gyvyYwbyezEIazj+ZMImILGEKZh8pdWK00tKv2Gdzu+lL7LxE1guRQsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663222; c=relaxed/simple; bh=yAT778lmh8iZSJhSLsPru2trsirA+GIFmR/Ncq8RM3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BPAbkgHVm9RYFEl0FnKunz78CsZxY4VIqWiJhSk90TELeZy+NW7aqkZEfQscTpGNKyFlieTjbEQI/58MsbExfXHqTSsjF3oWWUTC2qUzuNOd5szsMgxjlJj7fHbLNY9BUbZga/xxxLhse27hOPzqOZcp/Uhg9vqKpjP2l3HuVy8= 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=jLvyRxpk; 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="jLvyRxpk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663220; 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=UwTXplBP3/R1ua0FWXZ96Qds9nsahLlEWeI0/s59WsU=; b=jLvyRxpkOq0O1sWNFp6UVKVa0K9zKM+/ue1hM2+loxhcrzP3j7hPJhViegmn7GdpltXZiT bUAwAAYIQ5UgnF4D9f7j5BYTN3nglmvC1dHjwMMAwBq4Y5Ijer+GMZrKH2O2WPPeenoDPR 5uSeCJll29c7hCmYOkC5rukbtGQt4TM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-o-fzyAVKPtCX2m1Qjn9WWA-1; Fri, 01 May 2026 15:20:17 -0400 X-MC-Unique: o-fzyAVKPtCX2m1Qjn9WWA-1 X-Mimecast-MFC-AGG-ID: o-fzyAVKPtCX2m1Qjn9WWA_1777663214 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 17E731800352; Fri, 1 May 2026 19:20:14 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D69F1800906; Fri, 1 May 2026 19:20:11 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 5/9] mm: debug_vm_pgtable: use pgtable_has_pmd_leaves() Date: Fri, 1 May 2026 15:18:47 -0400 Message-ID: <3a360247fc636869c3f511cda52f3c4522418c06.1777663129.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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" debug_vm_pgtable calls has_transparent_hugepage() in multiple places to check if PMD-sized pages are supported, use pgtable_has_pmd_leaves() instead. Reviewed-by: Lance Yang Reviewed-by: Zi Yan Signed-off-by: Luiz Capitulino --- mm/debug_vm_pgtable.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 23dc3ee09561..bd53417dde2f 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -177,7 +177,7 @@ static void __init pmd_basic_tests(struct pgtable_debug= _args *args, int idx) unsigned long val =3D idx, *ptr =3D &val; pmd_t pmd; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 pr_debug("Validating PMD basic (%pGv)\n", ptr); @@ -222,7 +222,7 @@ static void __init pmd_advanced_tests(struct pgtable_de= bug_args *args) pmd_t pmd; unsigned long vaddr =3D args->vaddr; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 page =3D (args->pmd_pfn !=3D ULONG_MAX) ? pfn_to_page(args->pmd_pfn) : NU= LL; @@ -283,7 +283,7 @@ static void __init pmd_leaf_tests(struct pgtable_debug_= args *args) { pmd_t pmd; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 pr_debug("Validating PMD leaf\n"); @@ -688,7 +688,7 @@ static void __init pmd_protnone_tests(struct pgtable_de= bug_args *args) if (!IS_ENABLED(CONFIG_NUMA_BALANCING)) return; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 pr_debug("Validating PMD protnone\n"); @@ -737,7 +737,7 @@ static void __init pmd_soft_dirty_tests(struct pgtable_= debug_args *args) if (!pgtable_supports_soft_dirty()) return; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 pr_debug("Validating PMD soft dirty\n"); @@ -754,7 +754,7 @@ static void __init pmd_leaf_soft_dirty_tests(struct pgt= able_debug_args *args) !IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION)) return; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 pr_debug("Validating PMD swap soft dirty\n"); @@ -825,7 +825,7 @@ static void __init pmd_softleaf_tests(struct pgtable_de= bug_args *args) swp_entry_t arch_entry; pmd_t pmd1, pmd2; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 pr_debug("Validating PMD swap\n"); @@ -906,7 +906,7 @@ static void __init pmd_thp_tests(struct pgtable_debug_a= rgs *args) { pmd_t pmd; =20 - if (!has_transparent_hugepage()) + if (!pgtable_has_pmd_leaves()) return; =20 pr_debug("Validating PMD based THP\n"); @@ -997,7 +997,7 @@ static void __init destroy_args(struct pgtable_debug_ar= gs *args) } =20 if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - has_transparent_hugepage() && + pgtable_has_pmd_leaves() && args->pmd_pfn !=3D ULONG_MAX) { debug_vm_pgtable_free_huge_page(args, args->pmd_pfn, HPAGE_PMD_ORDER); args->pmd_pfn =3D ULONG_MAX; @@ -1249,7 +1249,7 @@ static int __init init_args(struct pgtable_debug_args= *args) } =20 if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - has_transparent_hugepage()) { + pgtable_has_pmd_leaves()) { page =3D debug_vm_pgtable_alloc_huge_page(args, HPAGE_PMD_ORDER); if (page) { args->pmd_pfn =3D page_to_pfn(page); --=20 2.53.0 From nobody Sun Jun 14 07:34:35 2026 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 851EA3CF032 for ; Fri, 1 May 2026 19:20:28 +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=1777663229; cv=none; b=Zgs9bq/Wg19bFMgQTWR2wfhe/tpBIhjJOlt5KCE6/MAgix90Ep22U45xy0lZFHysQ1UiuCjDoUlIKLWfCIdHLRarZmpMYNPyF/+PvM6Ew9NHqsAOBlNXBvNWm0oYv3YV9XCNWuw1wICb2lWJIN5RO/ixWvHFCgzn36Nr9YFrkGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663229; c=relaxed/simple; bh=JL3XVGWN3SNclgW26Ckbdugy0544v1euV+7B0qSNnJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jPmu2soYPQ8uUcNUyHbym/FoY8j/svotSmzDXChBUgtGEcQV62SuuuRXKaqHpbqx9CwJKGtPnxn6gYkRecbWP0uuPNRXLLh5tzcW3pFTndWVOvcKZO7pFDHzOf/AKJUrbLrUht/lMpK5BR2FCTiuSMaFLvErk7JHzVqnD6QtegY= 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=B1IIj+ZH; 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="B1IIj+ZH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663227; 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=vI1pVR9OhMfQO7McpLsXLDDOj63yJGYULZKGOcQ3TPw=; b=B1IIj+ZH7PFt0DZOGnHPnVVu0wBMjV9gKG4uWf00H+nPJt5vfkBMR1IqcuTgEOUd0u+n6J jKUUm/0T6PkU2XnlFUz9SG2vhU1kBFWPRZHHzni1YAbyGS1E46MrbjNyvvDrNKomSujRH1 ZQUDrMWQT4osm11z7gIegHetqW+tTF8= 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-125-DcaIPPpjM6eZpCNc6flWOw-1; Fri, 01 May 2026 15:20:20 -0400 X-MC-Unique: DcaIPPpjM6eZpCNc6flWOw-1 X-Mimecast-MFC-AGG-ID: DcaIPPpjM6eZpCNc6flWOw_1777663217 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 6B33C195608E; Fri, 1 May 2026 19:20:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5096F1800345; Fri, 1 May 2026 19:20:14 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 6/9] mm: shmem: drop has_transparent_hugepage() usage Date: Fri, 1 May 2026 15:18:48 -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" Shmem uses has_transparent_hugepage() in the following ways: - shmem_parse_one() and shmem_parse_huge(): Check if THP is built-in and if the CPU supports PMD-sized pages - shmem_init(): Since the CONFIG_TRANSPARENT_HUGEPAGE guard is outside the code block calling has_transparent_hugepage(), the has_transparent_hugepage() call is exclusively checking if the CPU supports PMD-sized pages While it's necessary to check if CONFIG_TRANSPARENT_HUGEPAGE is enabled in all cases, shmem can determine mTHP size support at folio allocation time. Therefore, drop has_transparent_hugepage() usage while keeping the CONFIG_TRANSPARENT_HUGEPAGE checks. Reviewed-by: Baolin Wang Reviewed-by: Lance Yang Acked-by: Zi Yan Signed-off-by: Luiz Capitulino --- mm/shmem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 3b5dc21b323c..1948d73fb1e3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -689,7 +689,7 @@ static int shmem_parse_huge(const char *str) else return -EINVAL; =20 - if (!has_transparent_hugepage() && + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && huge !=3D SHMEM_HUGE_NEVER && huge !=3D SHMEM_HUGE_DENY) return -EINVAL; =20 @@ -4656,8 +4656,7 @@ static int shmem_parse_one(struct fs_context *fc, str= uct fs_parameter *param) case Opt_huge: ctx->huge =3D result.uint_32; if (ctx->huge !=3D SHMEM_HUGE_NEVER && - !(IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - has_transparent_hugepage())) + !IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) goto unsupported_parameter; ctx->seen |=3D SHMEM_SEEN_HUGE; break; @@ -5449,7 +5448,7 @@ void __init shmem_init(void) #endif =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (has_transparent_hugepage() && shmem_huge > SHMEM_HUGE_DENY) + if (shmem_huge > SHMEM_HUGE_DENY) SHMEM_SB(shm_mnt->mnt_sb)->huge =3D shmem_huge; else shmem_huge =3D SHMEM_HUGE_NEVER; /* just in case it was patched */ --=20 2.53.0 From nobody Sun Jun 14 07:34:35 2026 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 395DB41B365 for ; Fri, 1 May 2026 19:20:26 +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=1777663227; cv=none; b=WCMFh1EMbMyV4MAcb71TWdJHr/rL+GwrCUPcuKX+K8dk/eDT+MchnsecME04Yjg6701iFkSBUOjgR/qVc7pXY59CBEWXO8YNrKNlwGj5f2S/hC1vknpo9g3WW9UG3WxGfoUi4pfZbdnbov89QhxPQ9SS/Ww8EDyTBd9qachf14A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663227; c=relaxed/simple; bh=iOoYgD/2B06sd9gBCGQxzv6YCacw1MFwfxNoJ+7Nipc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rZgpR4PD5QQgl3dsx/xNEakeFde1s0Mio/4iV1kL3YGHT9qgx6HpUxg6aC2WBbixIkWJztyi9Oinn66luc4xbQC122U1lRg56OmTCOIzOGZ1jO0K40F5d7bRexG/yGWijSBaP57aYK8AO92bUaXa0zu7+pxlXc9CxAyeTa20LzA= 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=FjPTDex/; 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="FjPTDex/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663225; 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=qNavbFWlO0DIPnynD7O4aaFA2GWbjCiwD9QcVuw7hgQ=; b=FjPTDex/wLP/cKaxhJ57ETz7Pxaf1RSSNf/gt4oXy/X9X/3SqkpcGL3qaYx152TkVGvQNT i779Fy39WgUkn4x9KW7jBoZORw1ZgqCQHvZw/9Rwo4IYfANIU0PG1Vp46Gqle5GOPs+XQu xRWUsd6vqL1XPbr7CsjQDSHOKY84iL4= 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-411-sBIt2aBvMIyjX3xsRgeTCw-1; Fri, 01 May 2026 15:20:23 -0400 X-MC-Unique: sBIt2aBvMIyjX3xsRgeTCw-1 X-Mimecast-MFC-AGG-ID: sBIt2aBvMIyjX3xsRgeTCw_1777663221 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ADDE71956053; Fri, 1 May 2026 19:20:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A31AF1800480; Fri, 1 May 2026 19:20:17 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 7/9] treewide: introduce arch_has_pmd_leaves() Date: Fri, 1 May 2026 15:18:49 -0400 Message-ID: <85674af7934cd363ceadd1d4f2b784d833a183cc.1777663129.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.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Now that all the has_transparent_hugepage() callers have been converted to pgtable_has_pmd_leaves(), this commit does two things: 1. Rename has_transparent_hugepage() arch implementations to arch_has_pmd_leaves(), since that's what the helper checks for 2. Introduce the default implementation of arch_has_pmd_leaves() as IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE). This means that if the arch doesn't implement arch_has_pmd_leaves() we default to checking CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE as a way to determine if PMD-sized pages are supported Note that arch_has_pmd_leaves() is supposed to be called only by init_arch_has_pmd_leaves(). The remaining exception is hugepage_init() which will be converted in a future commit. Signed-off-by: Luiz Capitulino --- arch/mips/include/asm/pgtable.h | 4 ++-- arch/mips/mm/tlb-r4k.c | 4 ++-- arch/powerpc/include/asm/book3s/64/hash-4k.h | 2 +- arch/powerpc/include/asm/book3s/64/hash-64k.h | 2 +- arch/powerpc/include/asm/book3s/64/pgtable.h | 10 +++++----- arch/powerpc/include/asm/book3s/64/radix.h | 2 +- arch/powerpc/mm/book3s64/hash_pgtable.c | 4 ++-- arch/s390/include/asm/pgtable.h | 4 ++-- arch/x86/include/asm/pgtable.h | 4 ++-- include/linux/pgtable.h | 4 ++-- mm/huge_memory.c | 2 +- mm/memory.c | 2 +- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtabl= e.h index fa7b935f947c..a97b788315e2 100644 --- a/arch/mips/include/asm/pgtable.h +++ b/arch/mips/include/asm/pgtable.h @@ -615,8 +615,8 @@ unsigned long io_remap_pfn_range_pfn(unsigned long pfn,= unsigned long size); /* We don't have hardware dirty/accessed bits, generic_pmdp_establish is f= ine.*/ #define pmdp_establish generic_pmdp_establish =20 -#define has_transparent_hugepage has_transparent_hugepage -extern int has_transparent_hugepage(void); +#define arch_has_pmd_leaves arch_has_pmd_leaves +extern int arch_has_pmd_leaves(void); =20 static inline int pmd_trans_huge(pmd_t pmd) { diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c index 24fe85fa169d..c423b5784337 100644 --- a/arch/mips/mm/tlb-r4k.c +++ b/arch/mips/mm/tlb-r4k.c @@ -434,7 +434,7 @@ void add_wired_entry(unsigned long entrylo0, unsigned l= ong entrylo1, =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE =20 -int has_transparent_hugepage(void) +int arch_has_pmd_leaves(void) { static unsigned int mask =3D -1; =20 @@ -450,7 +450,7 @@ int has_transparent_hugepage(void) } return mask =3D=3D PM_HUGE_MASK; } -EXPORT_SYMBOL(has_transparent_hugepage); +EXPORT_SYMBOL(arch_has_pmd_leaves); =20 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 diff --git a/arch/powerpc/include/asm/book3s/64/hash-4k.h b/arch/powerpc/in= clude/asm/book3s/64/hash-4k.h index 8e5bd9902bed..6744c2287199 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-4k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-4k.h @@ -165,7 +165,7 @@ extern void hash__pgtable_trans_huge_deposit(struct mm_= struct *mm, pmd_t *pmdp, extern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, p= md_t *pmdp); extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp); -extern int hash__has_transparent_hugepage(void); +extern int hash__arch_has_pmd_leaves(void); #endif =20 #endif /* !__ASSEMBLER__ */ diff --git a/arch/powerpc/include/asm/book3s/64/hash-64k.h b/arch/powerpc/i= nclude/asm/book3s/64/hash-64k.h index 7deb3a66890b..9392aba5e5dc 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-64k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-64k.h @@ -278,7 +278,7 @@ extern void hash__pgtable_trans_huge_deposit(struct mm_= struct *mm, pmd_t *pmdp, extern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, p= md_t *pmdp); extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp); -extern int hash__has_transparent_hugepage(void); +extern int hash__arch_has_pmd_leaves(void); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 #endif /* __ASSEMBLER__ */ diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/asm/book3s/64/pgtable.h index e67e64ac6e8c..b6629c041e75 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -1121,14 +1121,14 @@ static inline void update_mmu_cache_pud(struct vm_a= rea_struct *vma, { } =20 -extern int hash__has_transparent_hugepage(void); -static inline int has_transparent_hugepage(void) +extern int hash__arch_has_pmd_leaves(void); +static inline int arch_has_pmd_leaves(void) { if (radix_enabled()) - return radix__has_transparent_hugepage(); - return hash__has_transparent_hugepage(); + return radix__arch_has_pmd_leaves(); + return hash__arch_has_pmd_leaves(); } -#define has_transparent_hugepage has_transparent_hugepage +#define arch_has_pmd_leaves arch_has_pmd_leaves =20 static inline int has_transparent_pud_hugepage(void) { diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/incl= ude/asm/book3s/64/radix.h index da954e779744..c884a119cbd9 100644 --- a/arch/powerpc/include/asm/book3s/64/radix.h +++ b/arch/powerpc/include/asm/book3s/64/radix.h @@ -298,7 +298,7 @@ extern pmd_t radix__pmdp_huge_get_and_clear(struct mm_s= truct *mm, pud_t radix__pudp_huge_get_and_clear(struct mm_struct *mm, unsigned long addr, pud_t *pudp); =20 -static inline int radix__has_transparent_hugepage(void) +static inline int radix__arch_has_pmd_leaves(void) { /* For radix 2M at PMD level means thp */ if (mmu_psize_defs[MMU_PAGE_2M].shift =3D=3D PMD_SHIFT) diff --git a/arch/powerpc/mm/book3s64/hash_pgtable.c b/arch/powerpc/mm/book= 3s64/hash_pgtable.c index d9b5b751d7b7..88a4a2eab513 100644 --- a/arch/powerpc/mm/book3s64/hash_pgtable.c +++ b/arch/powerpc/mm/book3s64/hash_pgtable.c @@ -391,7 +391,7 @@ pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *m= m, return old_pmd; } =20 -int hash__has_transparent_hugepage(void) +int hash__arch_has_pmd_leaves(void) { =20 if (!mmu_has_feature(MMU_FTR_16M_PAGE)) @@ -420,7 +420,7 @@ int hash__has_transparent_hugepage(void) =20 return 1; } -EXPORT_SYMBOL_GPL(hash__has_transparent_hugepage); +EXPORT_SYMBOL_GPL(hash__arch_has_pmd_leaves); =20 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtabl= e.h index 2c6cee8241e0..33b165dbf3db 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1799,8 +1799,8 @@ static inline int pmd_trans_huge(pmd_t pmd) return pmd_leaf(pmd); } =20 -#define has_transparent_hugepage has_transparent_hugepage -static inline int has_transparent_hugepage(void) +#define arch_has_pmd_leaves arch_has_pmd_leaves +static inline int arch_has_pmd_leaves(void) { return cpu_has_edat1() ? 1 : 0; } diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 2187e9cfcefa..2edd6c9d789c 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -306,8 +306,8 @@ static inline int pud_trans_huge(pud_t pud) } #endif =20 -#define has_transparent_hugepage has_transparent_hugepage -static inline int has_transparent_hugepage(void) +#define arch_has_pmd_leaves arch_has_pmd_leaves +static inline int arch_has_pmd_leaves(void) { return boot_cpu_has(X86_FEATURE_PSE); } diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index b365be3516bf..3d7eeb50c183 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2273,8 +2273,8 @@ static inline void __init init_arch_has_pmd_leaves(vo= id) { } #endif #endif =20 -#ifndef has_transparent_hugepage -#define has_transparent_hugepage() IS_BUILTIN(CONFIG_TRANSPARENT_HUGEPAGE) +#ifndef arch_has_pmd_leaves +#define arch_has_pmd_leaves() IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGE= PAGE) #endif =20 #ifndef has_transparent_pud_hugepage diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 970e077019b7..4da10e94bbb6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -969,7 +969,7 @@ static int __init hugepage_init(void) int err; struct kobject *hugepage_kobj; =20 - if (!has_transparent_hugepage()) { + if (!arch_has_pmd_leaves()) { transparent_hugepage_flags =3D 1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED; return -EINVAL; } diff --git a/mm/memory.c b/mm/memory.c index 90b2d9e84320..c62fce83b8d0 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -169,7 +169,7 @@ EXPORT_SYMBOL(__arch_has_pmd_leaves_key); =20 void __init init_arch_has_pmd_leaves(void) { - if (!has_transparent_hugepage()) + if (!arch_has_pmd_leaves()) static_branch_disable(&__arch_has_pmd_leaves_key); } =20 --=20 2.53.0 From nobody Sun Jun 14 07:34:35 2026 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 B52EF3CF032 for ; Fri, 1 May 2026 19:20:32 +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=1777663234; cv=none; b=a6y7bLzUXUtrfdKfQsocQe0gRJSaG9AXrjNvy0i/q/gEhS2JEHqaC6cCKMRHtgez0gP3yn0srxP3FuqhCKBuEDlABZzo+PkIorzzQw7zhgmQ8pCm4rvmk/RR3h1pG+E/fSJIAAvXgtH9NbbYiLqhWHC5HQfmnVQK/T/YQJzdv8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663234; c=relaxed/simple; bh=yoZ215hOaFb1g/656xkJ3NJy9TUqaIB+GbJNfya65HA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BDogbGkkeH5QKUz5U9vovVMpfYy7hMGd3perqjdKZekFEGmWva24A3yqyWimxpbcKqpe5HptwY1tQRjf3FGgmnYCwMilcf7ejtqcSVV5A8hmYb1ZFVa21nIOktSjf+ArTj8iU4TJaRzCGllU7hJnarc83kWR/H03ueBzp9YY70I= 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=cWm4oLIE; 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="cWm4oLIE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663231; 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=MIFo0ncNVscrQBUDwO88EyFcNSwZmzv9OtuTCZgG/qA=; b=cWm4oLIE7Drw0CS6XlzbmctqnCFTDlcWxYzUZY5KZ8Sfub3rxENQind41pyH1N4JtOGOd+ Y2XeBpQpCB7oboHGNcUFl/XGndJPPFSv8yLKoEoAz0LNbeA5tZyAtjFHc9ui5GGjIN5Wkh LfWgwQrL2X2KTsGvRQjYMj2gXiUblVc= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-425-10OX0OkDPp6iQ2ERQs7qFA-1; Fri, 01 May 2026 15:20:26 -0400 X-MC-Unique: 10OX0OkDPp6iQ2ERQs7qFA-1 X-Mimecast-MFC-AGG-ID: 10OX0OkDPp6iQ2ERQs7qFA_1777663223 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B80B8180034B; Fri, 1 May 2026 19:20:23 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E481D1800906; Fri, 1 May 2026 19:20:20 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 8/9] mm: replace thp_disabled_by_hw() with pgtable_has_pmd_leaves() Date: Fri, 1 May 2026 15:18:50 -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" Despite its name, thp_disabled_by_hw() just checks whether the architecture supports PMD-sized pages. It returns true when TRANSPARENT_HUGEPAGE_UNSUPPORTED is set in transparent_hugepage_flags, this only occurs if the architecture implements arch_has_pmd_leaves() and that function returns false. Since pgtable_has_pmd_leaves() provides the same semantics, use it instead. Reviewed-by: Lance Yang Reviewed-by: Baolin Wang Acked-by: Zi Yan Signed-off-by: Luiz Capitulino Acked-by: David Hildenbrand (Arm) --- include/linux/huge_mm.h | 7 ------- mm/huge_memory.c | 6 ++---- mm/memory.c | 2 +- mm/shmem.c | 2 +- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 2949e5acff35..da048aa06761 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -47,7 +47,6 @@ vm_fault_t vmf_insert_folio_pud(struct vm_fault *vmf, str= uct folio *folio, bool write); =20 enum transparent_hugepage_flag { - TRANSPARENT_HUGEPAGE_UNSUPPORTED, TRANSPARENT_HUGEPAGE_FLAG, TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, @@ -352,12 +351,6 @@ static inline bool vma_thp_disabled(struct vm_area_str= uct *vma, return mm_flags_test(MMF_DISABLE_THP_EXCEPT_ADVISED, vma->vm_mm); } =20 -static inline bool thp_disabled_by_hw(void) -{ - /* If the hardware/firmware marked hugepage support disabled. */ - return transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTE= D); -} - unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned lo= ng addr, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4da10e94bbb6..32254febe097 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -133,7 +133,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area= _struct *vma, if (!vma->vm_mm) /* vdso */ return 0; =20 - if (thp_disabled_by_hw() || vma_thp_disabled(vma, vm_flags, forced_collap= se)) + if (!pgtable_has_pmd_leaves() || vma_thp_disabled(vma, vm_flags, forced_c= ollapse)) return 0; =20 /* khugepaged doesn't collapse DAX vma, but page fault is fine. */ @@ -969,10 +969,8 @@ static int __init hugepage_init(void) int err; struct kobject *hugepage_kobj; =20 - if (!arch_has_pmd_leaves()) { - transparent_hugepage_flags =3D 1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED; + if (!pgtable_has_pmd_leaves()) return -EINVAL; - } =20 /* * hugepages can't be allocated by the buddy allocator diff --git a/mm/memory.c b/mm/memory.c index c62fce83b8d0..483af476d9b2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5522,7 +5522,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct fo= lio *folio, struct page *pa * PMD mappings if THPs are disabled. As we already have a THP, * behave as if we are forcing a collapse. */ - if (thp_disabled_by_hw() || vma_thp_disabled(vma, vma->vm_flags, + if (!pgtable_has_pmd_leaves() || vma_thp_disabled(vma, vma->vm_flags, /* forced_collapse=3D*/ true)) return ret; =20 diff --git a/mm/shmem.c b/mm/shmem.c index 1948d73fb1e3..a48f034830cd 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1842,7 +1842,7 @@ unsigned long shmem_allowable_huge_orders(struct inod= e *inode, vm_flags_t vm_flags =3D vma ? vma->vm_flags : 0; unsigned int global_orders; =20 - if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags, shmem= _huge_force))) + if (!pgtable_has_pmd_leaves() || (vma && vma_thp_disabled(vma, vm_flags, = shmem_huge_force))) return 0; =20 global_orders =3D shmem_huge_global_enabled(inode, index, write_end, --=20 2.53.0 From nobody Sun Jun 14 07:34:35 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 0BBED361DA0 for ; Fri, 1 May 2026 19:20:33 +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=1777663235; cv=none; b=cEW9PF5ytDtYyMJYcMKONqK0qvarwc9TOtRM92dApUJj1nCNxNKjHAMMTtT/kxmCV+bPc8n0p5DBcLkGZ28/Qyov5f9eaYJ7pFT+ukB50LzH+yn9l3Ljm0/adwzKHsghyxrJlqqwv/rsjj2mIzH/GuvdAWf5wWvp8IuQfG9LfGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777663235; c=relaxed/simple; bh=zTmmwtRW5eOUa0XVvzuHMct5Gy2vUp5HzUBqsMEMbs0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OkWQOrMDyztNBdNdAGiPQEB/08VUSnFzh3KWTpS/oQQ0QuSkv0BvQ6y9z2ICggzLJQ07o6U8mvfaAjOuoAHHKRqojMeGhN1qofEICZSQ3D+M5H3UsFSAy10WUjcylmVPLNRXtR0K/FUMqDUr8f9qBpzI2DBe1m/eDQYOHUVXJyQ= 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=c49qXg+K; 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="c49qXg+K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777663233; 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=+8y7DwT1Mvod+Su8a9kqNPeVGjZgNT6OWk7sX0RRnCo=; b=c49qXg+KefWG/wAcmfPdlw81XQ/+wo7CS8fhgJHlsIG7aEhkVGXtF2sTMZKiQlMdNqhP+o AtdBn0N9++WpP+aZ+wVKFC6rlWXwt+qciKR+JiGmAe97HUddWi3mtV9avqqWhjT6IpixNE Z1PpYRXc3PKt7+0CzVmK6QmtAYubas8= 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-102-xmOm1cvmMIS1ApbmwSCO1w-1; Fri, 01 May 2026 15:20:29 -0400 X-MC-Unique: xmOm1cvmMIS1ApbmwSCO1w-1 X-Mimecast-MFC-AGG-ID: xmOm1cvmMIS1ApbmwSCO1w_1777663227 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 BBEC5195608B; Fri, 1 May 2026 19:20:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EECEF1800480; Fri, 1 May 2026 19:20:23 +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, dave.hansen@linux.intel.com, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v4 9/9] mm: thp: always enable mTHP support Date: Fri, 1 May 2026 15:18:51 -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" If PMD-sized pages are not supported on an architecture (ie. the arch implements arch_has_pmd_leaves() and it returns false) then the current code disables all THP, including mTHP. This commit fixes this by allowing mTHP to be always enabled for all archs. When PMD-sized pages are not supported, its sysfs entry won't be created and their mapping will be disallowed at page-fault time. Similarly, this commit implements the following changes for shmem in shmem_allowable_huge_orders(): - Drop the pgtable_has_pmd_leaves() check so that mTHP sizes are considered - Filter out PMD and PUD orders from allowable orders when PMD-sized pages are not supported by the CPU Signed-off-by: Luiz Capitulino Reviewed-by: Baolin Wang --- mm/huge_memory.c | 23 ++++++++++++++++++----- mm/shmem.c | 14 +++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 32254febe097..c1765c8e3dc6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -126,6 +126,14 @@ unsigned long __thp_vma_allowable_orders(struct vm_are= a_struct *vma, else supported_orders =3D THP_ORDERS_ALL_FILE_DEFAULT; =20 + if (!pgtable_has_pmd_leaves()) { + /* + * The CPU doesn't support PMD-sized pages, assume it + * doesn't support PUD-sized pages either. + */ + supported_orders &=3D ~(BIT(PMD_ORDER) | BIT(PUD_ORDER)); + } + orders &=3D supported_orders; if (!orders) return 0; @@ -133,7 +141,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area= _struct *vma, if (!vma->vm_mm) /* vdso */ return 0; =20 - if (!pgtable_has_pmd_leaves() || vma_thp_disabled(vma, vm_flags, forced_c= ollapse)) + if (vma_thp_disabled(vma, vm_flags, forced_collapse)) return 0; =20 /* khugepaged doesn't collapse DAX vma, but page fault is fine. */ @@ -848,7 +856,7 @@ static int __init hugepage_init_sysfs(struct kobject **= hugepage_kobj) * disable all other sizes. powerpc's PMD_ORDER isn't a compile-time * constant so we have to do this here. */ - if (!anon_orders_configured) + if (!anon_orders_configured && pgtable_has_pmd_leaves()) huge_anon_orders_inherit =3D BIT(PMD_ORDER); =20 *hugepage_kobj =3D kobject_create_and_add("transparent_hugepage", mm_kobj= ); @@ -870,6 +878,14 @@ static int __init hugepage_init_sysfs(struct kobject *= *hugepage_kobj) } =20 orders =3D THP_ORDERS_ALL_ANON | THP_ORDERS_ALL_FILE_DEFAULT; + if (!pgtable_has_pmd_leaves()) { + /* + * The CPU doesn't support PMD-sized pages, assume it + * doesn't support PUD-sized pages either. + */ + orders &=3D ~(BIT(PMD_ORDER) | BIT(PUD_ORDER)); + } + order =3D highest_order(orders); while (orders) { thpsize =3D thpsize_create(order, *hugepage_kobj); @@ -969,9 +985,6 @@ static int __init hugepage_init(void) int err; struct kobject *hugepage_kobj; =20 - if (!pgtable_has_pmd_leaves()) - return -EINVAL; - /* * hugepages can't be allocated by the buddy allocator */ diff --git a/mm/shmem.c b/mm/shmem.c index a48f034830cd..23893c2bc2dd 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1840,16 +1840,19 @@ unsigned long shmem_allowable_huge_orders(struct in= ode *inode, unsigned long mask =3D READ_ONCE(huge_shmem_orders_always); unsigned long within_size_orders =3D READ_ONCE(huge_shmem_orders_within_s= ize); vm_flags_t vm_flags =3D vma ? vma->vm_flags : 0; - unsigned int global_orders; + unsigned int global_orders, filter_orders =3D 0; =20 - if (!pgtable_has_pmd_leaves() || (vma && vma_thp_disabled(vma, vm_flags, = shmem_huge_force))) + if (vma && vma_thp_disabled(vma, vm_flags, shmem_huge_force)) return 0; =20 + if (!pgtable_has_pmd_leaves()) + filter_orders =3D BIT(PMD_ORDER) | BIT(PUD_ORDER); + global_orders =3D shmem_huge_global_enabled(inode, index, write_end, shmem_huge_force, vma, vm_flags); /* Tmpfs huge pages allocation */ if (!vma || !vma_is_anon_shmem(vma)) - return global_orders; + return global_orders & ~filter_orders; =20 /* * Following the 'deny' semantics of the top level, force the huge @@ -1863,7 +1866,7 @@ unsigned long shmem_allowable_huge_orders(struct inod= e *inode, * means non-PMD sized THP can not override 'huge' mount option now. */ if (shmem_huge =3D=3D SHMEM_HUGE_FORCE) - return READ_ONCE(huge_shmem_orders_inherit); + return READ_ONCE(huge_shmem_orders_inherit) & ~filter_orders; =20 /* Allow mTHP that will be fully within i_size. */ mask |=3D shmem_get_orders_within_size(inode, within_size_orders, index, = 0); @@ -1874,6 +1877,7 @@ unsigned long shmem_allowable_huge_orders(struct inod= e *inode, if (global_orders > 0) mask |=3D READ_ONCE(huge_shmem_orders_inherit); =20 + mask &=3D ~filter_orders; return THP_ORDERS_ALL_FILE_DEFAULT & mask; } =20 @@ -5457,7 +5461,7 @@ void __init shmem_init(void) * Default to setting PMD-sized THP to inherit the global setting and * disable all other multi-size THPs. */ - if (!shmem_orders_configured) + if (!shmem_orders_configured && pgtable_has_pmd_leaves()) huge_shmem_orders_inherit =3D BIT(HPAGE_PMD_ORDER); #endif return; --=20 2.53.0