From nobody Thu Apr 2 19:00:22 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 7641E3CF023 for ; Wed, 25 Mar 2026 11:41:37 +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=1774438899; cv=none; b=dZPhw/j7GnHSt1nD/kAH7i/19S+lRSJ6BJSL1dLWH4UQqwZZT9ZRZpI7zro/hmvT6eRYQoxAlVieLAi9wGRbX4RO9MQReFJ54Yg1vJCX4B/IYYZAMAWyZ3HRIPxBSVpvtlp2twAybEaTTLB4bAyS4WQoKA7CJeIDDHCm5j3wQng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774438899; c=relaxed/simple; bh=1eALHqoJOe4Zvwy1hgs/2dnGTg+eBCt2cxe+WnID5Pc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PU+mSGxDfCWjJYk5lkYyNBBEHuFAzdPcLxzj+Y0ngRN3eTRke/W1TGAMteoHzacTyyL5GMmP7iB2LRJSNvbKvi597K/skK7IGNSPT6jjbiri/+Kkiz4xUe88OVxzO019KYjQk2asGnDd3UZLdpB/Aj7cTl/tEiRi7uJqZLuJs1Y= 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=KIbfEc9j; 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="KIbfEc9j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774438896; 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=wpAMGReJ5HEw2g+jWb2G48bdmeRb9Igjsn8yjS6J0Rk=; b=KIbfEc9jci0oCkzUWlFUUN78w/ZjeA5hOldki9t1Dcr0qmWv9YVifk+mnv51IIdShpxo8S r3abdjk1ULPWJhXEu0tnt+AEN64D74W23KZAK+NlRZk55AfDs53/QNiP6QU7dlIyZfoxuJ +PP+FffreaeCUvPi6vK3NLWgWv0ZnqQ= 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-687-puJu_D8-Mia6SKWxxej48A-1; Wed, 25 Mar 2026 07:41:33 -0400 X-MC-Unique: puJu_D8-Mia6SKWxxej48A-1 X-Mimecast-MFC-AGG-ID: puJu_D8-Mia6SKWxxej48A_1774438892 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 6826D1800345; Wed, 25 Mar 2026 11:41:32 +0000 (UTC) Received: from p1.redhat.com (unknown [10.2.14.4]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C62E1800576; Wed, 25 Mar 2026 11:41:14 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: aarcange@redhat.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, apopple@nvidia.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, byungchul@sk.com, catalin.marinas@arm.com, cl@gentwo.org, corbet@lwn.net, dave.hansen@linux.intel.com, david@kernel.org, dev.jain@arm.com, gourry@gourry.net, hannes@cmpxchg.org, hughd@google.com, jackmanb@google.com, jack@suse.cz, jannh@google.com, jglisse@google.com, joshua.hahnjy@gmail.com, kas@kernel.org, lance.yang@linux.dev, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, mathieu.desnoyers@efficios.com, matthew.brost@intel.com, mhiramat@kernel.org, mhocko@suse.com, npache@redhat.com, peterx@redhat.com, pfalcato@suse.de, rakie.kim@sk.com, raquini@redhat.com, rdunlap@infradead.org, richard.weiyang@gmail.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, ryan.roberts@arm.com, shivankg@amd.com, sunnanyong@huawei.com, surenb@google.com, thomas.hellstrom@linux.intel.com, tiwai@suse.de, usamaarif642@gmail.com, vbabka@suse.cz, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, will@kernel.org, willy@infradead.org, yang@os.amperecomputing.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, zokeefe@google.com Subject: [PATCH mm-unstable v4 2/5] mm: introduce is_pmd_order helper Date: Wed, 25 Mar 2026 05:40:19 -0600 Message-ID: <20260325114022.444081-3-npache@redhat.com> In-Reply-To: <20260325114022.444081-1-npache@redhat.com> References: <20260325114022.444081-1-npache@redhat.com> 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.111 Content-Type: text/plain; charset="utf-8" In order to add mTHP support to khugepaged, we will often be checking if a given order is (or is not) a PMD order. Some places in the kernel already use this check, so lets create a simple helper function to keep the code clean and readable. Acked-by: David Hildenbrand (Arm) Reviewed-by: Baolin Wang Reviewed-by: Dev Jain Reviewed-by: Wei Yang Reviewed-by: Lance Yang Reviewed-by: Barry Song Reviewed-by: Zi Yan Reviewed-by: Pedro Falcato Reviewed-by: Lorenzo Stoakes Suggested-by: Lorenzo Stoakes Signed-off-by: Nico Pache --- include/linux/huge_mm.h | 5 +++++ mm/huge_memory.c | 2 +- mm/khugepaged.c | 6 +++--- mm/memory.c | 2 +- mm/mempolicy.c | 2 +- mm/page_alloc.c | 4 ++-- mm/shmem.c | 3 +-- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index c8799dca3b60..1258fa37e85b 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -769,6 +769,11 @@ static inline bool pmd_is_huge(pmd_t pmd) } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 +static inline bool is_pmd_order(unsigned int order) +{ + return order =3D=3D HPAGE_PMD_ORDER; +} + static inline int split_folio_to_list_to_order(struct folio *folio, struct list_head *list, int new_order) { diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2833b06d7498..b2a6060b3c20 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4118,7 +4118,7 @@ static int __folio_split(struct folio *folio, unsigne= d int new_order, i_mmap_unlock_read(mapping); out: xas_destroy(&xas); - if (old_order =3D=3D HPAGE_PMD_ORDER) + if (is_pmd_order(old_order)) count_vm_event(!ret ? THP_SPLIT_PAGE : THP_SPLIT_PAGE_FAILED); count_mthp_stat(old_order, !ret ? MTHP_STAT_SPLIT : MTHP_STAT_SPLIT_FAILE= D); return ret; diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6bd7a7c0632a..1f4609761294 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1547,7 +1547,7 @@ static enum scan_result try_collapse_pte_mapped_thp(s= truct mm_struct *mm, unsign if (IS_ERR(folio)) return SCAN_PAGE_NULL; =20 - if (folio_order(folio) !=3D HPAGE_PMD_ORDER) { + if (!is_pmd_order(folio_order(folio))) { result =3D SCAN_PAGE_COMPOUND; goto drop_folio; } @@ -2030,7 +2030,7 @@ static enum scan_result collapse_file(struct mm_struc= t *mm, unsigned long addr, * we locked the first folio, then a THP might be there already. * This will be discovered on the first iteration. */ - if (folio_order(folio) =3D=3D HPAGE_PMD_ORDER) { + if (is_pmd_order(folio_order(folio))) { result =3D SCAN_PTE_MAPPED_HUGEPAGE; goto out_unlock; } @@ -2358,7 +2358,7 @@ static enum scan_result hpage_collapse_scan_file(stru= ct mm_struct *mm, continue; } =20 - if (folio_order(folio) =3D=3D HPAGE_PMD_ORDER) { + if (is_pmd_order(folio_order(folio))) { result =3D SCAN_PTE_MAPPED_HUGEPAGE; /* * PMD-sized THP implies that we can only try diff --git a/mm/memory.c b/mm/memory.c index 6396d32c348a..e44469f9cf65 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5573,7 +5573,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct fo= lio *folio, struct page *pa if (!thp_vma_suitable_order(vma, haddr, PMD_ORDER)) return ret; =20 - if (folio_order(folio) !=3D HPAGE_PMD_ORDER) + if (!is_pmd_order(folio_order(folio))) return ret; page =3D &folio->page; =20 diff --git a/mm/mempolicy.c b/mm/mempolicy.c index ff52fb94ff27..fd08771e2057 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2449,7 +2449,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsig= ned int order, =20 if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && /* filter "hugepage" allocation, unless from alloc_pages() */ - order =3D=3D HPAGE_PMD_ORDER && ilx !=3D NO_INTERLEAVE_INDEX) { + is_pmd_order(order) && ilx !=3D NO_INTERLEAVE_INDEX) { /* * For hugepage allocation and non-interleave policy which * allows the current node (or other explicitly preferred diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 915b6aef55d0..ee81f5c67c18 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -652,7 +652,7 @@ static inline unsigned int order_to_pindex(int migratet= ype, int order) #ifdef CONFIG_TRANSPARENT_HUGEPAGE bool movable; if (order > PAGE_ALLOC_COSTLY_ORDER) { - VM_BUG_ON(order !=3D HPAGE_PMD_ORDER); + VM_BUG_ON(!is_pmd_order(order)); =20 movable =3D migratetype =3D=3D MIGRATE_MOVABLE; =20 @@ -684,7 +684,7 @@ static inline bool pcp_allowed_order(unsigned int order) if (order <=3D PAGE_ALLOC_COSTLY_ORDER) return true; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (order =3D=3D HPAGE_PMD_ORDER) + if (is_pmd_order(order)) return true; #endif return false; diff --git a/mm/shmem.c b/mm/shmem.c index d00044257401..4ecefe02881d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5532,8 +5532,7 @@ static ssize_t thpsize_shmem_enabled_store(struct kob= ject *kobj, spin_unlock(&huge_shmem_orders_lock); } else if (sysfs_streq(buf, "inherit")) { /* Do not override huge allocation policy with non-PMD sized mTHP */ - if (shmem_huge =3D=3D SHMEM_HUGE_FORCE && - order !=3D HPAGE_PMD_ORDER) + if (shmem_huge =3D=3D SHMEM_HUGE_FORCE && !is_pmd_order(order)) return -EINVAL; =20 spin_lock(&huge_shmem_orders_lock); --=20 2.53.0