From nobody Fri Sep 25 01:18:33 2026 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 C8BBD3E5A37 for ; Fri, 18 Sep 2026 03:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703939; cv=none; b=iLNI466CCWURv6iVuVwOrMBfgupZ+5e9E05gNWwnNit903QD7k6SWZYb4MJiTyDy7sto72hGsQmnCK1eqamPuuQWjVmzcDp+lduFJ1qY67eA7/x0QVYT3NFFhd92FgSLWXS2P9YImvRsICGRaM78Oa3M14kaewitCAxWmtw1acg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703939; c=relaxed/simple; bh=r8oOrlUxtwTPmq2VuAnFugBWXqKKUTdEyZPKnZeizgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eEjO26RxFhvCeh/QDAUQsqmsgdSNKSkZLxk7bts9UZhfDcJ5UB2uL0UCRXHnynqGoJ9ohzp9X0A8nk1HmhFtImcosZCBYuiGzfMNOSjkj6U7BYm3lfAuvFq9uIxHvUQGt//z+9SfZzJ+1vKDOiuOP9dzTurFiqfAsavkA0klTL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=X4xZ5TU8; arc=none smtp.client-ip=115.124.30.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="X4xZ5TU8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703929; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=NP5OzPya8rOoaZGJQaokuW0ZH+2iZDJtaFBx3BRmKL4=; b=X4xZ5TU8GRODaTfo/CR/IikvwKRzMRXtIgdjvzZldWKLGcgYKF42uJrTaswfjWb9Dm6fmlWyxRCsArcAqDXWd2EfyLW7cN4RDp9gf6LIMKjpQ2rHvpYSX9tYDOH2NaCFkBqtkDu1gPAsM+0mgWUDlCEAqpDRe7hj/kQbUWnlmUA= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9uK4L_1789703928; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9uK4L_1789703928 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:48 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/12] mm: khugepaged: remove outdated comments and check for shmem Date: Fri, 18 Sep 2026 11:58:32 +0800 Message-ID: <12bac4614aa4b37490e92051d484f4f2cb215076.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" After commit eb92d97f7e6a ("Revert 'tmpfs: don't enable large folios if not supported'"), all shmem mounts can support large folios unconditionally, so drop the outdated comments and the check for shmem in collapse_file(). Signed-off-by: Baolin Wang Reviewed-by: Barry Song --- mm/khugepaged.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a3a9e4d93b46..21d75f5b4b4d 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2192,12 +2192,9 @@ static enum scan_result collapse_file(struct mm_stru= ct *mm, unsigned long addr, bool is_shmem =3D shmem_file(file); =20 /* - * MADV_COLLAPSE ignores shmem huge config, so do not check shmem - * - * TODO: once shmem always calls mapping_set_large_folios() on its - * mapping, the shmem check can be removed. + * MADV_COLLAPSE ignores shmem huge config, so do not check shmem. */ - VM_WARN_ON_ONCE(!is_shmem && !mapping_pmd_folio_support(mapping)); + VM_WARN_ON_ONCE(!mapping_pmd_folio_support(mapping)); VM_WARN_ON_ONCE(start & (HPAGE_PMD_NR - 1)); =20 result =3D alloc_charge_folio(&new_folio, mm, cc, HPAGE_PMD_ORDER); --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 A2FEF54705D for ; Fri, 18 Sep 2026 03:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703935; cv=none; b=FiCkiOTVA8Rq2spev2izkEps6cM71YEuzzZc2L/fdO6JsIQZubpJrqGAK18sp6s1/RM4qM2Xk6VvtNFiQ6R1XJGKWH2HU1tSipWK59C7J0vTmGs8NN8GgCX6jmhInJ1Caf7dI8SNtTMKKbTemxK8iWJrXoAESh9QRWMsL123p+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703935; c=relaxed/simple; bh=qHRRxczt8J4eG+g2sOw/jM5GfYGKQK5Jkmn5R9iUIKQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dyPZG4x3g1pZrkbSVNvnEpp0KnLGFc3rD9BvG6V9k+zgX+EUlkTqSgyeYZjqKP/L0Hj5m4jMBE6UwlYWsLztIhacwKKH3voZnzBCFJWS8S5qu5Y62711fbWUqqWJH9V7qMX9VdNcxCkiSNmtSUFcar8xon+/mVdB+MsWCx/uJRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=JeIoQ6cm; arc=none smtp.client-ip=115.124.30.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="JeIoQ6cm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703930; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Gj7KZoF9VTbSXIKMoovF+7EFs6uTwEiek6buK+yA5uo=; b=JeIoQ6cmErZLfOR6mUd6fPoUPJjFWcAsjiHSrYTrC3y7UqTNShVVN+CvatlUACIzk+b4++uNMkQHzMMENLy3BINxVDKYov3v6Crq5x3GWSNmnvnyVHquVg81GoQPDKyOQ/3zHIXsj2AB3ahgOtJQXUiRmFHoS4+0xcwfgHh6UTA= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R881e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9o3aj_1789703928; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9o3aj_1789703928 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:49 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/12] mm: khugepaged: drop the hugepage_madvise() Date: Fri, 18 Sep 2026 11:58:33 +0800 Message-ID: X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" After commit 2fd4e7693674 ("mm: fix incorrect vm_flags usage when checking allowable orders for tmpfs"), hugepage_madvise() no longer calls any khugepaged related functions and only updates the VMA flags. So remove this helper and update the VMA flags directly in madvise_update_vma(), which simplifies the code. Signed-off-by: Baolin Wang Reviewed-by: Barry Song --- include/linux/huge_mm.h | 8 -------- mm/khugepaged.c | 22 ---------------------- mm/madvise.c | 8 +++++--- 3 files changed, 5 insertions(+), 33 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 8ca0fa3be2ac..334c387ad997 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -508,8 +508,6 @@ change_huge_pud(struct mmu_gather *tlb, struct vm_area_= struct *vma, __split_huge_pud(__vma, __pud, __address); \ } while (0) =20 -int hugepage_madvise(struct vm_area_struct *vma, vm_flags_t *vm_flags, - int advice); void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start, unsigned long end, struct vm_area_struct *next); spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma); @@ -707,12 +705,6 @@ static inline bool unmap_huge_pmd_locked(struct vm_are= a_struct *vma, #define split_huge_pud(__vma, __pmd, __address) \ do { } while (0) =20 -static inline int hugepage_madvise(struct vm_area_struct *vma, - vm_flags_t *vm_flags, int advice) -{ - return -EINVAL; -} - static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start, unsigned long end, diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 21d75f5b4b4d..f81ecaaa4890 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -380,28 +380,6 @@ static unsigned int collapse_max_ptes_swap(struct coll= apse_control *cc, return cc->policy.max_ptes_swap; } =20 -int hugepage_madvise(struct vm_area_struct *vma, - vm_flags_t *vm_flags, int advice) -{ - switch (advice) { - case MADV_HUGEPAGE: - *vm_flags &=3D ~VM_NOHUGEPAGE; - *vm_flags |=3D VM_HUGEPAGE; - break; - case MADV_NOHUGEPAGE: - *vm_flags &=3D ~VM_HUGEPAGE; - *vm_flags |=3D VM_NOHUGEPAGE; - /* - * Setting VM_NOHUGEPAGE will prevent khugepaged from scanning - * this vma even if we leave the mm registered in khugepaged if - * it got registered before VM_NOHUGEPAGE was set. - */ - break; - } - - return 0; -} - int __init khugepaged_init(void) { mm_slot_cache =3D KMEM_CACHE(mm_slot, 0); diff --git a/mm/madvise.c b/mm/madvise.c index eb491fa88325..4150f6a8cf64 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1598,10 +1598,12 @@ static int madvise_vma_behavior(struct madvise_beha= vior *madv_behavior) goto out; break; case MADV_HUGEPAGE: + new_flags &=3D ~VM_NOHUGEPAGE; + new_flags |=3D VM_HUGEPAGE; + break; case MADV_NOHUGEPAGE: - error =3D hugepage_madvise(vma, &new_flags, behavior); - if (error) - goto out; + new_flags &=3D ~VM_HUGEPAGE; + new_flags |=3D VM_NOHUGEPAGE; break; case __MADV_SET_ANON_VMA_NAME: /* Only anonymous mappings can be named */ --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (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 F066539A7E1 for ; Fri, 18 Sep 2026 03:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703940; cv=none; b=GcN0PJlHV7TRgGHF9GbS1pvFvuP4+/FVNita8b3GNukLdDTXwMt24pL/ms2jbESENkn2Vuho0WLTQ139jb4qMriuyVWN9RoT3lIoJDQ7j02TFZQenr+ojS/DSRQRvBu2oIm3abqdbq/4MLPPCCt4HpnExPcbU9Z0nQwskkh4clc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703940; c=relaxed/simple; bh=fSWqPj39BvU99lm30j0V+57ezq9vrTzpuqO1OwTYwxY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ki8q4/o1pw6hLVvWzSt3L+SJxXWu1dkKc907PUJ2Kw3aV2w1urngGsqUw6ZimCdxaEJJ+Excc6ppq/HCmn/R4pafHRKMc8crwaqXBlBBrgTKjecGnSg9LuMiFhPW4ghRrMfkQ7ucKbeLKmVD4/sULuYJmpIIiWt3jpggo87wrkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=MEP8E3wW; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="MEP8E3wW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703930; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=aUu5Mif0L8trLz2WDJF44yPBNDrTZZYsfYbfGjVTknY=; b=MEP8E3wWlXjztLtPIsl8JbxvyhNLtI+V/cxef83JweS8ksnVbSZxIQAV+5VbAjVgGYlfkO4WMknhKiOLON00xPR5+YGMVhXyMtXqokOKfaZe5tvU/7VQGWAGXqscuEy+hHfMJWYGJ5oTE0PXLbdAE56as2N93Cy5ppF+7l+r/x4= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9uK4l_1789703929; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9uK4l_1789703929 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:50 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/12] mm: shmem: don't expose 'deny' and 'force' via the kernel command line Date: Fri, 18 Sep 2026 11:58:34 +0800 Message-ID: X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" Based on the previous discussion with Lorenzo[1], the 'deny' and 'force' options are testing-only configurations and shouldn't be exposed via the shmem kernel command line. So drop these debug options from the shmem kernel command line and update the documentation to make this clear. [1] https://lore.kernel.org/all/6e4aae7b-2c71-4109-945c-6481efde3636@linux.= alibaba.com/ Suggested-by: Lorenzo Stoakes (ARM) Signed-off-by: Baolin Wang --- Documentation/admin-guide/mm/transhuge.rst | 4 ++-- mm/shmem.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/adm= in-guide/mm/transhuge.rst index b187d618452f..0a8265d1cb55 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -389,8 +389,8 @@ is not defined within a valid ``thp_anon``, its policy = will default to Similarly to ``transparent_hugepage``, you can control the hugepage allocation policy for the internal shmem mount by using the kernel paramet= er ``transparent_hugepage_shmem=3D``, where ```` is one of the -seven valid policies for shmem (``always``, ``within_size``, ``advise``, -``never``, ``deny``, and ``force``). +four valid policies for shmem (``always``, ``within_size``, ``advise``, +``never``). =20 Similarly to ``transparent_hugepage_shmem``, you can control the default hugepage allocation policy for the tmpfs mount by using the kernel paramet= er diff --git a/mm/shmem.c b/mm/shmem.c index b572c60f2af8..951e922091fe 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -668,7 +668,7 @@ static unsigned int shmem_huge_global_enabled(struct in= ode *inode, pgoff_t index } } =20 -static int shmem_parse_huge(const char *str) +static int shmem_parse_huge(const char *str, bool skip_deny_force) { int huge; =20 @@ -683,9 +683,9 @@ static int shmem_parse_huge(const char *str) huge =3D SHMEM_HUGE_WITHIN_SIZE; else if (!strcmp(str, "advise")) huge =3D SHMEM_HUGE_ADVISE; - else if (!strcmp(str, "deny")) + else if (!strcmp(str, "deny") && !skip_deny_force) huge =3D SHMEM_HUGE_DENY; - else if (!strcmp(str, "force")) + else if (!strcmp(str, "force") && !skip_deny_force) huge =3D SHMEM_HUGE_FORCE; else return -EINVAL; @@ -5680,7 +5680,7 @@ static ssize_t shmem_enabled_store(struct kobject *ko= bj, if (count && tmp[count - 1] =3D=3D '\n') tmp[count - 1] =3D '\0'; =20 - huge =3D shmem_parse_huge(tmp); + huge =3D shmem_parse_huge(tmp, /*skip_deny_force=3D*/false); if (huge =3D=3D -EINVAL) return huge; =20 @@ -5807,7 +5807,7 @@ static int __init setup_transparent_hugepage_shmem(ch= ar *str) { int huge; =20 - huge =3D shmem_parse_huge(str); + huge =3D shmem_parse_huge(str, /*skip_deny_force=3D*/true); if (huge =3D=3D -EINVAL) { pr_warn("transparent_hugepage_shmem=3D cannot parse, ignored\n"); return huge; @@ -5822,7 +5822,7 @@ static int __init setup_transparent_hugepage_tmpfs(ch= ar *str) { int huge; =20 - huge =3D shmem_parse_huge(str); + huge =3D shmem_parse_huge(str, /*skip_deny_force=3D*/true); if (huge < 0) { pr_warn("transparent_hugepage_tmpfs=3D cannot parse, ignored\n"); return huge; --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (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 9D1F93F3290 for ; Fri, 18 Sep 2026 03:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703941; cv=none; b=uRE8vc0V79lvJXrHjEac/VdoAKX4QKnoAGCqOFYc3DGdDYBQwLw+D9jntBQdIPFDu5CHdMwEJjDfzIxbf93d47e6eK+iICW2Y74b7Lc08gcK5a52/0ekPflUHQL4mMMJfYlfGDlYzU4DNGujVysYXr7+V/hF+cGadPmPOzbw7ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703941; c=relaxed/simple; bh=BJPDHa+AFDXkXkBgKnPY0PrNRd1+OCRsjpbumQYFstM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IyVHcd/iuRhRgR/GHuI44V+drNpWmlompP5NV6GMGaysOOUb+s/3qT3QgAe+ME+J0SLgIAfBmdkRKnvzvlxoLFtefVPgcxTZL+TW3AQltMsEhni50slXILJ+bSH0mSKn73tgWN5J1vnZyOXuu4rvwS0j2Xnbl3MYeMcZ0ySpDVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Wu2wlHG1; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Wu2wlHG1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703931; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Uublj1o5v+asXNyk+Uqq0+npYGJId5+xW/omcnk5atg=; b=Wu2wlHG1pjm3PuuhtoRfiBMBkknnALUyiANiy1j/AMwxlSlCCOKcaNaoFmTsW70xBXIxA2dx2XmoZHTpgeWQoSBjlUj6niWqt7gfssFHJOQsS9txREuEuuvJPOWdiIShMXx18xNMgwIfkHZrReZLmtkSbgmMCSys54yzx4N0WKc= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9o3b4_1789703930; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9o3b4_1789703930 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:50 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/12] mm: khugepaged: move cc->scan_file and cc->scan_pgoff assignment into collapse_scan_file() Date: Fri, 18 Sep 2026 11:58:35 +0800 Message-ID: <6c444420195c6a46072fd02553fe468715041753.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" Move the assignment of cc->scan_file and cc->scan_pgoff into collapse_scan_= file(). This simplifies the parameter passing to collapse_scan_file() and cleans up the code in preparation for the upcoming shmem mTHP collapse support. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index f81ecaaa4890..249ee91a66f2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2586,14 +2586,15 @@ static enum scan_result collapse_file(struct mm_str= uct *mm, unsigned long addr, return result; } =20 -static enum scan_result collapse_scan_file(struct mm_struct *mm, - unsigned long addr, struct file *file, pgoff_t start, - struct collapse_control *cc) +static enum scan_result collapse_scan_file(struct vm_area_struct *vma, + unsigned long addr, struct collapse_control *cc) { const unsigned int max_ptes_none =3D collapse_max_ptes_none(cc, NULL, HPA= GE_PMD_ORDER); const unsigned int max_ptes_swap =3D collapse_max_ptes_swap(cc, HPAGE_PMD= _ORDER); + struct file *file =3D vma->vm_file; struct folio *folio =3D NULL; struct address_space *mapping =3D file->f_mapping; + pgoff_t start =3D linear_page_index(vma, addr); XA_STATE(xas, &mapping->i_pages, start); int present, swap; int node =3D NUMA_NO_NODE; @@ -2689,7 +2690,21 @@ static enum scan_result collapse_scan_file(struct mm= _struct *mm, count_vm_event(THP_SCAN_EXCEED_NONE_PTE); } =20 - trace_mm_khugepaged_scan_file(mm, failed_pfn, file, present, swap, + /* + * SCAN_PTE_MAPPED_HUGEPAGE is work too: the page cache already holds + * the PMD folio, and retracting the PTE table is the run's job. + */ + if (result =3D=3D SCAN_SUCCEED || result =3D=3D SCAN_PTE_MAPPED_HUGEPAGE)= { + /* + * A file collapse works on the page cache and never sees a + * VMA, so take what it needs from this one while it is still + * here. + */ + cc->scan_file =3D get_file(file); + cc->scan_pgoff =3D start; + } + + trace_mm_khugepaged_scan_file(vma->vm_mm, failed_pfn, file, present, swap, result); return result; } @@ -2737,9 +2752,6 @@ enum scan_result collapse_scan_pmd(struct vm_area_str= uct *vma, unsigned long addr, struct collapse_control *cc, unsigned long orders) { - enum scan_result result; - pgoff_t pgoff; - mmap_assert_locked(vma->vm_mm); /* Whatever the last scan found has to have been run by now */ collapse_put_scan_file(cc); @@ -2747,22 +2759,7 @@ enum scan_result collapse_scan_pmd(struct vm_area_st= ruct *vma, if (vma_is_anonymous(vma)) return collapse_scan_anon_pmd(vma, addr, cc, orders); =20 - pgoff =3D linear_page_index(vma, addr); - result =3D collapse_scan_file(vma->vm_mm, addr, vma->vm_file, pgoff, cc); - /* - * SCAN_PTE_MAPPED_HUGEPAGE is work too: the page cache already holds - * the PMD folio, and retracting the PTE table is the run's job. - */ - if (result !=3D SCAN_SUCCEED && result !=3D SCAN_PTE_MAPPED_HUGEPAGE) - return result; - - /* - * A file collapse works on the page cache and never sees a VMA, so take - * what it needs from this one while it is still here. - */ - cc->scan_file =3D get_file(vma->vm_file); - cc->scan_pgoff =3D pgoff; - return result; + return collapse_scan_file(vma, addr, cc); } =20 /* --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.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 0F49340DB49 for ; Fri, 18 Sep 2026 03:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703943; cv=none; b=H6wRD3MGoECqp+Yb9didqI+PO1+HlqdtYVIKR7qrhoshdjbWAV98zuSGFbD+QpBWisvCcmrq61vwApEUM2lW+rxCt6WPufHqw+nXLsjKXpUda7WrRIxFzdGn1WUm2CdDv4aiaMRAlPIaXJqQhHI53P/+jm62hKLnfKCMH3MKqAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703943; c=relaxed/simple; bh=t22kCtCu90mhJLe2YH+9tr29Ko8Pvxxghx1jWwrrPGg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCagTI5ZSyDjNT7hE4udjKoB252BpWkeNoDyhrUGjf4BV+LXoc9Nnyw6d/ZHjRiQlClnmVuk6dOd2uWydV4dGHSKqPB7M/iyoa8HUo596tnkabCvVfD5XpfhNgWigIZ7a7rR8WJsKbW1eKyXdVjFK4nIw4+xQCCQjeAb78IQnfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=C6/aKmkx; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="C6/aKmkx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703933; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=aTpaE1iWIra8O6SpviNVFAUm/4Np7UYKQjsgFYl6AbE=; b=C6/aKmkxcgHvjRd70abnrVGgBVn+jFRf5LILzPYAdhPiKlltfx6KzxoIpB9WR1UZmaHlU9GQReY5mZ97Pl8lyadwe2xN872PLTtqTRRinrjrge1C+COaTFrNLBKtGt/NFX8zXtvPGH2ci2Y6RdX3iXEkin8TU4UstcGRvrIlSfY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R421e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9taoO_1789703931; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9taoO_1789703931 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:51 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/12] mm: khugepaged: add max_ptes_none check in collapse_file() Date: Fri, 18 Sep 2026 11:58:36 +0800 Message-ID: <56bd2febf013c88e2fedbd653e7cc5dc12c6bc85.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" Similar to the anonymous folios collapse, we should also check the 'max_ptes_none' when trying to collapse shmem/file folios, which is also intended as preparation for shmem mTHP collapse in the following patches. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 249ee91a66f2..f741dec3acc2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2158,6 +2158,7 @@ static void retract_page_tables(struct address_space = *mapping, pgoff_t pgoff) static enum scan_result collapse_file(struct mm_struct *mm, unsigned long = addr, struct file *file, pgoff_t start, struct collapse_control *cc) { + const unsigned int max_ptes_none =3D collapse_max_ptes_none(cc, NULL, HPA= GE_PMD_ORDER); struct address_space *mapping =3D file->f_mapping; struct page *dst; struct folio *folio, *tmp, *new_folio; @@ -2222,7 +2223,13 @@ static enum scan_result collapse_file(struct mm_stru= ct *mm, unsigned long addr, goto xa_locked; } } - nr_none++; + + if (++nr_none > max_ptes_none) { + result =3D SCAN_EXCEED_NONE_PTE; + count_vm_event(THP_SCAN_EXCEED_NONE_PTE); + goto xa_locked; + } + index++; continue; } --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (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 3E71D41D620 for ; Fri, 18 Sep 2026 03:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703944; cv=none; b=KmyyPhhnyn1tLfF+Bu+4i2qAbBJaHOs34VA2jRt29jdaqv84cmFZbNmxFdM/oyAVE3NmjbQgZQXFUKTdxsQM9eFjWhExT59B5v37wn13bGfEEVBUgboPCxj0zcUU8gi5thqrA8fNXLiv0E7c+zFM0AoUcCKpjuIMAH+jW6qpjY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703944; c=relaxed/simple; bh=b2oBfU7aP9091UrlKPtlDFeBleHx1chQgKv6EZAb7Os=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ALSRXkfeWlGSR9rw38IMvHIfm6QfONZe0JqHoNAmEh/SpiPFSlq10R0vLM6bL0+UNgjbDe3a+K8skDf2qgt/6tqay6GreiTRnlTmgo94fzfHgxCkd7ipCxuSQPPfSatq3MQplGM9bbfIJqtVAMjZWCshgjDz2IGbb+VkM8GrBRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=mPyApdi2; arc=none smtp.client-ip=115.124.30.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="mPyApdi2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703934; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=bFNaStZZHo8Umn9+ZoNiZRjr6gBJxuMv0I9V0qtdSoU=; b=mPyApdi2SjXJQnrqpiSdkvBttqs4qiDuNNStR9g0lzu/B6TLzymRIl5PsMZO16gPP1h67PoFESDeHs2bFVZqeymTjroRZ3a9wCYL67lTXihyv4GZIgCjziBH2t7As+jRnNSE06Lu3PwDpjBqcA+5gd4o5qfgEodi95aMMXmfD/I= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R661e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9taoW_1789703932; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9taoW_1789703932 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:52 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/12] mm: khugepaged: generalize collapse_file() for shmem mTHP support Date: Fri, 18 Sep 2026 11:58:37 +0800 Message-ID: <14cfc6705c6afc487d1b39c2606d13c93bda07f1.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" Generalize the order of the collapse_file() function to support future shmem mTHP collapse. No functional changes in this patch. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index f741dec3acc2..a987d233ec47 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2138,6 +2138,7 @@ static void retract_page_tables(struct address_space = *mapping, pgoff_t pgoff) * @file: file that collapse on * @start: collapse start address * @cc: collapse context and scratchpad + * @order: folio order being collapsed to * * Basic scheme is simple, details are more complex: * - allocate and lock a new huge page; @@ -2156,16 +2157,18 @@ static void retract_page_tables(struct address_spac= e *mapping, pgoff_t pgoff) * + unlock and free huge page; */ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long = addr, - struct file *file, pgoff_t start, struct collapse_control *cc) + struct file *file, pgoff_t start, struct collapse_control *cc, + int order) { - const unsigned int max_ptes_none =3D collapse_max_ptes_none(cc, NULL, HPA= GE_PMD_ORDER); + const unsigned int max_ptes_none =3D collapse_max_ptes_none(cc, NULL, ord= er); struct address_space *mapping =3D file->f_mapping; + const unsigned long nr_pages =3D 1UL << order; struct page *dst; struct folio *folio, *tmp, *new_folio; unsigned long new_pfn =3D -1; - pgoff_t index =3D 0, end =3D start + HPAGE_PMD_NR; + pgoff_t index =3D 0, end =3D start + nr_pages; LIST_HEAD(pagelist); - XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER); + XA_STATE_ORDER(xas, &mapping->i_pages, start, order); enum scan_result result =3D SCAN_SUCCEED; int nr_none =3D 0; bool is_shmem =3D shmem_file(file); @@ -2174,9 +2177,9 @@ static enum scan_result collapse_file(struct mm_struc= t *mm, unsigned long addr, * MADV_COLLAPSE ignores shmem huge config, so do not check shmem. */ VM_WARN_ON_ONCE(!mapping_pmd_folio_support(mapping)); - VM_WARN_ON_ONCE(start & (HPAGE_PMD_NR - 1)); + VM_WARN_ON_ONCE(start & (nr_pages - 1)); =20 - result =3D alloc_charge_folio(&new_folio, mm, cc, HPAGE_PMD_ORDER); + result =3D alloc_charge_folio(&new_folio, mm, cc, order); if (result !=3D SCAN_SUCCEED) goto out; new_pfn =3D folio_pfn(new_folio); @@ -2514,12 +2517,12 @@ static enum scan_result collapse_file(struct mm_str= uct *mm, unsigned long addr, } =20 if (is_shmem) { - lruvec_stat_mod_folio(new_folio, NR_SHMEM, HPAGE_PMD_NR); + lruvec_stat_mod_folio(new_folio, NR_SHMEM, nr_pages); lruvec_stat_mod_folio(new_folio, NR_SHMEM_THPS, HPAGE_PMD_NR); } else { lruvec_stat_mod_folio(new_folio, NR_FILE_THPS, HPAGE_PMD_NR); } - lruvec_stat_mod_folio(new_folio, NR_FILE_PAGES, HPAGE_PMD_NR); + lruvec_stat_mod_folio(new_folio, NR_FILE_PAGES, nr_pages); =20 /* * Mark new_folio as uptodate before inserting it into the @@ -2527,14 +2530,14 @@ static enum scan_result collapse_file(struct mm_str= uct *mm, unsigned long addr, * unwritten page. */ folio_mark_uptodate(new_folio); - folio_ref_add(new_folio, HPAGE_PMD_NR - 1); + folio_ref_add(new_folio, nr_pages - 1); =20 if (is_shmem) folio_mark_dirty(new_folio); folio_add_lru(new_folio); =20 /* Join all the small entries into a single multi-index entry. */ - xas_set_order(&xas, start, HPAGE_PMD_ORDER); + xas_set_order(&xas, start, order); xas_store(&xas, new_folio); WARN_ON_ONCE(xas_error(&xas)); xas_unlock_irq(&xas); @@ -2589,7 +2592,7 @@ static enum scan_result collapse_file(struct mm_struc= t *mm, unsigned long addr, folio_put(new_folio); out: VM_BUG_ON(!list_empty(&pagelist)); - trace_mm_khugepaged_collapse_file(mm, new_pfn, index, addr, is_shmem, fil= e, HPAGE_PMD_NR, result); + trace_mm_khugepaged_collapse_file(mm, new_pfn, index, addr, is_shmem, fil= e, nr_pages, result); return result; } =20 @@ -2796,7 +2799,7 @@ enum scan_result collapse_run_pmd(struct mm_struct *m= m, unsigned long addr, if (result =3D=3D SCAN_PTE_MAPPED_HUGEPAGE) goto retract; retry: - result =3D collapse_file(mm, addr, file, pgoff, cc); + result =3D collapse_file(mm, addr, file, pgoff, cc, HPAGE_PMD_ORDER); =20 /* Dirty pages are worth a writeback and one more try, if asked for */ if (cc->policy.writeback_dirty && result =3D=3D SCAN_PAGE_DIRTY_OR_WRITEB= ACK && --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 A9B6D3E4C94 for ; Fri, 18 Sep 2026 03:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703938; cv=none; b=NI4NGcCMal0sekMnSLtTfisG5iefq3duQdFrNRtAuNdFuAGtJA0Qafr1WW+qEl+iwIivbHXy1w1ndWwG6MGZSL5s+0BxXrrDblHyd2KLlkXc+9bJIS0eSUcJQjauk0INxXo063QxBz1vGp2HpLN+F9JJ1GZurMlylGDZYo/s0Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703938; c=relaxed/simple; bh=+uGabi91fPc2iZkUaNG0TbXcnhEcpURISeL0ADO/qxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D3QjgMaNai0QL6GpYpFosx6JrspHw9zb/hct8xo401cBq44IBX3df8sAAqofTw8l1FxcH1Z9s1GnIiKVJljPAbdfNfBlZD4XWO/TFTApr0bfBElYYVi82J50fW3ybRpQAmrkX8QLucScXeXiErD8CcdQ4ta2Cn6JFFMgqe2Kg3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=TG4D4lbq; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="TG4D4lbq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703934; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=8mmUDsC9rv2Qg56cTGaMzYYkxCmY4QHyGj8J02CULg0=; b=TG4D4lbqOWZ4jnC7P5U/02gc4wY8srbpS1MLMDVaQ4o7bLLdOM+7gpa/wvdPF/NZywKIb8cevkWQ/d0le1gIRc2MrtAuptqaL2jCrEcjXAJIpv5fAX2kjCOI2ea8hsvkbuzvMAL3CFqiwmeS1dersQ9Wzp/QoHtexFkznAMBLUo= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9o3bp_1789703932; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9o3bp_1789703932 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:53 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/12] mm: khugepaged: add an order check for PMD-sized THP statistics Date: Fri, 18 Sep 2026 11:58:38 +0800 Message-ID: <880d5e981b8af49f956cea49074ef6dc553a575a.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" In order to support shmem mTHP collapse in the following patches, add an PMD-sized THP order check to avoid PMD-sized THP statistics errors. No functional changes. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a987d233ec47..6c648ede24c4 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2518,8 +2518,9 @@ static enum scan_result collapse_file(struct mm_struc= t *mm, unsigned long addr, =20 if (is_shmem) { lruvec_stat_mod_folio(new_folio, NR_SHMEM, nr_pages); - lruvec_stat_mod_folio(new_folio, NR_SHMEM_THPS, HPAGE_PMD_NR); - } else { + if (is_pmd_order(order)) + lruvec_stat_mod_folio(new_folio, NR_SHMEM_THPS, HPAGE_PMD_NR); + } else if (is_pmd_order(order)) { lruvec_stat_mod_folio(new_folio, NR_FILE_THPS, HPAGE_PMD_NR); } lruvec_stat_mod_folio(new_folio, NR_FILE_PAGES, nr_pages); --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 753A83EE1E5 for ; Fri, 18 Sep 2026 03:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703939; cv=none; b=jOVxCdN+9NG1yjsGzeASyXNDhqqv4CuTnGe6S3J2DOoFh3iFtxOPaPyNd768fE8QDeRx6GfKPPGqHmNFgTIK+hnvLsbO4W9c4Um0vU9yMcYfIjLBLGysIZfTcU63YsOePHr2CW9rgbNWMdIPlffz4BLaqZqxATufVagzJRUGKMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703939; c=relaxed/simple; bh=V8Rfzzs7GBde0fLUTqjYqNwT4mcz2/NcO59aZ+lqhXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OapI2g3H05xpAD2pZJCq95Fqtnu7GnaYXVFSG1sGjJomGcMINsDU2kPMwPencP0CN6+B1G6GNFxbnAq0HsF9CrOWEbEl0PBi+dngxPcAqY+STRI7o6G4YAIF81bqT6OyT9G02n4nqvrOWgbKOsXWIZiBwMpzTwpRYrkZhIj3+Nw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=eJiNIiVn; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="eJiNIiVn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703934; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=kIKdO5bjBZZP6x4MDEA3rAxUaYok98mp4CY02zuEzqA=; b=eJiNIiVn4n6ersp4SK0Jw3gy2Ai2C3+JXlOjP9M5DpPGhae4hSrQLhfvweA4Ws/VXuP6peQHTs/i6exYtDQPrfbuihWzgY5MnyGSI0DSurjouOB4yqpB5h17yVzcyJfX5/CDMRecHK7vaNTmOzjojxsXtyCXzfnrW9tJqmtkaOQ= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R591e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9tap2_1789703933; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9tap2_1789703933 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:54 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/12] mm: khugepaged: add a helper to get the minimal collapse order Date: Fri, 18 Sep 2026 11:58:39 +0800 Message-ID: <4b97f478b7569014ec52196a17532c4b664b97c1.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" shmem mTHP collapse will need to support order-1 collapse in the future, so add a helper to retrieve the minimal collapse order as a preparation. Also rename KHUGEPAGED_MIN_MTHP_ORDER to KHUGEPAGED_MIN_ANON_MTHP_ORDER for better readability, and add a new COLLAPSE_MIN_FILE_MTHP_ORDER for the shmem minimal collapse order. Signed-off-by: Baolin Wang --- mm/collapse.h | 3 ++- mm/khugepaged.c | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mm/collapse.h b/mm/collapse.h index e52969965262..d2fff6b5e1ec 100644 --- a/mm/collapse.h +++ b/mm/collapse.h @@ -8,7 +8,8 @@ #include =20 #define COLLAPSE_MAX_PTES_LIMIT (HPAGE_PMD_NR - 1) -#define COLLAPSE_MIN_MTHP_ORDER 2 +#define COLLAPSE_MIN_ANON_MTHP_ORDER 2 +#define COLLAPSE_MIN_FILE_MTHP_ORDER 1 =20 enum scan_result { SCAN_FAIL, diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6c648ede24c4..64605a72ac2b 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -302,6 +302,14 @@ static bool pte_none_or_zero(pte_t pte) return pte_present(pte) && is_zero_pfn(pte_pfn(pte)); } =20 +static unsigned int collapse_min_mthp_order(struct file *file) +{ + if (file) + return COLLAPSE_MIN_FILE_MTHP_ORDER; + + return COLLAPSE_MIN_ANON_MTHP_ORDER; +} + /** * collapse_max_ptes_none - Calculate maximum allowed empty PTEs or PTEs m= apping * the shared zeropage for the given collapse operation. @@ -1485,7 +1493,7 @@ static enum scan_result mthp_collapse(struct mm_struc= t *mm, unsigned long addres * any smaller order enabled. When at the smallest order * we must always move to the next offset. */ - if (order > COLLAPSE_MIN_MTHP_ORDER && + if (order > collapse_min_mthp_order(NULL) && (cc->scan_orders & GENMASK(order - 1, 0))) { order--; continue; --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 7CFB354705D for ; Fri, 18 Sep 2026 03:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703940; cv=none; b=F8dAnNfC55YpJLV6URhHTA6Ma3s1Dbv5H/+XtrNqhEyi8E9bXfVQwItXBQ2Vy0t6WQqy6DJ6sZUk0kAOp/h/aBABWvB9aoGjxLWFnKX5lkki8O9TbbLydUC8EWjVKpM3RIk3pe8750bI6pObwdJenPQfILSnery8LMbDh9/78RA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703940; c=relaxed/simple; bh=kV5nodOYBBXhHpLhXDlQndjB5MFGzuNitcOvqrzcyxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CCHQqf5zINC17XkO+RDJ/ktR2vGFzE45UgAS2/D2Ux1QCDvIac+cDCI4IZqZQlcg5i4j8jTotI5gM1vIPgRcZLPKMGxrtF1qzUYCa3BZ1mI1B/LUpr2+VcdXgruBdPEFZjm9mQm+53swyFrF+39W3zIS/Q8SkP75hgKJEcC+7sM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=X+/AthxS; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="X+/AthxS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703936; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=GVLNVVgni+ygI11Mkg6WFcdyrUYsnS6Lm8jx1pX0R4A=; b=X+/AthxSxY0CnTgVwXl7QmtWDHOoZ0zguAWdxSMgpMLy7Y5VHc3ufPztOluMqtNRlHIGGs3W0IqpIVY+2QgMkJBGS08nJESkrXPEBi+hasbYVWVcSDhYIuQqohXnsWCzJXs1/Lq+8+ipfbsL070uMSBSHutk6TIBEjEpeNfEJ+Y= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9uK64_1789703934; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9uK64_1789703934 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:54 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/12] mm: khugepaged: add shmem mTHP collapse support Date: Fri, 18 Sep 2026 11:58:40 +0800 Message-ID: <0bcc8d5e6cc15670c83c643c0f0527138014fe6a.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" Khugepaged already supports the anonymous mTHP collapse. Similarly, let khugepaged also support the shmem mTHP collapse. The strategy for shmem mTHP collapse follows the anonymous mTHP collapse: Track present pages via a bitmap while scanning PMD ranges for collapse candidates. After the scan completes, use the bitmap to determine the most efficient mTHP order to collapse to. Scale 'max_ptes_none' by the attempted collapse order to determine the minimum fill threshold for eligibility. Similarly, shmem mTHP collapse rejects regions containing swapped-out pages to avoid creep. Currently, the collapse_pte_mapped_thp() does not build the mapping for mTH= P. Cause we still expect to establish the mTHP mapping via refault under the control of fault_around. So collapse_pte_mapped_thp() remains responsible only for building the mapping for PMD-sized THP, which is reasonable and makes life easier. Note that we do not need to remove pte page tables for shmem mTHP collapse. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 100 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 19 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 64605a72ac2b..dba747442461 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -84,6 +84,10 @@ static struct khugepaged_scan khugepaged_scan =3D { .mm_head =3D LIST_HEAD_INIT(khugepaged_scan.mm_head), }; =20 +static enum scan_result collapse_file(struct mm_struct *mm, unsigned long = addr, + struct file *file, pgoff_t start, + struct collapse_control *cc, int order); + #ifdef CONFIG_SYSFS static ssize_t scan_sleep_millisecs_show(struct kobject *kobj, struct kobj_attribute *attr, @@ -1452,7 +1456,11 @@ static enum scan_result mthp_collapse(struct mm_stru= ct *mm, unsigned long addres enum scan_result ret; =20 collapse_address =3D address + offset * PAGE_SIZE; - ret =3D collapse_huge_page(mm, collapse_address, cc, order); + if (cc->scan_file) + ret =3D collapse_file(mm, collapse_address, cc->scan_file, + cc->scan_pgoff + offset, cc, order); + else + ret =3D collapse_huge_page(mm, collapse_address, cc, order); =20 switch (ret) { /* Cases where we continue to next collapse candidate */ @@ -1460,6 +1468,13 @@ static enum scan_result mthp_collapse(struct mm_stru= ct *mm, unsigned long addres collapsed +=3D nr_ptes; fallthrough; case SCAN_PTE_MAPPED_HUGEPAGE: + /* + * Return SCAN_PTE_MAPPED_HUGEPAGE to call + * collapse_pte_mapped_thp() if the page cache + * already holds the PMD folio. + */ + if (order =3D=3D HPAGE_PMD_ORDER) + last_result =3D ret; goto next_offset; /* Cases where lower orders might still succeed */ case SCAN_ALLOC_HUGE_PAGE_FAIL: @@ -1493,7 +1508,7 @@ static enum scan_result mthp_collapse(struct mm_struc= t *mm, unsigned long addres * any smaller order enabled. When at the smallest order * we must always move to the next offset. */ - if (order > collapse_min_mthp_order(NULL) && + if (order > collapse_min_mthp_order(cc->scan_file) && (cc->scan_orders & GENMASK(order - 1, 0))) { order--; continue; @@ -2237,7 +2252,8 @@ static enum scan_result collapse_file(struct mm_struc= t *mm, unsigned long addr, =20 if (++nr_none > max_ptes_none) { result =3D SCAN_EXCEED_NONE_PTE; - count_vm_event(THP_SCAN_EXCEED_NONE_PTE); + count_collapse_event(order, THP_SCAN_EXCEED_NONE_PTE, + MTHP_STAT_COLLAPSE_EXCEED_NONE); goto xa_locked; } =20 @@ -2247,6 +2263,19 @@ static enum scan_result collapse_file(struct mm_stru= ct *mm, unsigned long addr, =20 if (xa_is_value(folio) || !folio_test_uptodate(folio)) { xas_unlock_irq(&xas); + + /* + * TODO: Support swapin without leading to further mTHP + * collapses. Currently bringing in new pages via swapin may + * cause a future higher order collapse on a rescan of the same + * range. + */ + if (!is_pmd_order(order)) { + count_mthp_stat(order, MTHP_STAT_COLLAPSE_EXCEED_SWAP); + result =3D SCAN_EXCEED_SWAP_PTE; + goto xa_unlocked; + } + /* swap in or instantiate fallocated page */ if (shmem_get_folio(mapping->host, index, 0, &folio, SGP_NOALLOC)) { @@ -2330,6 +2359,15 @@ static enum scan_result collapse_file(struct mm_stru= ct *mm, unsigned long addr, goto out_unlock; } =20 + /* + * If the folio order is greater than the collapse order, there is + * no need to continue attempting to collapse. + */ + if (folio_order(folio) >=3D order) { + result =3D SCAN_PTE_MAPPED_HUGEPAGE; + goto out_unlock; + } + if (folio_mapping(folio) !=3D mapping) { result =3D SCAN_TRUNCATED; goto out_unlock; @@ -2552,10 +2590,11 @@ static enum scan_result collapse_file(struct mm_str= uct *mm, unsigned long addr, xas_unlock_irq(&xas); =20 /* - * Remove pte page tables, so we can re-fault the page as huge. A - * caller that wants the PMD mapped now is told to go and do that. + * Remove pte page tables for PMD-sized THP collapse, so we can + * re-fault the page as huge. */ - retract_page_tables(mapping, start); + if (is_pmd_order(order)) + retract_page_tables(mapping, start); if (cc->policy.install_pmd) result =3D SCAN_PTE_MAPPED_HUGEPAGE; folio_unlock(new_folio); @@ -2606,10 +2645,11 @@ static enum scan_result collapse_file(struct mm_str= uct *mm, unsigned long addr, } =20 static enum scan_result collapse_scan_file(struct vm_area_struct *vma, - unsigned long addr, struct collapse_control *cc) + unsigned long addr, struct collapse_control *cc, + unsigned long enabled_orders) { - const unsigned int max_ptes_none =3D collapse_max_ptes_none(cc, NULL, HPA= GE_PMD_ORDER); const unsigned int max_ptes_swap =3D collapse_max_ptes_swap(cc, HPAGE_PMD= _ORDER); + unsigned int max_ptes_none =3D collapse_max_ptes_none(cc, NULL, HPAGE_PMD= _ORDER); struct file *file =3D vma->vm_file; struct folio *folio =3D NULL; struct address_space *mapping =3D file->f_mapping; @@ -2619,10 +2659,19 @@ static enum scan_result collapse_scan_file(struct v= m_area_struct *vma, int node =3D NUMA_NO_NODE; enum scan_result result =3D SCAN_SUCCEED; unsigned long failed_pfn =3D -1; + unsigned long nr_pages; + pgoff_t pgoff; =20 present =3D 0; swap =3D 0; collapse_scan_reset(cc); + /* + * If PMD is the only enabled order, enforce max_ptes_none, otherwise + * scan all pages to populate the bitmap for mTHP collapse. + */ + if (enabled_orders !=3D BIT(HPAGE_PMD_ORDER)) + max_ptes_none =3D COLLAPSE_MAX_PTES_LIMIT; + rcu_read_lock(); xas_for_each(&xas, folio, start + HPAGE_PMD_NR - 1) { if (xas_retry(&xas, folio)) @@ -2690,7 +2739,17 @@ static enum scan_result collapse_scan_file(struct vm= _area_struct *vma, * is just too costly... */ =20 - present +=3D folio_nr_pages(folio); + nr_pages =3D folio_nr_pages(folio); + present +=3D nr_pages; + + /* + * If there are folios present, keep track of it in the bitmap + * for file/shmem mTHP collapse. + */ + pgoff =3D max_t(pgoff_t, start, folio->index) - start; + nr_pages =3D min_t(int, HPAGE_PMD_NR - pgoff, nr_pages); + bitmap_set(cc->eligible_ptes, pgoff, nr_pages); + folio_put(folio); =20 if (need_resched()) { @@ -2706,7 +2765,8 @@ static enum scan_result collapse_scan_file(struct vm_= area_struct *vma, =20 if (result =3D=3D SCAN_SUCCEED && present < HPAGE_PMD_NR - max_ptes_none)= { result =3D SCAN_EXCEED_NONE_PTE; - count_vm_event(THP_SCAN_EXCEED_NONE_PTE); + count_collapse_event(HPAGE_PMD_ORDER, THP_SCAN_EXCEED_NONE_PTE, + MTHP_STAT_COLLAPSE_EXCEED_NONE); } =20 /* @@ -2721,6 +2781,8 @@ static enum scan_result collapse_scan_file(struct vm_= area_struct *vma, */ cc->scan_file =3D get_file(file); cc->scan_pgoff =3D start; + cc->scan_orders =3D enabled_orders; + cc->scan_unmapped =3D swap; } =20 trace_mm_khugepaged_scan_file(vma->vm_mm, failed_pfn, file, present, swap, @@ -2778,7 +2840,7 @@ enum scan_result collapse_scan_pmd(struct vm_area_str= uct *vma, if (vma_is_anonymous(vma)) return collapse_scan_anon_pmd(vma, addr, cc, orders); =20 - return collapse_scan_file(vma, addr, cc); + return collapse_scan_file(vma, addr, cc, orders); } =20 /* @@ -2796,23 +2858,21 @@ enum scan_result collapse_run_pmd(struct mm_struct = *mm, unsigned long addr, { struct file *file =3D cc->scan_file; bool triggered_wb =3D false; - pgoff_t pgoff; - - if (!file) - return mthp_collapse(mm, addr, cc); - - cc->scan_file =3D NULL; - pgoff =3D cc->scan_pgoff; =20 /* The scan found the PMD folio in place: nothing to collapse */ if (result =3D=3D SCAN_PTE_MAPPED_HUGEPAGE) goto retract; + retry: - result =3D collapse_file(mm, addr, file, pgoff, cc, HPAGE_PMD_ORDER); + result =3D mthp_collapse(mm, addr, cc); + /* Just return the results for anonymous folio collapse. */ + if (!file) + return result; =20 /* Dirty pages are worth a writeback and one more try, if asked for */ if (cc->policy.writeback_dirty && result =3D=3D SCAN_PAGE_DIRTY_OR_WRITEB= ACK && !triggered_wb && mapping_can_writeback(file->f_mapping)) { + pgoff_t pgoff =3D cc->scan_pgoff; const loff_t lstart =3D (loff_t)pgoff << PAGE_SHIFT; const loff_t lend =3D lstart + HPAGE_PMD_SIZE - 1; =20 @@ -2821,6 +2881,8 @@ enum scan_result collapse_run_pmd(struct mm_struct *m= m, unsigned long addr, goto retry; } retract: + cc->scan_file =3D NULL; + VM_WARN_ON_ONCE(!file); fput(file); =20 /* --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.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 11F8243E074 for ; Fri, 18 Sep 2026 03:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703948; cv=none; b=uybeMfTEYWsGqGV3BCCtO46PR4MTu1sz9ddLF5W8PnLoBz4DJ3hW41Sq9k0GAQdFTYd+wj8DZ1r6VzEwLiLLALCesDj1W+BYYcm/gamOQ4DxZZJi9UtsGRQHI/Je/Gr1F3mt2+Dccp0LjMLBmoS8rKMb7tGzf+bPTHPbfaI/S20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703948; c=relaxed/simple; bh=oTY7ToQKQxWUPqnpGGIaIJGoOnKFr/LL/Ic95Ezpc4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eCukV70tJBC0mtdzqslY48SzzoBdN64kT8bLnauI5Gh042owxPn9KvtFYQdWGBNIwqI7MG+mQdtfdkQBW++C3rth2XZdiwHiaSSr6zD8hUBW20NgoiTP+weeZZlIsRHKgLSj3NiXivnXutJrE9OFlxo+BcfiX0n2dHAUEh32CDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=KFcmzR5k; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="KFcmzR5k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703937; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=0x3dSjlUiTkXS7vb5onP0ckg+vTzpvO3+8JjOPhJO8M=; b=KFcmzR5kQpdstBc3Dq1M/4Qqp0umEOoxwgYuFSUbIQXQkbopP6NeCpzU8qCo8Jk4X1oUgastqj7onW0eTxkDjSgGehvB8pL5wG+dDMyUDr5Sp7I+I7QN/lW7EUOAKdpzLI2JiNwaNdTQ2PfTg4GKoOON4Kiz7umYRDTy5SF3XPQ= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R901e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9o3cX_1789703935; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9o3cX_1789703935 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:55 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/12] mm: shmem: run khugepaged for all shmem mTHP orders Date: Fri, 18 Sep 2026 11:58:41 +0800 Message-ID: <3dee70b589a0190e5e7b5c8b085a7e9da4b27f4a.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" When only non-PMD-sized mTHP is enabled (such as only 64K mTHP enabled), we should also allow kicking khugepaged to attempt scanning and collapsing 64K shmem mTHP. Modify shmem_hpage_pmd_enabled() to support shmem mTHP collapse, and while we are at it, rename it to make the function name more clear. Signed-off-by: Baolin Wang --- include/linux/shmem_fs.h | 4 ++-- mm/khugepaged.c | 2 +- mm/shmem.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index a7c7a96a7cbf..9f2036f58bb8 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -135,7 +135,7 @@ int shmem_unuse(unsigned int type); unsigned long shmem_allowable_huge_orders(struct inode *inode, struct vm_area_struct *vma, pgoff_t index, loff_t write_end, bool shmem_huge_force); -bool shmem_hpage_pmd_enabled(void); +bool shmem_hpage_enabled(void); #else static inline unsigned long shmem_allowable_huge_orders(struct inode *inod= e, struct vm_area_struct *vma, pgoff_t index, @@ -144,7 +144,7 @@ static inline unsigned long shmem_allowable_huge_orders= (struct inode *inode, return 0; } =20 -static inline bool shmem_hpage_pmd_enabled(void) +static inline bool shmem_hpage_enabled(void) { return false; } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index dba747442461..5c477ea16c6f 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -447,7 +447,7 @@ static bool hugepage_enabled(void) return true; if (anon_hpage_enabled()) return true; - if (shmem_hpage_pmd_enabled()) + if (shmem_hpage_enabled()) return true; return false; } diff --git a/mm/shmem.c b/mm/shmem.c index 951e922091fe..6567bd4cdc07 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2018,17 +2018,17 @@ static struct folio *shmem_swapin_cluster(swp_entry= _t swap, gfp_t gfp, } =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE -bool shmem_hpage_pmd_enabled(void) +bool shmem_hpage_enabled(void) { if (shmem_huge =3D=3D SHMEM_HUGE_DENY) return false; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_always)) + if (READ_ONCE(huge_shmem_orders_always)) return true; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_madvise)) + if (READ_ONCE(huge_shmem_orders_madvise)) return true; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_within_size)) + if (READ_ONCE(huge_shmem_orders_within_size)) return true; - if (test_bit(HPAGE_PMD_ORDER, &huge_shmem_orders_inherit) && + if (READ_ONCE(huge_shmem_orders_inherit) && shmem_huge !=3D SHMEM_HUGE_NEVER) return true; =20 --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 DA278409277 for ; Fri, 18 Sep 2026 03:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703943; cv=none; b=AqGqUaeUjwsCL8XO7pv4XzNKhBBluyvyI+OhLfYEU77freUjOXchDJYSANvr+TEveW6URAqNkAqpNpkCiIfkl374tQ5TQmbgrbdw5dDScppc8QweWKXIfI5DcTMNktLFpnqN3eTmuRIkFThuRGZuzH9jDHOxGsQg1NEs5uXFRwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703943; c=relaxed/simple; bh=HGM5KbtDXMkgnjxwXFsXCRlOvC088Gdr9mgccBzOuC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AzMkhngal54oUG+GaOPDRCjcRts6Dn5TNr2DPnGUfgbZpHr6D2YkNdj5mYvjGujSEIoa3NEiWdbeqEdMqp+se7tROhuOssKHEqbjVNMVKIUJ3JMRYkxK6VHnUJ1YeSEW3ZaLuiX5bqTcRRUMzjR9Mri11RPPxVUSTsmeDfhZ6XI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ydKkrnd+; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ydKkrnd+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703938; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=loQVaTQd/RKm32T1IKVgII9zZSimhBFrCIUTGWgc3Hc=; b=ydKkrnd+BCMCU5dNMiP2CsRm1gZMmejq7P7odVf3kKNqBNGJpW8/RP62/ZKPeytWBQYj/ZIve8qu/ctMuIZpF9utqYtaWY9m+aex95kY0lHmXzQQmdH62W3gmQ/u1tTPwluDPjP5bAnc0a7Xs0Qv6cT4qCTuSHMTpPLoWITc77M= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9tapk_1789703936; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9tapk_1789703936 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:56 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/12] mm: khugepaged: allow khugepaged to check all shmem mTHP-sized orders Date: Fri, 18 Sep 2026 11:58:42 +0800 Message-ID: X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" We are now ready to enable shmem mTHP collapse, allowing thp_vma_allowable_orders() to check all permissible shmem large orders. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 5c477ea16c6f..4b5e1f8ddf87 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -493,9 +493,14 @@ unsigned long collapse_possible_orders(struct vm_area_= struct *vma, { unsigned long orders; =20 - /* If khugepaged is scanning an anonymous vma, allow mTHP collapse */ + /* + * If khugepaged is scanning an anonymous or shmem vma, + * allow mTHP collapse. + */ if ((tva_flags =3D=3D TVA_KHUGEPAGED) && vma_is_anonymous(vma)) orders =3D THP_ORDERS_ALL_ANON; + else if ((tva_flags =3D=3D TVA_KHUGEPAGED) && vma_is_shmem(vma)) + orders =3D THP_ORDERS_ALL_FILE_DEFAULT; else orders =3D BIT(HPAGE_PMD_ORDER); =20 --=20 2.47.3 From nobody Fri Sep 25 01:18:33 2026 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (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 D10573EEADE for ; Fri, 18 Sep 2026 03:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703949; cv=none; b=JpIJJo8OsQLT26535tInBXHYJkP40EgpUly1I7sA45NGEi2ciX6uzh5yclIK8c14pPqMt5iBHCQe4VmFa/AXIW1mXL2hnzoKZ6EUGZOnzaGlmwpV90gJ79boP1GbhyJw0R3bdnjmf+FrCqv0GiZbfl2aN90gU22XPUbbLhP1BXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789703949; c=relaxed/simple; bh=QhM6UnmsOFyjjE8oQemprMSibMedycjjOOzuFtMylzA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bs9XiDlWTxe9e0/WCzh7oWbwhN0DsGq98CHJmOsfhXh1o/Z/wYN1qtPe9hqBML8k240xEqh1IjS323E9RnkcBYP2bLRVqU9sHjmbmh/0vTMAv/gOVyi4V/uPoHiXtWI+ZopMnDhr0bsdSDFN+Qln36DvLnwu6psQrNsNbwy6X7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=MhLMeKEF; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="MhLMeKEF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1789703940; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=JGEA7g9C3seBG7Njk9iXotctiOXVjOvcLMoVwj7oXRY=; b=MhLMeKEF5yMWeEhOck6msS9p83WCIbZV4pcX2juF98eqyxwrZM5KdDFRMqMtuIVHii04ci9l3w/7aQZSwDas6Ig39wfnht7wh5LrknYx4MKfUu1ctIgXA15Cdr1AghctT9lilweBaWXxXiHd6v1rjwudCtID+ycOYv7ayxy78cc= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0XB9uK6u_1789703936; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XB9uK6u_1789703936 cluster:ay36) by smtp.aliyun-inc.com; Fri, 18 Sep 2026 11:58:57 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com, david@kernel.org Cc: ziy@nvidia.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, ljs@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/12] selftests: mm: add shmem mTHP collapse test cases Date: Fri, 18 Sep 2026 11:58:43 +0800 Message-ID: <5f0b54de46dfe0dabaeb78e8a68bbe828ffce9ca.1789701677.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" Add shmem mTHP collapse test cases for 'collapse_full', and 'collapse_singl= e_mthp' for shmem. All khugepaged test cases passed. Signed-off-by: Baolin Wang --- tools/testing/selftests/mm/khugepaged.c | 7 +++++-- tools/testing/selftests/mm/run_vmtests.sh | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selfte= sts/mm/khugepaged.c index f82673f5f6b4..a205b7afbc85 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -627,6 +627,9 @@ static void mthp_khugepaged_collapse(const char *msg, c= har *p, int nr_hpages, if (ops =3D=3D &__anon_ops) { settings.thp_enabled =3D THP_NEVER; settings.hugepages[collapse_order].enabled =3D THP_MADVISE; + } else if (ops =3D=3D &__shmem_ops) { + settings.shmem_enabled =3D SHMEM_NEVER; + settings.shmem_hugepages[collapse_order].enabled =3D SHMEM_ADVISE; } =20 thp_push_settings(&settings); @@ -1260,8 +1263,6 @@ static void parse_test_type(int argc, char **argv) usage(); } else if (!strcmp(buf, "shmem")) { shmem_ops =3D &__shmem_ops; - if (mthp_khugepaged_context) - usage(); } else { usage(); } @@ -1358,6 +1359,7 @@ int main(int argc, char **argv) TEST(collapse_full, khugepaged_context, read_write_file_write_ops); TEST(collapse_full, khugepaged_context, shmem_ops); TEST(collapse_full, mthp_khugepaged_context, anon_ops); + TEST(collapse_full, mthp_khugepaged_context, shmem_ops); TEST(collapse_full, madvise_context, anon_ops); TEST(collapse_full, madvise_context, read_only_file_ops); TEST(collapse_full, madvise_context, read_write_file_read_ops); @@ -1369,6 +1371,7 @@ int main(int argc, char **argv) TEST(collapse_empty, madvise_context, anon_ops); =20 TEST(collapse_single_mthp, mthp_khugepaged_context, anon_ops); + TEST(collapse_single_mthp, mthp_khugepaged_context, shmem_ops); =20 TEST(collapse_single_pte_entry, khugepaged_context, anon_ops); TEST(collapse_single_pte_entry, khugepaged_context, read_only_file_ops); diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/self= tests/mm/run_vmtests.sh index 19755fb4edb9..e1e404a612cc 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -427,6 +427,8 @@ CATEGORY=3D"thp" run_test ./khugepaged -s 4 all:shmem =20 CATEGORY=3D"thp" run_test ./khugepaged -c 4 mthp_khugepaged:anon =20 +CATEGORY=3D"thp" run_test ./khugepaged -c 4 mthp_khugepaged:shmem + # Try to create XFS if not provided if [ -z "${SPLIT_HUGE_PAGE_TEST_XFS_PATH}" ]; then if test_selected "thp"; then --=20 2.47.3