From nobody Thu Apr 9 10:30:36 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 007C23DB636 for ; Wed, 8 Apr 2026 20:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775680747; cv=none; b=nH9sPL5nDnwOaf0hf35LqY2o+eQ2cQxtpSL6unDEuyXErq29K8m+XhIVmIjawyciRXuZfqWDR8euWaReX/zc9AVMJm4bGZxQT6XIgoK+zpoE4Ld66ad15I0gOcz1sKyS4bTNfux/BARhShqhtXtt4OeQhG2RrAWesTDXpBPyE2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775680747; c=relaxed/simple; bh=L/bRT1T8vdtz6U6KXcEidtC0So3piDUr9vzBhuqebrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jMv/eVGEUcjvVREoV1InTSYd5WtcBvlbGVk7ym1NIsVK9U0avN9x5OSro/4UYN1SOytZUyIkI5tn2iz+MvFdgii+18txjb3Hza5vi37VQPbUWR9UbAAD5EZsnftzR2VAW9Yp9WBiB31FjyA2BI4MWpyUPp7KeCfDiw4WvunbSYA= 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=fC3BS80n; 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="fC3BS80n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775680745; 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=q5DLMjRaVolqsbGTCRhcQShr1myO/MYUO5PjIwdLZWU=; b=fC3BS80nLtShmP5QT1BAFImZwcwCWINw4jnO7Rp0rySUthawzsHQrNFwvU0PGiDVStAf0c 1dYf8iC57HW0CWjlAx5c0He4Q8/Ikr9zNrtxKFB5hIRWyXUlQmwU2gpEMck5s6J5/XpLDP jDI4ZD2ICF1xnaKarYwlrqtd2FCzfcE= 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-393-9S6wRMOHNjqFBwrQOGi0LQ-1; Wed, 08 Apr 2026 16:23:28 -0400 X-MC-Unique: 9S6wRMOHNjqFBwrQOGi0LQ-1 X-Mimecast-MFC-AGG-ID: 9S6wRMOHNjqFBwrQOGi0LQ_1775679807 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 17F7F18005B6; Wed, 8 Apr 2026 20:23:27 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.88.140]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE09C180075B; Wed, 8 Apr 2026 20:23:25 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org, baolin.wang@linux.alibaba.com Cc: ryan.roberts@arm.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com Subject: [PATCH v3 08/10] mm: replace thp_disabled_by_hw() with pgtable_has_pmd_leaves() Date: Wed, 8 Apr 2026 16:23:03 -0400 Message-ID: <9432a2398caef7261ca44355fb7b786bb20bc15e.1775679721.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" 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. 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 a4d9f964dfde..e291a650b10f 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -47,7 +47,6 @@ vm_fault_t vmf_insert_folio_pud(struct vm_fault *vmf, str= uct folio *folio, bool write); =20 enum transparent_hugepage_flag { - TRANSPARENT_HUGEPAGE_UNSUPPORTED, TRANSPARENT_HUGEPAGE_FLAG, TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, @@ -352,12 +351,6 @@ static inline bool vma_thp_disabled(struct vm_area_str= uct *vma, return mm_flags_test(MMF_DISABLE_THP_EXCEPT_ADVISED, vma->vm_mm); } =20 -static inline bool thp_disabled_by_hw(void) -{ - /* If the hardware/firmware marked hugepage support disabled. */ - return transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTE= D); -} - unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned lo= ng addr, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9e4889d1673f..86e489c0a150 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -125,7 +125,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. */ @@ -908,10 +908,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 87a65f6eabfb..29cb4ea33ba0 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5427,7 +5427,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 6f8b20d77e07..613393eae5a9 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1839,7 +1839,7 @@ unsigned long shmem_allowable_huge_orders(struct inod= e *inode, vm_flags_t vm_flags =3D vma ? vma->vm_flags : 0; unsigned int global_orders; =20 - if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags, shmem= _huge_force))) + if (!pgtable_has_pmd_leaves() || (vma && vma_thp_disabled(vma, vm_flags, = shmem_huge_force))) return 0; =20 global_orders =3D shmem_huge_global_enabled(inode, index, write_end, --=20 2.53.0