From nobody Thu Apr 2 18:59:39 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 A342A1F4C8C for ; Thu, 12 Feb 2026 02:19:18 +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=1770862759; cv=none; b=IQRuuWOecHUYCyRW6NIiZkOrk5eQ0AyVlLKHNi8FS0Rp6oAhq5rTKrBq0U/BtUhJFalVQ8W4WhFAzvqYH2adM/ebWKaY4Qo5qfK8apTuIdbQzszNIHZ7CoxJRs2HoIcdk5meGsG1JPD5T5NuRatDGvkOuzwQQtgo0CIlUuHijGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770862759; c=relaxed/simple; bh=rW64OleDM6H1vQ+Tvju5x4ZV6UNoMoBmgOwyiJUV9OM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EVgQ8HMFwuuGYFad1Ues6GBcWogdDuUP60bNl/zcr/AB2p1mxCdDYKyHmJF/X0VZLRo5uuVByKg2iouqG42vUs7ClErazbawoYomnbUe/L8u18dyIn7EaNugSjBjLDjpk4pdbvWh6gAqYxweoxipEdrxw6i2vjEspB8MX1cuXug= 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=QGA8zger; 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="QGA8zger" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770862757; 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=OMwzVZ6Pva3OZZvdMPb7Ru0uN6OFYrizNjTFcvvE/ds=; b=QGA8zgerd3YU9yM+0jo7Ha4W9HSj9yd/5cMFysNqs8Gb/Yedk1Oqxx10Y3FhxL/Vlqf8ev yKhmSSbzUYTAj0g6N5FPcjoXCr3yqBvC2Wx8uBRvQ6gU5smgdPjiuktwKmGkOzxHK5sdQs WjiSY+olwcwDaENoOjw+MrxJPKkCepA= 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-66-6vJplVlWNkmOQ2GM6PEGAg-1; Wed, 11 Feb 2026 21:19:13 -0500 X-MC-Unique: 6vJplVlWNkmOQ2GM6PEGAg-1 X-Mimecast-MFC-AGG-ID: 6vJplVlWNkmOQ2GM6PEGAg_1770862752 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 BF1F818005AD; Thu, 12 Feb 2026 02:19:12 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.91]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8D8B91956053; Thu, 12 Feb 2026 02:19:02 +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 v1 2/5] mm: introduce is_pmd_order helper Date: Wed, 11 Feb 2026 19:18:32 -0700 Message-ID: <20260212021835.17755-3-npache@redhat.com> In-Reply-To: <20260212021835.17755-1-npache@redhat.com> References: <20260212021835.17755-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.0 on 10.30.177.17 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. Reviewed-by: Lorenzo Stoakes Suggested-by: Lorenzo Stoakes Signed-off-by: Nico Pache arches# pick b3ace8be204f # mm/khugepaged: rename hpage_collapse_* to co= llapse_* Acked-by: David Hildenbrand (Arm) Reviewed-by: Barry Song Reviewed-by: Lance Yang Reviewed-by: Pedro Falcato Reviewed-by: Wei Yang Reviewed-by: Zi Yan --- include/linux/huge_mm.h | 5 +++++ mm/huge_memory.c | 2 +- mm/khugepaged.c | 4 ++-- mm/mempolicy.c | 2 +- mm/page_alloc.c | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index a4d9f964dfde..bd7f0e1d8094 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -771,6 +771,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 44ff8a648afd..5eae85818635 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4097,7 +4097,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 fa1e57fd2c46..c362b3b2e08a 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2000,7 +2000,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)) && folio->index =3D=3D start) { /* Maybe PMD-mapped */ result =3D SCAN_PTE_MAPPED_HUGEPAGE; @@ -2329,7 +2329,7 @@ static enum scan_result hpage_collapse_scan_file(stru= ct mm_struct *mm, unsigned continue; } =20 - if (folio_order(folio) =3D=3D HPAGE_PMD_ORDER && + if (is_pmd_order(folio_order(folio)) && folio->index =3D=3D start) { /* Maybe PMD-mapped */ result =3D SCAN_PTE_MAPPED_HUGEPAGE; diff --git a/mm/mempolicy.c b/mm/mempolicy.c index dbd48502ac24..3802e52b01fc 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2450,7 +2450,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 c2e96ac35636..2acf22f97ae5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -719,7 +719,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; --=20 2.53.0