mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "Kiryl Shutsemau (Meta)" <kas@kernel.org>
Cc: David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>, Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com, "Liam R. Howlett" <liam@infradead.org>,
	Nico Pache <nico.pache@linux.dev>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	Vlastimil Babka <vbabka@kernel.org>, Jann Horn <jannh@google.com>
Subject: Re: [PATCH v5 0/9] mm/collapse: separate a collapse from its callers
Date: Wed, 14 Oct 2026 14:16:16 -0700	[thread overview]
Message-ID: <20261014141616.6d79df8fc8c6ef7d41df5afc@linux-foundation.org> (raw)
In-Reply-To: <20261014171145.3292736-1-kas@kernel.org>

On Wed, 14 Oct 2026 18:11:33 +0100 "Kiryl Shutsemau (Meta)" <kas@kernel.org> wrote:

> There is no line between the collapse engine and the callers that ask for
> a collapse.  khugepaged.c holds both, and they reach into each other.
> 
>  - Sixteen tests through the collapse path read cc->is_khugepaged to work
>    out what they are allowed to do, when every one of those decisions was
>    made by the caller before it asked.
> 
>  - collapse_single_pmd() does both halves of a collapse behind one call.
>    Where it gives up mmap_lock between them is buried in the anonymous
>    scan on one side and ahead of the file scan on the other.
> 
> Start drawing the line.  The caller states what it allows in a policy,
> and the collapse code reads the policy instead of asking who called.  The
> scan of a PTE table and the collapse that follows get a function each,
> with the mmap_lock drop between them in one place.

Thanks, updated.

> Changes since v4
> ================
> 
>   https://lore.kernel.org/all/20260928100630.21870-1-kirill@shutemov.name/
> 
>  - Patches 10-13 dropped.
> 
>  - Patch 7: the changelog no longer mentions a release for the control,
>    which v4 dropped.
> 
>  - Patch 9: collapse_scan_anon(), collapse_pmd() and collapse_anon()
>    replace collapse_scan_anon_pmd(), collapse_run_pmd() and
>    mthp_collapse() (David).  The scan_* fields in collapse_control are
>    commented as anonymous-only and file-only (Zi).  Comments that named
>    collapse_scan_pmd() for the anonymous scan follow the rename.
> 
>  - Acked-by from David Hildenbrand on 5 and 8; Reviewed-by from Zi Yan on
>    5 and 8 and from Baolin Wang on 5; Tested-by from Baolin Wang on 5;
>    Acked-by from Zi Yan on 9.

Here are the v3->v4 changes for the nine remaining patches:


 mm/collapse.h   |   16 ++++++++++------
 mm/khugepaged.c |   28 ++++++++++++++--------------
 2 files changed, 24 insertions(+), 20 deletions(-)

--- a/mm/collapse.h~b
+++ a/mm/collapse.h
@@ -100,16 +100,20 @@ struct collapse_control {
 	DECLARE_BITMAP(eligible_ptes, MAX_PTRS_PER_PTE);
 
 	/*
-	 * What a scan found and the run after it needs.  Live only between the
-	 * two, and read by nobody else.
-	 *
-	 * The file side takes a reference while it still has the VMA, since a
-	 * file collapse works on the page cache and never sees one; the run is
-	 * what gives it back.
+	 * What a scan found and the collapse after it needs.  Live only between
+	 * the two, and read by nobody else.
 	 */
+
+	/* Anonymous only: orders to try, referenced and swap PTE counts */
 	unsigned long scan_orders;
 	int scan_referenced;
 	int scan_unmapped;
+
+	/*
+	 * File only.  A file collapse works on the page cache and never sees a
+	 * VMA, so the scan takes a reference to the file while it still has
+	 * one, and the collapse gives it back.
+	 */
 	struct file *scan_file;
 	pgoff_t scan_pgoff;
 };
--- a/mm/khugepaged.c~b
+++ a/mm/khugepaged.c
@@ -646,7 +646,7 @@ static enum scan_result __collapse_huge_
 			goto out;
 		}
 
-		/* See collapse_scan_pmd(). */
+		/* See collapse_scan_anon(). */
 		if (folio_maybe_mapped_shared(folio)) {
 			/*
 			 * TODO: Support shared pages without leading to further
@@ -1099,7 +1099,7 @@ static enum scan_result check_pmd_still_
 
 /*
  * Bring missing pages in from swap, to complete THP collapse.
- * Only done if collapse_scan_pmd() believes it is worthwhile.
+ * Only done if collapse_scan_anon() believes it is worthwhile.
  *
  * For mTHP orders the function bails on the first swap entry, because
  * faulting pages back in during collapse could re-populate PTEs that
@@ -1460,8 +1460,8 @@ static unsigned int max_order_from_offse
 }
 
 /*
- * mthp_collapse() consumes the bitmap that is generated during
- * collapse_scan_pmd() to determine what regions and mTHP orders fit best.
+ * collapse_anon() consumes the bitmap that is generated during
+ * collapse_scan_anon() to determine what regions and mTHP orders fit best.
  *
  * Each bit in cc->eligible_ptes marks a PTE the scan accepted as a collapse
  * source. We start at the PMD order and check if it is eligible for collapse;
@@ -1476,8 +1476,8 @@ static unsigned int max_order_from_offse
  * If a collapse is permitted, we attempt to collapse the PTE range into a
  * mTHP.
  */
-static enum scan_result mthp_collapse(struct mm_struct *mm, unsigned long address,
-		struct collapse_control *cc)
+static enum scan_result collapse_anon(struct mm_struct *mm,
+		unsigned long address, struct collapse_control *cc)
 {
 	unsigned int nr_eligible_ptes, nr_ptes, max_ptes_none;
 	enum scan_result last_result = SCAN_FAIL;
@@ -1576,7 +1576,7 @@ done:
 	return last_result;
 }
 
-static enum scan_result collapse_scan_anon_pmd(struct vm_area_struct *vma,
+static enum scan_result collapse_scan_anon(struct vm_area_struct *vma,
 		unsigned long start_addr, struct collapse_control *cc)
 {
 	const unsigned int max_ptes_shared = collapse_max_ptes_shared(cc, HPAGE_PMD_ORDER);
@@ -1612,7 +1612,7 @@ static enum scan_result collapse_scan_an
 	/*
 	 * If PMD is the only enabled order, enforce max_ptes_none, otherwise
 	 * scan all pages to populate the bitmap for mTHP collapse. The bitmap
-	 * is then checked again in mthp_collapse() for each attempted order.
+	 * is then checked again in collapse_anon() for each attempted order.
 	 */
 	if (enabled_orders != BIT(HPAGE_PMD_ORDER))
 		max_ptes_none = COLLAPSE_MAX_PTES_LIMIT;
@@ -2785,20 +2785,20 @@ static enum scan_result collapse_scan_pm
 	pgoff_t pgoff;
 
 	mmap_assert_locked(vma->vm_mm);
-	/* Whatever the last scan found has to have been run by now */
+	/* A scan that found work has to have been followed by collapse_pmd() */
 	if (WARN_ON_ONCE(cc->scan_file)) {
 		fput(cc->scan_file);
 		cc->scan_file = NULL;
 	}
 
 	if (vma_is_anonymous(vma))
-		return collapse_scan_anon_pmd(vma, addr, cc);
+		return collapse_scan_anon(vma, addr, cc);
 
 	pgoff = linear_page_index(vma, addr);
 	result = 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.
+	 * the PMD folio, and collapse_pmd() still has to retract the PTE table.
 	 */
 	if (result != SCAN_SUCCEED && result != SCAN_PTE_MAPPED_HUGEPAGE)
 		return result;
@@ -2812,7 +2812,7 @@ static enum scan_result collapse_scan_pm
 	return result;
 }
 
-static enum scan_result collapse_run_pmd(struct mm_struct *mm,
+static enum scan_result collapse_pmd(struct mm_struct *mm,
 		unsigned long addr, enum scan_result result,
 		struct collapse_control *cc)
 {
@@ -2821,7 +2821,7 @@ static enum scan_result collapse_run_pmd
 	pgoff_t pgoff;
 
 	if (!file)
-		return mthp_collapse(mm, addr, cc);
+		return collapse_anon(mm, addr, cc);
 
 	cc->scan_file = NULL;
 	pgoff = cc->scan_pgoff;
@@ -2882,7 +2882,7 @@ static enum scan_result collapse_single_
 	mmap_read_unlock(mm);
 	*lock_dropped = true;
 
-	return collapse_run_pmd(mm, addr, result, cc);
+	return collapse_pmd(mm, addr, result, cc);
 }
 
 static void collapse_scan_mm_slot(unsigned int progress_max,
_


      parent reply	other threads:[~2026-10-14 21:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 17:11 Kiryl Shutsemau (Meta)
2026-10-14 17:11 ` [PATCH v5 1/9] mm/khugepaged: drop redundant mm_struct pin in madvise_collapse() Kiryl Shutsemau (Meta)
2026-10-15  4:34   ` Lance Yang
2026-10-14 17:11 ` [PATCH v5 2/9] mm/khugepaged: count collapses where khugepaged makes them Kiryl Shutsemau (Meta)
2026-10-15  4:36   ` Lance Yang
2026-10-14 17:11 ` [PATCH v5 3/9] mm/khugepaged: rename mthp_present_ptes bitmap to eligible_ptes Kiryl Shutsemau (Meta)
2026-10-15  4:38   ` Lance Yang
2026-10-14 17:11 ` [PATCH v5 4/9] mm/collapse: add collapse.h for the collapse interface Kiryl Shutsemau (Meta)
2026-10-15  4:41   ` Lance Yang
2026-10-14 17:11 ` [PATCH v5 5/9] mm/collapse: state what a collapse may do in the policy Kiryl Shutsemau (Meta)
2026-10-15  4:44   ` Lance Yang
2026-10-14 17:11 ` [PATCH v5 6/9] mm/collapse: drop the collapse_possible() wrapper Kiryl Shutsemau (Meta)
2026-10-15  4:45   ` Lance Yang
2026-10-14 17:11 ` [PATCH v5 7/9] mm/collapse: name the per-table scan reset for what it resets Kiryl Shutsemau (Meta)
2026-10-15  4:46   ` Lance Yang
2026-10-14 17:11 ` [PATCH v5 8/9] mm/collapse: call collapse_file() from collapse_single_pmd() Kiryl Shutsemau (Meta)
2026-10-15  5:39   ` Lance Yang
2026-10-15  7:21   ` Baolin Wang
2026-10-14 17:11 ` [PATCH v5 9/9] mm/collapse: separate scanning a PTE table from collapsing it Kiryl Shutsemau (Meta)
2026-10-15  5:43   ` Lance Yang
2026-10-14 21:16 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014141616.6d79df8fc8c6ef7d41df5afc@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=jannh@google.com \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=nico.pache@linux.dev \
    --cc=ryan.roberts@arm.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®