From nobody Sat Sep 26 13:46:40 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 76A5C4398FD for ; Tue, 1 Sep 2026 03:12:53 +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=1788232375; cv=none; b=kytO6jiSsrsxyIxTHzRsnO6noRGGvxnUthjtmqUy3ShwFxIuqKNF9h08YUd1rOSs0t/+1Fywn0YTXeYtNc/qU3BSRHgh3Lnn6lVMYKoaxKTxJl7cIN2kh5gtFpTjClAJzBiizoslAWoyvi1xylN34jau2b7KlAtqssf4Q5LoByM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232375; c=relaxed/simple; bh=jjjHMPkdak8lkkYB/pcSbYZxNq0AkW3cx++JKabbUsA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A1IzPgvn5LmlXKDRrubIFCycF7MN3yauwqd7pUoZPg3zyHljTpSYd/we2rk4B/OtPLBghS5++D2HCGcbTY4F0P5VEqCs0whevx1wJYiUfJyu7q4BTbHJBabQ9Q+L4niMp9FFCTWQckOUMVcygHfgLTGrThj3Vnr0cMkMmVTsxeo= 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=ctAyUZzB; 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="ctAyUZzB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232372; 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=aTPhd0YOiSXsclxv5AA53kAUpU9ZSjRHrVegM1KWz8s=; b=ctAyUZzBfCez2JzSDyovF7sUGmHysW43CyajCdpvfk28uMjQGSd8Pyv32ctxVQxlzhjdBv wUeQeqikiBJzrb+MHz2lHK0W10Kd2007Sh9kqKKRkCheFQA0HAvkIV9ZAXdmGjRsHp+QFb Cqr5r0J6vLGEQatGp70as51FvTmnXZ8= 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-298-w99-JZioNOeppOKV-AZtOg-1; Mon, 31 Aug 2026 23:12:48 -0400 X-MC-Unique: w99-JZioNOeppOKV-AZtOg-1 X-Mimecast-MFC-AGG-ID: w99-JZioNOeppOKV-AZtOg_1788232365 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 C86EF19774DB; Tue, 1 Sep 2026 03:12:43 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D042618005B7; Tue, 1 Sep 2026 03:12:38 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 01/14] docs: tmpfs: remove implementation detail reference Date: Mon, 31 Aug 2026 23:12:05 -0400 Message-ID: <7205859de9c2e3bde0cb1d9539a3976bd4b31d9e.1788232334.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 Reviewed-by: Dev Jain 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.55.0 From nobody Sat Sep 26 13:46:40 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 3A60A392807 for ; Tue, 1 Sep 2026 03:12:58 +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=1788232379; cv=none; b=UVpJYqylnkSXozyETX56Mvys4qMAShiBsMRW2LHF8u5ry7T92Bb6sDXsKfu/bEnHWoaSdP1PA62SDq0y2D1aCvV0Ic179k7IFxQbvfGAuYJ9gG3+f5swv1lJDehLlTdpvh1DI5yHHTWwMsAQx8Djk+vXVQfIycc252vuoTNw5H0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232379; c=relaxed/simple; bh=/g85e5VUvc/+J8Z6oeY5QKxvevGtt3AtN7aUwC2HJ5E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WTXfUnUKsgJwnqunDwdAXZxdkeJJavLvUNFAzgkQ8i3wC1ud/H4yzL706ArCsVMTHP8ADBJYiyF5SFBNdvMwH+DuXj+RBEExH1rQfbhaXmC4+RBG1Ha67M4PSHazV2T7lDg4T09cv/pkPacKSYn2ez7H8mdBfoSY8ihql2TDWsc= 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=SRMVEDW8; 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="SRMVEDW8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232377; 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=6/15VKFd0k8fjwRB+GcpY7pyNM2oKVrWq2M5AHqmwy8=; b=SRMVEDW8ojL3gh77J0lsEMRN1iOpCQGwvYWTURlxVj2teLzpwY8cOW1rlrsVziyqUYBTin 7b0SjTqeRT/4dH02xwzWSsKjn62uQf/B+tzA2f4ozLM8b8XePJJnL6SdfqouBSGv/Pidti qh8UTnUT5LIRYE5n1FVuNRsljS9Hed8= 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-335-s-uJBlnQOgWk27tOwn31BQ-1; Mon, 31 Aug 2026 23:12:53 -0400 X-MC-Unique: s-uJBlnQOgWk27tOwn31BQ-1 X-Mimecast-MFC-AGG-ID: s-uJBlnQOgWk27tOwn31BQ_1788232370 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 C57901955F61; Tue, 1 Sep 2026 03:12:48 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0AE9B18005B8; Tue, 1 Sep 2026 03:12:43 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 02/14] mm: shmem: shmem_getattr(): set blksize to highest supported THP order Date: Mon, 31 Aug 2026 23:12:06 -0400 Message-ID: <4d61dc5e8d6ffe957020eb34f57fb51099c2913b.1788232334.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" Today, shmem_getattr() sets stat->blksize to PMD size whenever shmem_huge_global_enabled() returns non-zero. While this works fine for the normal THP-enabled case as explained by Baolin in [1], this has two problems: 1. Theoretically, when shmem is configured for within_size, this could set blksize to PMD size even though the allocation may be a smaller mTHP order 2. A future commit will allow shmem THP support to be enabled even when the CPU doesn't support PMD-sized pages. We should not allow blksize to be set to PMD size in this case In order to fix #1 and prepare for #2, this commit sets blksize to the size of the highest supported order returned by shmem_huge_global_enabled(). [1] https://lore.kernel.org/linux-mm/6591a74c-7ef9-4614-9ae9-cb2fbed86ebf= @linux.alibaba.com/ Suggested-by: Baolin Wang Acked-by: Zi Yan Signed-off-by: Luiz Capitulino --- mm/shmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index eeb9a78c125a..b963f55640a8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1506,6 +1506,7 @@ static int shmem_getattr(struct mnt_idmap *idmap, { struct inode *inode =3D path->dentry->d_inode; struct shmem_inode_info *info =3D SHMEM_I(inode); + unsigned int orders; =20 /* Fast-path hint; recalc under info->lock corrects any stale read. */ if (data_race(info->alloced - info->swapped !=3D inode->i_mapping->nrpage= s)) @@ -1522,8 +1523,9 @@ static int shmem_getattr(struct mnt_idmap *idmap, STATX_ATTR_NODUMP); generic_fillattr(idmap, request_mask, inode, stat); =20 - if (shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0)) - stat->blksize =3D HPAGE_PMD_SIZE; + orders =3D shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0); + if (orders) + stat->blksize =3D PAGE_SIZE << highest_order(orders); =20 if (request_mask & STATX_BTIME) { stat->result_mask |=3D STATX_BTIME; --=20 2.55.0 From nobody Sat Sep 26 13:46:40 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 0C7A643C7C5 for ; Tue, 1 Sep 2026 03:13: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=1788232383; cv=none; b=O0t06MsfILNMK9pp3CcKVn854qImbPQOYTM+fZ5yVmjor3b/o50DKCWjW4t8Ha1lKt2xMRFfNbVNtgeiZLSj5H2V2Bx48uLxeAK7aBVBNAv7WnknR+VfXh5MeFE/yk8fPYnAp+q25KSEbujI2kFpr8jWH/wlV57xnVYw3NJ4HYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232383; c=relaxed/simple; bh=02J+Qe5fyesF586IwRP1eymetPveRTZQ6LiTFPk0jts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jrUVSmi2JwT6kibJirFFWVXGH2pTpKRQyZ7vZYC+arpMRzCoKOu6WaEt5vB167cr/PL0KiuRvRm31o7CM6rOmnT9hnKOExdpQvkzYqVoUPyh4/obSRmvvi4wJv71mQqwlhDhz5ttdqjciYaUS6fCuHh9CO+hvcs3WYNMW/3EV8g= 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=QHUvRZlq; 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="QHUvRZlq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232381; 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=3/uIoSPqM2R1drx5bO2xtSm3XMBl+fSHryO7BumUdVU=; b=QHUvRZlqnYsa1Loj/63v+JK7mz7to2UvqBv5Sr8MDna210xa6YFncmXd2Z1Igwk5Iq1yx/ pfJNdLblXB59JNBQw8/P0TYF+tcXtnw26VwUbC6t6S7YhuWsEuxO+Z+vD1BPXQo2r5RxrD evcQ7pcVnZ6JW3jIaH4eY6oUYiuVAQw= 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-131-8Qe_BjHDOQeJU0moI1Z-Vg-1; Mon, 31 Aug 2026 23:12:57 -0400 X-MC-Unique: 8Qe_BjHDOQeJU0moI1Z-Vg-1 X-Mimecast-MFC-AGG-ID: 8Qe_BjHDOQeJU0moI1Z-Vg_1788232374 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 8C6EC1843AD1; Tue, 1 Sep 2026 03:12:53 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0738018005B7; Tue, 1 Sep 2026 03:12:48 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 03/14] mm: introduce pgtable_has_pmd_leaves() Date: Mon, 31 Aug 2026 23:12:07 -0400 Message-ID: <57cfee4b4c203b8c5219739d5da1ba7d118d2d23.1788232334.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() during boot. This helper is used in fast paths A better design would be to separate CONFIG_TRANSPARENT_HUGEPAGE checking, which can be done with the IS_ENABLED() macro, from checking if a CPU supports PMD-sized pages. To this end, this commit introduces a new helper called pgtable_has_pmd_leaves() which offers the following advantages: 1. Well defined and clear semantics: it returns true if the CPU supports PMD-sized pages and false otherwise 2. It always returns a cached value, so it can be used in fast paths 3. It's implemented with a static key: it's a no-op for archs not implemeting it and for archs implementing it the static key is changed only during boot 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() and/or IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE). 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 =20 @@ -2313,6 +2314,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 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__ */ =20 #if !defined(MAX_POSSIBLE_PHYSMEM_BITS) && !defined(CONFIG_64BIT) diff --git a/mm/memory.c b/mm/memory.c index bc14cae3c49d..69ab1bb54853 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 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 33ff95141adb..0476d54d0b6f 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2645,6 +2645,7 @@ void __init mm_core_init(void) { arch_mm_preinit(); init_zero_page_pfn(); + pgtable_leaf_support_init(); =20 /* Initializations relying on SMP setup */ BUILD_BUG_ON(MAX_ZONELISTS > 2); --=20 2.55.0 From nobody Sat Sep 26 13:46:40 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 21EC929408 for ; Tue, 1 Sep 2026 03:13:07 +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=1788232389; cv=none; b=djSLvdlxfpSI6e6E+6jIC7I5x824T634hO3UEBEIhaqMeaCkbhgiy+Mflwu24Spn2NgVkjuvyBOKJDTR9e9UTl1tdqJu9qPWqCl4gOv8X1t6hF5RJR4pxFtg8jNvDMi7kcJOBrR1rAs5Eena76tX6+8ildERQZ49MQX12FxElUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232389; c=relaxed/simple; bh=IWo8K8Ath75VoPrVg1XoiMwhI4xLfgFkKOpsccJJuWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ay0ggvzJWzT3kOFnT+973Puzh3IW0ZkWOMz/qERN+QMcfmhJCNQ8qdtCbwAAFsAQJAsPBzlmGwMsZGZMRuTVi+FzzjP+nPYci78ajr821rYbx35oJ09jiaRTxoP4G7wbJb96H17+s84BqhEhSGpQGxpumiPDXTaT2vy9y4o2SuE= 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=NQTOVxiA; 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="NQTOVxiA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232387; 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=U5VGhony2GlXcldX4fKODtBEKHSnENc20be4cbUK9lc=; b=NQTOVxiAGifnrV0XIQBtJeGBvO30JFKaElqUo/gwIPYNk566arNtvnRMrjvQDK8ilmTGxU /b50qpo9FGgLw8YZYRHZq1aqykB711vrWBqpe+hfHXGes/iSaC0h5r0hndtZJ6S/eItVp0 geAwsteninRtvK4UdS1Qwh3JjNt33co= 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-152-mDrP8zVkNGum5w-rbgaU_g-1; Mon, 31 Aug 2026 23:13:02 -0400 X-MC-Unique: mDrP8zVkNGum5w-rbgaU_g-1 X-Mimecast-MFC-AGG-ID: mDrP8zVkNGum5w-rbgaU_g_1788232378 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 7CC8919792E3; Tue, 1 Sep 2026 03:12:57 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C14CE18005B8; Tue, 1 Sep 2026 03:12:53 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 04/14] drivers: dax: use pgtable_has_pmd_leaves() Date: Mon, 31 Aug 2026 23:12:08 -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 607a53a91f58..18a6295aa766 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -121,7 +121,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.55.0 From nobody Sat Sep 26 13:46:40 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 6998343BDD6 for ; Tue, 1 Sep 2026 03:13:09 +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=1788232391; cv=none; b=lFmtAcS2JtJjezVMOWReEVc3yN9oCjzbifQd7h/S74SjhBVUVfLkiSBJRKk9P/xLJyBOmL6PO/TUsvv3BCV7e4YsdY27xfXipExWfxp3QP88xw2/bX60jdXGOGDUG3GWDsrzFXrdI42ysBTOzqE7RZTsSsNsyM08jN9+BS8tbZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232391; c=relaxed/simple; bh=V/ZoTEkWXOtImTwoEfhGMxCO3nj3l9asJXzzKsI+Wd4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t/Ygw4DZpdeBFdtqxlsx327C5PBHAN5n7R0v9ASOaDhZAMXCB9t9fpQutL4OCVtMw7ufr6yeUXS7IqyfUHpuH2qF7BvyOpD1vkxnCVLW9dJDbck/4k3R1ReJ3b9t/YTHquA1l5fn+yLkyAFkmmRcZiM0EFrFwdLJ/VYpEvid9hw= 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=hDcQR0V4; 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="hDcQR0V4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232388; 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=vWKt08g60DdFG3Icxm2Us7CxOftu08depFwjwgt6DxU=; b=hDcQR0V4JbiP5l2/GIxrJ3hf/W4aDheCmkSX0W3U5zSL3PQ8JIEArTWxr2bNftg1c8di1A iSMl72X1zpB2IlMZt746EA0xuMuF/QnIOqLMjnemrpHh58QW0uYKnf4I5+WIx7IGNGBZmX Kz55ToxDrqMCjFe8LcmZTsEDMYfWrBU= 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-682-iIcXydKnMJSdbTVyIHsEhQ-1; Mon, 31 Aug 2026 23:13:05 -0400 X-MC-Unique: iIcXydKnMJSdbTVyIHsEhQ-1 X-Mimecast-MFC-AGG-ID: iIcXydKnMJSdbTVyIHsEhQ_1788232382 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 D44B118707A6; Tue, 1 Sep 2026 03:13:01 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B33DF18005B7; Tue, 1 Sep 2026 03:12:57 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 05/14] drivers: nvdimm: use pgtable_has_pmd_leaves() Date: Mon, 31 Aug 2026 23:12:09 -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" 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.55.0 From nobody Sat Sep 26 13:46:40 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 D198343CE70 for ; Tue, 1 Sep 2026 03:13: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=1788232396; cv=none; b=aQ0LF98gTMNRZvMMBarwnwR166bEm8jgUZRECZZ8SXGc33mJB+CnacPpskBU3LvGdmZDR+MtadZPdKT6dcFV5mFexzeUkhPQcaaSn0k2xxpc4+mygQeFtzs+xG2bHZ9x9atCz44BRcRnDa03v6z4Gfo5ddNDDBfr2SDNU1opPbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232396; c=relaxed/simple; bh=4V3DzS2gX3wjcHhnRervOk7hTouQtCPr8g2YJfIu0w8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iKHj8NFx3pbFAmUF1nD9pgIOXoptA60VwB9CDeU/f7aavAI3cJior7XTTsiKxT8mLVQwUICQ9rWPw5Ca6TS+8ef/2oHmfeD2Ecrvh4axIQ6BFqeuAl/Tojv0c+GFAhRToTy4WQKHSR8lKJVjfedtk+lq+WsYS0hMjOuz1Pv4aDE= 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=Dl2+FS/X; 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="Dl2+FS/X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232393; 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=jaZuFD7TaK5q+SRf/M6wNF+Sb+xKBaTWhSdcsCrRx7E=; b=Dl2+FS/XbE6Q9aK5cyNeYLin5EZbKmN5L0ziTEoLIckZqEZs7Ns1gAUWhgCXRfBQ+hSwrk c9mvTR2CwCO9lw92ZBhuU7G/H+bYZpPO4aMc7rUxk32Jch9hRhkRoabw9QAZZ0+v39BCAx rxLKmmIn4O+ciWbMFiW30rLZYy22Clo= 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-659-0-t71zyqNBGa9_pVECkung-1; Mon, 31 Aug 2026 23:13:09 -0400 X-MC-Unique: 0-t71zyqNBGa9_pVECkung-1 X-Mimecast-MFC-AGG-ID: 0-t71zyqNBGa9_pVECkung_1788232387 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 6E9281944A8E; Tue, 1 Sep 2026 03:13:06 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 181EA18005BD; Tue, 1 Sep 2026 03:13:01 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 06/14] mm: debug_vm_pgtable: use pgtable_has_pmd_leaves() Date: Mon, 31 Aug 2026 23:12:10 -0400 Message-ID: <23277327a26a0bcdc6efab1f699d266bbe729cbd.1788232334.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 2875fd22d7bb..25038b74c7bc 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_ARCH_HAS_PTE_PROTNONE)) 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_HAS_PMD_SOFTLEAVES)) 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.55.0 From nobody Sat Sep 26 13:46:40 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 C522143C05E for ; Tue, 1 Sep 2026 03:13:18 +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=1788232400; cv=none; b=QfdhTYgGbJbvEkqzgbK2zpDyyrfFNt/Rlc2SYNnB+evZ35xTeHC8P04HuXH79RbkhGt/dC6HJTjwXtuGwJZKSlSXOCAnnxl7hUJ3m8NUORGKKWDXGixKcaD0p7KeQQ+xQUshtOcqSykx5o+Tu4LXl6apEadpTy766S6PKVoF7wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232400; c=relaxed/simple; bh=DWQmB4xdOyp+bRvvjhFT0MNhErC58LhVvAIxgJYVUgQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tHKo5o81A0eLENB4yKfSMig9+VEYvF2kFyWI75yTKgmb61Aodhiu8qBkC3p9Gr9K8JmUAUgTbiTVn/giXgnfbCn93I7WD5m2qbdABrPmD8o4LEOwAbKdZRZ6+lKjLlfY8+FG6roSrpZQRhevk8XMbK1i3aFCfuZ9ITCeL5qGuh0= 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=E+H10Hx/; 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="E+H10Hx/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232397; 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=5/r7ApZA/+iU7/IPziHFVic/Rma7PRrQe4ZXAKweg9I=; b=E+H10Hx/vnfoMhj8HeaifwDhgYrvadd5k9LpdaI65C2n5UQ7/obTiUzs3F3BNg/tdG7AyV WeUxBbT8eV8XcXxP8PJJthUojPX99JlxURv6RTb6oFSqQAEXMwr/BWXcW8gq2Qfqj4KVwm k3gND4enk5Sets9sjQf2IKwIwmTaoIk= 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-651-K3s1vfWkNe6lSHNICysDqg-1; Mon, 31 Aug 2026 23:13:13 -0400 X-MC-Unique: K3s1vfWkNe6lSHNICysDqg-1 X-Mimecast-MFC-AGG-ID: K3s1vfWkNe6lSHNICysDqg_1788232390 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 1BE0C1843AD5; Tue, 1 Sep 2026 03:13:10 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A41AC18005B8; Tue, 1 Sep 2026 03:13:06 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 07/14] mm: shmem: allow THP support determination at folio allocation time Date: Mon, 31 Aug 2026 23:12:11 -0400 Message-ID: <600c346841252a68d4c1792f74c515c345ace4ce.1788232334.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" In order to enable THP support in shmem today, besides the user configuration required, the CPU must support PMD-sized pages. This is the case because of the following has_transparent_hugepage() usage: - 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 THP size support at folio allocation time. Therefore, drop the has_transparent_hugepage() usage listed above while keeping the CONFIG_TRANSPARENT_HUGEPAGE checks. Additionally, we need to check if PMD size order is supported in shmem_getattr(). Use pgtable_has_pmd_leaves() for that. Reviewed-by: Baolin Wang Signed-off-by: Luiz Capitulino --- mm/shmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b963f55640a8..c285cb7fd32e 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -690,7 +690,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 @@ -1524,6 +1524,8 @@ static int shmem_getattr(struct mnt_idmap *idmap, generic_fillattr(idmap, request_mask, inode, stat); =20 orders =3D shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0); + if (!pgtable_has_pmd_leaves()) + orders &=3D ~BIT(PMD_ORDER); if (orders) stat->blksize =3D PAGE_SIZE << highest_order(orders); =20 @@ -4810,8 +4812,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; @@ -5616,7 +5617,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.55.0 From nobody Sat Sep 26 13:46:40 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 CF0C543CEC8 for ; Tue, 1 Sep 2026 03:13:22 +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=1788232404; cv=none; b=b/j8N+Rh3bSK+Vfov9ZBg71qso5CPRDsIHZQWQxZ4IJuYMPFwnlzVsoBnCt9NpUrBhCEFWhmdI6butRVqqw9p9xvdT5OptcJGBkBfVNXwskdPBpkzJharWkTy87bCBkOgYsyWtxQpI4/vcBJ3bSaMYWW5aj1zZFBxQb7CueRV30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232404; c=relaxed/simple; bh=vzP2y24how2k5GqsBVu45wjx4OYWghN6TbUbEftSVhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=acce+gXwKrkrFzRlsL39pAsidRAyrqhucXRlLuHHKH6g71u/AqxrjVnss4LI4VTOJODSywabjG+v4wcAO9NUGNARDYd5UQ+pRETnVxltlKJY904zWuZ6dDp4K8KHq2KPGmzy/zTMD52JPM5YqvoEWLmhueJ/Z1Aht7+iIeoJT+8= 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=EeGGIqpP; 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="EeGGIqpP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232401; 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=QTc935LDNPx7nXKta8GUS/LwnjuaroaKOzKm4nVuj4M=; b=EeGGIqpPP3hM+H8EB9ZEMV8Za2C6XuZGqu8cdbUS19/pi/nxAI8Lra1NF8OKRRb1fpdAPE 0k/5oX2kIyoNhEF5zs7hROkVIZaIrzybmRbK0nJlg/dRmzTIXMQQxJBdxcyiPrIFgSTJUS J60jbLx0eBbN8WfbuoQttb/B1+yHCpA= 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-232-OThTEAxzMc6Qm6uhOHF8eA-1; Mon, 31 Aug 2026 23:13:17 -0400 X-MC-Unique: OThTEAxzMc6Qm6uhOHF8eA-1 X-Mimecast-MFC-AGG-ID: OThTEAxzMc6Qm6uhOHF8eA_1788232394 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 2265D1944CC3; Tue, 1 Sep 2026 03:13:14 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 52AC618005BC; Tue, 1 Sep 2026 03:13:10 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 08/14] s390: move has_transparent_hugepage() out of THP guard Date: Mon, 31 Aug 2026 23:12:12 -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" A future commit will introduce a kernel API to allow for checking if the CPU supports PMD-sized pages. This API will be based on the has_transparent_hugepage() implementation but will be orthogonal to THP and therefore must work when CONFIG_TRANSPARENT_HUGEPAGE=3Dn. Move its definition out of the THP guard. Signed-off-by: Luiz Capitulino --- arch/s390/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtabl= e.h index e882663a58e7..5aa8f621df04 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1825,13 +1825,13 @@ static inline int pmd_trans_huge(pmd_t pmd) { return pmd_leaf(pmd); } +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 #define has_transparent_hugepage has_transparent_hugepage static inline int has_transparent_hugepage(void) { return cpu_has_edat1() ? 1 : 0; } -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 #ifdef CONFIG_PAGE_TABLE_CHECK static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned= long addr, pte_t pte) --=20 2.55.0 From nobody Sat Sep 26 13:46:40 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 4641143CE6D for ; Tue, 1 Sep 2026 03:13:25 +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=1788232407; cv=none; b=h/GCH0yna41wbOuAyN3qyL1p5SI4cGZoYioFaFUFi0l+JjEYfrgW6l9+sVNAg99lL92TdMmbnTyOVgU+TnWIBGSPggkVEN765vaOo135SMTAgT44ImrzRTiCPGhjo9/ekNod84W4IocG5qzB4vnyE9Zq6B4DlSTNDg3Lx/3Yeno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232407; c=relaxed/simple; bh=wt4KdYQ3pnl9rIoySNMwB93le9mpGPwkuH4rMhWXFUs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ae+FQSbebnJz06GhCTESaMuQOpOl82BaPHNGTyBas5XP37rZuJKEkRmpdkhENyQoHYIGTFKdglxCpo9QW+wtaHp4ofMqcYFG1/KtxPPJ1gR1zvZGhh5uJy9EWRe6ZIn36Z2c+YcB97DqF5pq+snZweYKF7pH8cDmLLqqnU+7rP4= 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=fdmCOYhl; 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="fdmCOYhl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232405; 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=crl0HXre1NIi+8woj4LEpZq1+eUcVCGkBif2epTDMXU=; b=fdmCOYhlzIGXELOK4pkZYdHOeLJqjDLWK0bbCK9PV0CwdHD3/oa774spAxd9Fpu7Yxs1io Zisccj2+MS9VleD01Uxr++iJzk/uf9c+VHtBCq1IFlquz3SnBtJftQ8Ewe4B5eYR9zznZs f5mtUUNWOvsJIvqiDengmvUSYHrQwfA= 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-352-prBHtdLwO_yvVuQfw_suXg-1; Mon, 31 Aug 2026 23:13:20 -0400 X-MC-Unique: prBHtdLwO_yvVuQfw_suXg-1 X-Mimecast-MFC-AGG-ID: prBHtdLwO_yvVuQfw_suXg_1788232397 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 ACEE81860975; Tue, 1 Sep 2026 03:13:17 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 40F5A18005BD; Tue, 1 Sep 2026 03:13: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, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 09/14] powerpc: move has_transparent_hugepage() out of THP guard Date: Mon, 31 Aug 2026 23:12:13 -0400 Message-ID: <5d7ed96fc5c9ffe357eca9cb48bd679d658dd8e0.1788232334.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" A future commit will introduce a kernel API to allow for checking if the CPU supports PMD-sized pages. This API will be based on the has_transparent_hugepage() implementation but will be orthogonal to THP and therefore must work when CONFIG_TRANSPARENT_HUGEPAGE=3Dn. Move its definition out of the THP guard. Signed-off-by: Luiz Capitulino --- 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 | 18 +++++++++--------- arch/powerpc/include/asm/book3s/64/radix.h | 14 +++++++------- arch/powerpc/mm/book3s64/hash_pgtable.c | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) 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..79511e6abfca 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-4k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-4k.h @@ -165,9 +165,9 @@ 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); #endif =20 +extern int hash__has_transparent_hugepage(void); #endif /* !__ASSEMBLER__ */ =20 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */ 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..a4a44a112ff9 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-64k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-64k.h @@ -278,9 +278,9 @@ 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); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 +extern int hash__has_transparent_hugepage(void); #endif /* __ASSEMBLER__ */ =20 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */ diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/asm/book3s/64/pgtable.h index f4db7d7fbd5c..2a795f6d9263 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -1121,15 +1121,6 @@ static inline void update_mmu_cache_pud(struct vm_ar= ea_struct *vma, { } =20 -extern int hash__has_transparent_hugepage(void); -static inline int has_transparent_hugepage(void) -{ - if (radix_enabled()) - return radix__has_transparent_hugepage(); - return hash__has_transparent_hugepage(); -} -#define has_transparent_hugepage has_transparent_hugepage - static inline int has_transparent_pud_hugepage(void) { if (radix_enabled()) @@ -1441,6 +1432,15 @@ static inline bool arch_needs_pgtable_deposit(void) =20 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 +extern int hash__has_transparent_hugepage(void); +static inline int has_transparent_hugepage(void) +{ + if (radix_enabled()) + return radix__has_transparent_hugepage(); + return hash__has_transparent_hugepage(); +} +#define has_transparent_hugepage has_transparent_hugepage + #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION pte_t ptep_modify_prot_start(struct vm_area_struct *, unsigned long, pte_t= *); void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long, diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/incl= ude/asm/book3s/64/radix.h index da954e779744..50545cf519bd 100644 --- a/arch/powerpc/include/asm/book3s/64/radix.h +++ b/arch/powerpc/include/asm/book3s/64/radix.h @@ -298,22 +298,22 @@ extern pmd_t radix__pmdp_huge_get_and_clear(struct mm= _struct *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__has_transparent_pud_hugepage(void) { - /* For radix 2M at PMD level means thp */ - if (mmu_psize_defs[MMU_PAGE_2M].shift =3D=3D PMD_SHIFT) + /* For radix 1G at PUD level means pud hugepage support */ + if (mmu_psize_defs[MMU_PAGE_1G].shift =3D=3D PUD_SHIFT) return 1; return 0; } +#endif =20 -static inline int radix__has_transparent_pud_hugepage(void) +static inline int radix__has_transparent_hugepage(void) { - /* For radix 1G at PUD level means pud hugepage support */ - if (mmu_psize_defs[MMU_PAGE_1G].shift =3D=3D PUD_SHIFT) + /* For radix 2M at PMD level means thp */ + if (mmu_psize_defs[MMU_PAGE_2M].shift =3D=3D PMD_SHIFT) return 1; return 0; } -#endif =20 struct vmem_altmap; struct dev_pagemap; diff --git a/arch/powerpc/mm/book3s64/hash_pgtable.c b/arch/powerpc/mm/book= 3s64/hash_pgtable.c index d9b5b751d7b7..50316f3fc5d3 100644 --- a/arch/powerpc/mm/book3s64/hash_pgtable.c +++ b/arch/powerpc/mm/book3s64/hash_pgtable.c @@ -391,6 +391,8 @@ pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *m= m, return old_pmd; } =20 +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + int hash__has_transparent_hugepage(void) { =20 @@ -422,8 +424,6 @@ int hash__has_transparent_hugepage(void) } EXPORT_SYMBOL_GPL(hash__has_transparent_hugepage); =20 -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ - #ifdef CONFIG_STRICT_KERNEL_RWX =20 struct change_memory_parms { --=20 2.55.0 From nobody Sat Sep 26 13:46:40 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 AF09843E078 for ; Tue, 1 Sep 2026 03:13:31 +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=1788232413; cv=none; b=oQf97BXlUnl9Zd0kmTduu5emo+2lNLICovJD4NSgdh2bzEpPBp7PeE49Ra715iVYnbaSINQLsoUn4hgKgM7f7SNkf7gUjhFOKVLgRCaHpsXntlYx++/nEjL0eBF2L5TKsOe4X/kTXMeA/wwE7wfbmQRsVrUHdY/YIekFqGwWBfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232413; c=relaxed/simple; bh=fllwW39kdUIFiI8dLb1EwgHE5lb7la7tdBmXdWvCsU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fzH3FbCRR3mHbgJYyD1srHi5xA4+5emqqkCQI7rt6KIyZjJBq0VDmwAvSqcRbTSYdRn4gjw5qAIoyO7JTQJOH5IamiBSbGlqybsf5+3MCFYikmRAA87IjVw8dj8A7mgZxaxZUKPgYSS8btxWDx4Fq2rwtVd9BU2rZXCKP4GHsoA= 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=A89+cN3Z; 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="A89+cN3Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232410; 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=kTRmmRqhPEEdzIyvqBzqpo/dsWefXC0sTAvXgcanp6w=; b=A89+cN3ZJVVXLjzZ1l6S6/IKk7+BYdmrafYM6hDazL+S1faji6FpZ4ieCSP4QouC28BaVB 1M0kaX4Q7lVn5jYU5NsO1XF0tXxjSgCxNoBvFaswemvh5hFtMGUXE0/U7d9MTCILCgt4Pe uha7cdQzYgYx3MizDkuCWn84pHgXYT8= 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-62-4vqw-M50OOqPm7vL5KfHpA-1; Mon, 31 Aug 2026 23:13:24 -0400 X-MC-Unique: 4vqw-M50OOqPm7vL5KfHpA-1 X-Mimecast-MFC-AGG-ID: 4vqw-M50OOqPm7vL5KfHpA_1788232401 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 62DD1185FBE9; Tue, 1 Sep 2026 03:13:21 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E45CF18005B8; Tue, 1 Sep 2026 03:13: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, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 10/14] mips: move has_transparent_hugepage() out of THP guard Date: Mon, 31 Aug 2026 23:12:14 -0400 Message-ID: <371e2d3a7bcac265ac748ad3c67b74abfa238422.1788232334.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" A future commit will introduce a kernel API to allow for checking if the CPU supports PMD-sized pages. This API will be based on the has_transparent_hugepage() implementation but will be orthogonal to THP and therefore must work when CONFIG_TRANSPARENT_HUGEPAGE=3Dn. Move its definition out of the THP guard. Signed-off-by: Luiz Capitulino --- arch/mips/include/asm/pgtable.h | 6 +++--- arch/mips/mm/tlb-r4k.c | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtabl= e.h index fa7b935f947c..b038da872ec6 100644 --- a/arch/mips/include/asm/pgtable.h +++ b/arch/mips/include/asm/pgtable.h @@ -615,9 +615,6 @@ 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); - static inline int pmd_trans_huge(pmd_t pmd) { return !!(pmd_val(pmd) & _PAGE_HUGE); @@ -743,6 +740,9 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_s= truct *mm, =20 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 +#define has_transparent_hugepage has_transparent_hugepage +extern int has_transparent_hugepage(void); + #ifdef _PAGE_HUGE #define pmd_leaf(pmd) ((pmd_val(pmd) & _PAGE_HUGE) !=3D 0) #define pud_leaf(pud) ((pud_val(pud) & _PAGE_HUGE) !=3D 0) diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c index 24fe85fa169d..f4e369342a56 100644 --- a/arch/mips/mm/tlb-r4k.c +++ b/arch/mips/mm/tlb-r4k.c @@ -432,8 +432,6 @@ void add_wired_entry(unsigned long entrylo0, unsigned l= ong entrylo1, #endif } =20 -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - int has_transparent_hugepage(void) { static unsigned int mask =3D -1; @@ -452,8 +450,6 @@ int has_transparent_hugepage(void) } EXPORT_SYMBOL(has_transparent_hugepage); =20 -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ - /* * Used for loading TLB entries before trap_init() has started, when we * don't actually want to add a wired entry which remains throughout the --=20 2.55.0 From nobody Sat Sep 26 13:46:40 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 E4A8543CE6D for ; Tue, 1 Sep 2026 03:13:35 +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=1788232417; cv=none; b=IWXUtAQf1riw32EZOlB7QdO9TIjN4fwuf4cwjQyCqgzkBwHKpAS4I1LNFKs0nYh/rqmO8jJe1OXLFG975U2bHH32+Tn0lgVz1wV/LxbOBqgA6qlA/GI11IO9tT1ZFSNGffg8hM6TXQdpz4yA+c0xOAkhfmOSmaqz3Q//dWbEKgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232417; c=relaxed/simple; bh=I8WGTvPwl2HscdcJoioO7N/lpxfcyBoZaYt1p7RXZHU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kgMOI2ZBtdi1uVYKHXSx8kkIdcsoFVZGXI484nno3ERk6AxWDptg+P86WDiqacayxHu3PoVYMA2ESzk3AIQ7mblLvE33h6xOCi23f0EvgTEqhNFWrmLevzlViSiKQH7vQt3NaOnuqCRPlFC3cO7IluGwcq3lYS9N8nK5bhSkiec= 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=KnVKuh8M; 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="KnVKuh8M" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232415; 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=TIfvMfZyaWvl4SXEvl5wZrxucNW79v3GPJFsRYX4w4M=; b=KnVKuh8MOInTCpYSQmhGx04j/C+hQXgfVv8djuTmxmG7ej3LXm5+S/sMs4j0KPYMNYdx1+ oD4V33VrP40x6u1BZ2TIGvsI9nl5djn14OlIpR1AKhz6A7VYZsYnjERs9EnsWoRP9EmP2J 4tC6HpBZT/tQTMP9biIZ3KKTzUXp7ZI= 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-528-kyslgUdCMcmyuoL2_hzZ4A-1; Mon, 31 Aug 2026 23:13:28 -0400 X-MC-Unique: kyslgUdCMcmyuoL2_hzZ4A-1 X-Mimecast-MFC-AGG-ID: kyslgUdCMcmyuoL2_hzZ4A_1788232405 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 178AD192E255; Tue, 1 Sep 2026 03:13:25 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9944518005B7; Tue, 1 Sep 2026 03:13:21 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 11/14] x86: move has_transparent_hugepage() out of THP guard Date: Mon, 31 Aug 2026 23:12:15 -0400 Message-ID: <9f8cc58ebe0f8365952e2c528f547e1321e1a23d.1788232334.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" A future commit will introduce a kernel API to allow for checking if the CPU supports PMD-sized pages. This API will be based on the has_transparent_hugepage() implementation but will be orthogonal to THP and therefore must work when CONFIG_TRANSPARENT_HUGEPAGE=3Dn. Move its definition out of the THP guard. Signed-off-by: Luiz Capitulino --- arch/x86/include/asm/pgtable.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index d5f4917c1edc..f207e5268918 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -306,12 +306,6 @@ 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) -{ - return boot_cpu_has(X86_FEATURE_PSE); -} - #ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP static inline bool pmd_special(pmd_t pmd) { @@ -337,6 +331,12 @@ static inline pud_t pud_mkspecial(pud_t pud) #endif /* CONFIG_ARCH_SUPPORTS_PUD_PFNMAP */ #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 +#define has_transparent_hugepage has_transparent_hugepage +static inline int has_transparent_hugepage(void) +{ + return boot_cpu_has(X86_FEATURE_PSE); +} + static inline pte_t pte_set_flags(pte_t pte, pteval_t set) { pteval_t v =3D native_pte_val(pte); --=20 2.55.0 From nobody Sat Sep 26 13:46:40 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 38CBA43DA20 for ; Tue, 1 Sep 2026 03:13:35 +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=1788232417; cv=none; b=gNzloJflcKbH2KjmeMnffbZq8v1x5LvvEnSmB/oUJ3/Df8W7WOqTt2d3PPydgoV+zY0a6GhSy5gQCptWT33zr65Sv0IEMyMAD7elfz8uiVHxYkbrIJTwBIuSwI/ijGegAQ+RWP/bQGVtp1nN3v/5iUIz2tVz010UEwMZgtI1Cbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232417; c=relaxed/simple; bh=1t1Laf4IvmKFdr5rUzpdHJwZjlsVlUYJYO/wAHzl0Fs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FbZo5l9rjQDiXyxh5GOmDEV5UxgGcRursyVnpu7OqIcjpwJv9YyJHAFGFwCTEj4idvQkqkLXa1LsgNAI8cFMquczDTz30EiN6taoiD/rG6ZRTqV/AOZtBVilSmum2TEOvEzlxA5shhxyOtj3yBod3sxVGbofACgL62TxExFAYLo= 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=Sp8gItB1; 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="Sp8gItB1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232414; 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=KHn9TD6sOT1RAi8FF05petGcyHv8TIvSIsX6lDHGiZs=; b=Sp8gItB1OcmMhHbgaIp00ascs7uO7HnkhPhMFoqkoaeCFhr+wQxtoWNAr8upbonFi6JVdl q8hFb/Pdldh2k2uIuayNvOHKxwoXenENY0xcsUtjL2Hbb9n3QSny3UkR6b9whuhLwtovCV 4QwaAU/1U0EAMDU+BQNBDeQSjvlGoYA= 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-255-rHF_4iuPM1ObqYEwEMvJhw-1; Mon, 31 Aug 2026 23:13:31 -0400 X-MC-Unique: rHF_4iuPM1ObqYEwEMvJhw-1 X-Mimecast-MFC-AGG-ID: rHF_4iuPM1ObqYEwEMvJhw_1788232408 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 BAA10192E266; Tue, 1 Sep 2026 03:13:28 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4D27018005B7; Tue, 1 Sep 2026 03:13:25 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 12/14] treewide: introduce arch_has_pmd_leaves() Date: Mon, 31 Aug 2026 23:12:16 -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" 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 pgtable_leaf_support_init(). 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 b038da872ec6..2a0a7ddf8bee 100644 --- a/arch/mips/include/asm/pgtable.h +++ b/arch/mips/include/asm/pgtable.h @@ -740,8 +740,8 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_s= truct *mm, =20 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =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 #ifdef _PAGE_HUGE #define pmd_leaf(pmd) ((pmd_val(pmd) & _PAGE_HUGE) !=3D 0) diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c index f4e369342a56..9339ebb0815f 100644 --- a/arch/mips/mm/tlb-r4k.c +++ b/arch/mips/mm/tlb-r4k.c @@ -432,7 +432,7 @@ void add_wired_entry(unsigned long entrylo0, unsigned l= ong entrylo1, #endif } =20 -int has_transparent_hugepage(void) +int arch_has_pmd_leaves(void) { static unsigned int mask =3D -1; =20 @@ -448,7 +448,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 /* * Used for loading TLB entries before trap_init() has started, when we diff --git a/arch/powerpc/include/asm/book3s/64/hash-4k.h b/arch/powerpc/in= clude/asm/book3s/64/hash-4k.h index 79511e6abfca..d532e3f0dfc3 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-4k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-4k.h @@ -167,7 +167,7 @@ extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_st= ruct *mm, unsigned long addr, pmd_t *pmdp); #endif =20 -extern int hash__has_transparent_hugepage(void); +extern int hash__arch_has_pmd_leaves(void); #endif /* !__ASSEMBLER__ */ =20 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */ diff --git a/arch/powerpc/include/asm/book3s/64/hash-64k.h b/arch/powerpc/i= nclude/asm/book3s/64/hash-64k.h index a4a44a112ff9..d523c80f44f7 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-64k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-64k.h @@ -280,7 +280,7 @@ extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_st= ruct *mm, unsigned long addr, pmd_t *pmdp); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 -extern int hash__has_transparent_hugepage(void); +extern int hash__arch_has_pmd_leaves(void); #endif /* __ASSEMBLER__ */ =20 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */ diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/asm/book3s/64/pgtable.h index 2a795f6d9263..41166d44fa75 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -1432,14 +1432,14 @@ static inline bool arch_needs_pgtable_deposit(void) =20 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =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 #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION pte_t ptep_modify_prot_start(struct vm_area_struct *, unsigned long, pte_t= *); diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/incl= ude/asm/book3s/64/radix.h index 50545cf519bd..e8b74528953f 100644 --- a/arch/powerpc/include/asm/book3s/64/radix.h +++ b/arch/powerpc/include/asm/book3s/64/radix.h @@ -307,7 +307,7 @@ static inline int radix__has_transparent_pud_hugepage(v= oid) } #endif =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 50316f3fc5d3..a67bc1723404 100644 --- a/arch/powerpc/mm/book3s64/hash_pgtable.c +++ b/arch/powerpc/mm/book3s64/hash_pgtable.c @@ -393,7 +393,7 @@ pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *m= m, =20 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 -int hash__has_transparent_hugepage(void) +int hash__arch_has_pmd_leaves(void) { =20 if (!mmu_has_feature(MMU_FTR_16M_PAGE)) @@ -422,7 +422,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 #ifdef CONFIG_STRICT_KERNEL_RWX =20 diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtabl= e.h index 5aa8f621df04..24ee90c7e9bf 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1827,8 +1827,8 @@ static inline int pmd_trans_huge(pmd_t pmd) } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =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 f207e5268918..17b060184b1d 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -331,8 +331,8 @@ static inline pud_t pud_mkspecial(pud_t pud) #endif /* CONFIG_ARCH_SUPPORTS_PUD_PFNMAP */ #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =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 4c00cf53e183..98b0a8759ab1 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2344,8 +2344,8 @@ static inline void __init pgtable_leaf_support_init(v= oid) { } #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 54494c3fa983..469d98e01b5f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1095,7 +1095,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 69ab1bb54853..ed5029745dfb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -169,7 +169,7 @@ EXPORT_SYMBOL(__arch_has_pmd_leaves_key); =20 void __init pgtable_leaf_support_init(void) { - if (!has_transparent_hugepage()) + if (!arch_has_pmd_leaves()) static_branch_disable(&__arch_has_pmd_leaves_key); } =20 --=20 2.55.0 From nobody Sat Sep 26 13:46:40 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 528AD43E09D for ; Tue, 1 Sep 2026 03:13:39 +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=1788232420; cv=none; b=YPvIfe7+DuhDjugEPwZXckqrTvt7wSeu+XmwqJO+etM9cQiluLVHlFSxDzHTILTrOAS06WbA/f2Nr6DArrtDr/IFVuVGUSEDi3+A0e5lilHHMyEedJVcfTMQTO/bR1SfQrSc3x83qPGOre7Ly+Edgi3NlYPOSTgyrCd7MagZTlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232420; c=relaxed/simple; bh=+bd2H53wRi6FQqvBoWH4vwhxT8wG1AQb/PQyQULszOc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MOigNE+JL3VCXHcAHjLWsJ8uGqK73cePkKAafT9GEDiYZXZVcCdDw7hmPu7VloDrGQ2hCu7gd7ZYjqNK4bWhM/3PHJoAc/f0McRvyLrGf2H9CC4s66SvaRXZKQtO8tpCV/4Bn1ZTfqiwOH8UmVgjpwL4djBM5jokSjd/mRoPgH4= 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=ifWJ76o6; 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="ifWJ76o6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232418; 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=FfgDDE8CEmW1Q+z8UseKVnUMAM5pqEP/DOHTfkRU7Ug=; b=ifWJ76o6kK2ZpC6YgqJb7r+zxm0NGrk4oXQyke23mK/WJqKAxr485ieMoBvfaYmYUxOBVP P7+woRaIPGG1DdIumiGKvlnUqY3pNhieJI6YLNj5G/B3rvJoyZDgLa0doyU86+9PbhNLnT UUCz276Rkt9PnTYEpi/Ygwm5mp41iAo= 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-241-6imlDJqgPaWD4O50xf4G0g-1; Mon, 31 Aug 2026 23:13:36 -0400 X-MC-Unique: 6imlDJqgPaWD4O50xf4G0g-1 X-Mimecast-MFC-AGG-ID: 6imlDJqgPaWD4O50xf4G0g_1788232412 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 75CD218345AD; Tue, 1 Sep 2026 03:13:32 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EF52518005B8; Tue, 1 Sep 2026 03:13:28 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 13/14] mm: replace thp_disabled_by_hw() with pgtable_has_pmd_leaves() Date: Mon, 31 Aug 2026 23:12:17 -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 Acked-by: David Hildenbrand (Arm) Signed-off-by: Luiz Capitulino --- 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 c745f7ad2298..525acea2eb59 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, @@ -383,12 +382,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_vmaflags(struct file *filp, unsigned l= ong addr, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 469d98e01b5f..d5e65cac6a16 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -204,7 +204,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. */ @@ -1095,10 +1095,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 ed5029745dfb..6be55fc39383 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5611,7 +5611,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 c285cb7fd32e..73281fa060ed 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2047,7 +2047,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.55.0 From nobody Sat Sep 26 13:46:40 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 DE2E43A544A for ; Tue, 1 Sep 2026 03:13:45 +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=1788232427; cv=none; b=nEovhQrbkEV30m5R+Et190Kou4MQZ1kSUEoQSDhbEs063QfCssiWOvReoziiV92dGURDUluT9gMFT93gj+1Cfs5RhaKqqw7G2W64EmcstkfeJ93Bml/g0FqAJf4C7LW9g7kucoVM4egnwPFsNYA1unZXkW9EoiwerWb8foEmyH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788232427; c=relaxed/simple; bh=tTjXIud/4VC6otlwGg2HYuKjR6W6KHJUUFq4tisWxmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eKoDgvTgj42v62ZDDu5OAeCJ4IHDTyYLXm8MVYyuOYZCLdDDjOtNZJShoAk6dJTl7Bd8mWo0HHysaC8pZLt/mjRfDTRvvXusQxsICLUfj8TVKArp7aZ0OKlTox2s6BDHOsJYIP2dmmYborlyT+lxij2hJ9Is4mgQfZa2DO5zmE4= 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=jJeqpZeh; 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="jJeqpZeh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788232424; 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=0OpWaOvwdnfJBr1Jj4YAaiCB/uPhe5itjUn7qv1f4qI=; b=jJeqpZehT/7+4HQOkOkb9KhdYeiol1aC10BoWJEajMUmCxXfhv+lCVmUDZwNtvHX7SViow nBO2O5I0J1QlhDmronBtv2mFZKTW820vhJi3CTT7+ce/pdSP6JUajCCj6dneiWymTQIcyK tRtPd5W0s9BwQISwr9WaM9VwrOE/xgs= 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-684-X8UupBHrPEWy_Dsv-WJmlA-1; Mon, 31 Aug 2026 23:13:39 -0400 X-MC-Unique: X8UupBHrPEWy_Dsv-WJmlA-1 X-Mimecast-MFC-AGG-ID: X8UupBHrPEWy_Dsv-WJmlA_1788232416 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 25377184B397; Tue, 1 Sep 2026 03:13:36 +0000 (UTC) Received: from fedora.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC66718005B7; Tue, 1 Sep 2026 03:13:32 +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, 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, dev.jain@arm.com, usama.arif@linux.dev Subject: [PATCH v7 14/14] mm: thp: always enable mTHP support Date: Mon, 31 Aug 2026 23:12:18 -0400 Message-ID: <0d7adcd340c1703b5eda63bd001537242cee7822.1788232334.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" 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 Reviewed-by: Baolin Wang Signed-off-by: Luiz Capitulino --- mm/huge_memory.c | 25 ++++++++++++++++++++----- mm/shmem.c | 14 +++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d5e65cac6a16..95b2191174fc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -197,6 +197,15 @@ 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()) { + /* + * If the CPU does not support PMD leaves, assume for + * now that it does not support PUD leaves and disable + * both folio orders. + */ + supported_orders &=3D ~(BIT(PMD_ORDER) | BIT(PUD_ORDER)); + } + orders &=3D supported_orders; if (!orders) return 0; @@ -204,7 +213,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. */ @@ -984,7 +993,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= ); @@ -1006,6 +1015,15 @@ 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()) { + /* + * If the CPU does not support PMD leaves, assume for + * now that it does not support PUD leaves and disable + * both folio orders. + */ + orders &=3D ~(BIT(PMD_ORDER) | BIT(PUD_ORDER)); + } + order =3D highest_order(orders); while (orders) { thpsize =3D thpsize_create(order, *hugepage_kobj); @@ -1095,9 +1113,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 73281fa060ed..163e7dc4b2a8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2045,16 +2045,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, disabled_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()) + disabled_orders =3D BIT(PMD_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 & ~disabled_orders; =20 /* * Following the 'deny' semantics of the top level, force the huge @@ -2068,7 +2071,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) & ~disabled_orders; =20 /* Allow mTHP that will be fully within i_size. */ mask |=3D shmem_get_orders_within_size(inode, within_size_orders, index, = 0); @@ -2079,6 +2082,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 ~disabled_orders; return THP_ORDERS_ALL_FILE_DEFAULT & mask; } =20 @@ -5626,7 +5630,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.55.0