From nobody Mon Feb 9 13:01:31 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 58A8A338598 for ; Thu, 22 Jan 2026 19:32:05 +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=1769110330; cv=none; b=j7YrNnD0/4uLRyleEm4aFbDDRWt2ytqLQyQrL55BPicYi4NX+UG96MhwGM6o0dqpAw/+SLxEZ0kedo/Xn/q90V1FslNmH/Z2MAAsfNYNjAv36neLKPGPkhtXtgB13TkYAnrRryNd7Dl3ZQKROvdL4L3ly8xrKi9OOCIyU0SJWXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769110330; c=relaxed/simple; bh=azOv5STgEDWoVyw7ccF/Gi8CrPdfJA7BrU5usD4yZFY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oxrZPe0AA24AOVpkU877J/zHlGIYPslKcGLiHB3n6PtOlUVMgrUeIE+WuOrQ2zyO0YfobKTAZ7mtOwibDfS+zBJq7XCi+mL0UTUe42eIA5/nzWaUv5ZbNfF9ii18Na9glXaSWoD474oN5PefbbSis+jO/hQWUjfjx+YG7zJu+v8= 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=BR+RXfFN; 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="BR+RXfFN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769110323; 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=DhNYD18mHUxoOlYpRtufX5ZWTVzzqP6thRPGOk33sQs=; b=BR+RXfFNKDgbGQqL1+D6oTTZB6PsNu3HgSiKs2aOFp+2yFwIT3FlpJItCyn5tgWTuB8xrt mKDsmu1ZaGFWxFyXwe5pVOtxZylRB/WqC7cylGOHWdPzy08Un5wjqF8pbEQEEhNiqm3obI UeHAzW+AVr7pMKC+Dk25etIUSRHDQv4= 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-541-NR6RFnyGMBWgL6P3t7tb1g-1; Thu, 22 Jan 2026 14:32:02 -0500 X-MC-Unique: NR6RFnyGMBWgL6P3t7tb1g-1 X-Mimecast-MFC-AGG-ID: NR6RFnyGMBWgL6P3t7tb1g_1769110321 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 94C2618005B6; Thu, 22 Jan 2026 19:32:01 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.88.59]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 872C61958DC1; Thu, 22 Jan 2026 19:31:51 +0000 (UTC) From: Nico Pache To: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: npache@redhat.com, akpm@linux-foundation.org, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, jannh@google.com, pfalcato@suse.de, jackmanb@google.com, hannes@cmpxchg.org, willy@infradead.org, peterx@redhat.com, wangkefeng.wang@huawei.com, usamaarif642@gmail.com, sunnanyong@huawei.com, vishal.moola@gmail.com, thomas.hellstrom@linux.intel.com, yang@os.amperecomputing.com, kas@kernel.org, aarcange@redhat.com, raquini@redhat.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, tiwai@suse.de, will@kernel.org, dave.hansen@linux.intel.com, jack@suse.cz, cl@gentwo.org, jglisse@google.com, zokeefe@google.com, rientjes@google.com, rdunlap@infradead.org, hughd@google.com, richard.weiyang@gmail.com Subject: [PATCH mm-unstable v14 12/16] khugepaged: introduce collapse_allowable_orders helper function Date: Thu, 22 Jan 2026 12:28:37 -0700 Message-ID: <20260122192841.128719-13-npache@redhat.com> In-Reply-To: <20260122192841.128719-1-npache@redhat.com> References: <20260122192841.128719-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.12 Content-Type: text/plain; charset="utf-8" Add collapse_allowable_orders() to generalize THP order eligibility. The function determines which THP orders are permitted based on collapse context (khugepaged vs madv_collapse). This consolidates collapse configuration logic and provides a clean interface for future mTHP collapse support where the orders may be different. Reviewed-by: Baolin Wang Signed-off-by: Nico Pache --- mm/khugepaged.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index e33b2594949d..11eedd261285 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -498,12 +498,22 @@ static unsigned int collapse_max_ptes_none(unsigned i= nt order, bool full_scan) return -EINVAL; } =20 +/* Check what orders are allowed based on the vma and collapse type */ +static unsigned long collapse_allowable_orders(struct vm_area_struct *vma, + vm_flags_t vm_flags, bool is_khugepaged) +{ + enum tva_type tva_flags =3D is_khugepaged ? TVA_KHUGEPAGED : TVA_FORCED_C= OLLAPSE; + unsigned long orders =3D BIT(HPAGE_PMD_ORDER); + + return thp_vma_allowable_orders(vma, vm_flags, tva_flags, orders); +} + void khugepaged_enter_vma(struct vm_area_struct *vma, vm_flags_t vm_flags) { if (!mm_flags_test(MMF_VM_HUGEPAGE, vma->vm_mm) && hugepage_pmd_enabled()) { - if (thp_vma_allowable_order(vma, vm_flags, TVA_KHUGEPAGED, PMD_ORDER)) + if (collapse_allowable_orders(vma, vm_flags, /*is_khugepaged=3D*/true)) __khugepaged_enter(vma->vm_mm); } } @@ -2610,7 +2620,7 @@ static unsigned int collapse_scan_mm_slot(unsigned in= t pages, enum scan_result * progress++; break; } - if (!thp_vma_allowable_order(vma, vma->vm_flags, TVA_KHUGEPAGED, PMD_ORD= ER)) { + if (!collapse_allowable_orders(vma, vma->vm_flags, /*is_khugepaged=3D*/t= rue)) { progress++; continue; } @@ -2920,7 +2930,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsi= gned long start, BUG_ON(vma->vm_start > start); BUG_ON(vma->vm_end < end); =20 - if (!thp_vma_allowable_order(vma, vma->vm_flags, TVA_FORCED_COLLAPSE, PMD= _ORDER)) + if (!collapse_allowable_orders(vma, vma->vm_flags, /*is_khugepaged=3D*/fa= lse)) return -EINVAL; =20 cc =3D kmalloc(sizeof(*cc), GFP_KERNEL); --=20 2.52.0