mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kiryl Shutsemau <kirill@shutemov.name>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.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 v3 05/12] mm/collapse: state what a collapse may do in the policy
Date: Thu, 24 Sep 2026 14:49:05 +0100	[thread overview]
Message-ID: <arUVpLSG3Xj560m5@thinkstation> (raw)
In-Reply-To: <2add40dc-6541-41e3-8233-521cce7e0d33@kernel.org>

On Wed, Sep 23, 2026 at 02:24:04PM +0200, David Hildenbrand (Arm) wrote:
> > +/* What a collapse is allowed to do, decided by the caller that asks for it */
> > +struct collapse_policy {
> > +	/* Limits, stated per PMD; HPAGE_PMD_NR means "no limit" */
> > +	unsigned int max_ptes_none;
> > +	unsigned int max_ptes_swap;
> > +	unsigned int max_ptes_shared;
> > +
> > +	/* Take no swapped-out or shared PTE into a sub-PMD collapse */
> > +	bool strict_sub_pmd;
> 
> Reading this variable name without the documentation I have no idea what it
> means. It looks like the wrong abstraction.
> 
> Maybe you instead want to split max_ptes_swap and shared to a PMD and non-PMD case?
> 
> I am also confused why you use "strict_sub_pmd" in the collapse_max_ptes_none()
> handler below? Something seems odd, as it doesn't amtch the description here.

The comment undersells it.

The flag stands in for every sub-PMD rule khugepaged applies and
MADV_COLLAPSE does not: no swapped-out PTE, no shared PTE, and
max_ptes_none scaled to the order.

Before this patch all three helpers tested is_khugepaged and then
is_pmd_order; the flag replaced the first test in each. Which makes it
is_khugepaged under another name, so you are right that it is the wrong
abstraction.

Splitting the limits works. Two sets of counts, one per order class:

	struct collapse_limits {
		unsigned int max_ptes_none;
		unsigned int max_ptes_swap;
		unsigned int max_ptes_shared;
	};

	struct collapse_policy {
		struct collapse_limits pmd;
		struct collapse_limits sub_pmd;
		...
	};

For swap and shared the sub-PMD value is a count: 0 for khugepaged, no
limit for MADV_COLLAPSE.

For none it is the knob value, and the helper keeps today's rule: 511
means all but one PTE of the window, anything else means none.

	static unsigned int collapse_max_ptes_none(struct collapse_control *cc,
			struct vm_area_struct *vma, unsigned int order)
	{
		unsigned int max_ptes_none;

		if (vma && userfaultfd_armed(vma))
			return 0;
		if (is_pmd_order(order))
			return cc->policy.pmd.max_ptes_none;

		/* Below PMD order: all but one PTE of the window, or none */
		max_ptes_none = cc->policy.sub_pmd.max_ptes_none;
		if (max_ptes_none == COLLAPSE_MAX_PTES_LIMIT)
			return (1 << order) - 1;
		return 0;
	}

Only the warning for other knob values moves to where khugepaged fills
its policy. MADV_COLLAPSE never reads sub_pmd: it collapses to PMD order
only. Nothing is scaled, so the creep question is untouched.

> > +
> > +	/* Leave clean lazyfree folios to reclaim rather than collapse them */
> > +	bool skip_lazyfree;
> > +
> > +	/* Refuse a range with no sign of use */
> > +	bool require_referenced;
> > +
> > +	/* Map the PMD over a file collapse instead of leaving it to a fault */
> > +	bool install_pmd;
> 
> Confusing.
> 
> If some of these policies are anon-/ file-specific, the name should indicate
> that, so there is less head scratching.

install_pmd and writeback_dirty are read only on the file side,
skip_lazyfree and require_referenced only on the anonymous side.

I will prefix them.

> > +/* MADV_COLLAPSE was asked for explicitly, so it is not held to those */
> > +static void collapse_policy_forced(struct collapse_policy *p)
> 
> Why are we not calling this collapse_policy_madvise to match its description here?

Will do.

> > @@ -2943,6 +2952,9 @@ static void khugepaged_do_scan(struct collapse_control *cc)
> >  
> >  	lru_add_drain_all();
> >  
> > +	/* One policy for the whole pass, so every table is treated the same */
> 
> just drop that comment.

Ack.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov

  reply	other threads:[~2026-09-24 13:49 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  9:31 [PATCH v3 00/12] mm/collapse: separate a collapse from its callers Kiryl Shutsemau
2026-09-16  9:31 ` [PATCH v3 01/12] mm/khugepaged: drop redundant mm_struct pin in madvise_collapse() Kiryl Shutsemau
2026-09-23 11:49   ` David Hildenbrand (Arm)
2026-09-16  9:31 ` [PATCH v3 02/12] mm/khugepaged: count collapses where khugepaged makes them Kiryl Shutsemau
2026-09-23 11:51   ` David Hildenbrand (Arm)
2026-09-16  9:31 ` [PATCH v3 03/12] mm/khugepaged: rename mthp_present_ptes bitmap to eligible_ptes Kiryl Shutsemau
2026-09-23 11:52   ` David Hildenbrand (Arm)
2026-09-16  9:31 ` [PATCH v3 04/12] mm/collapse: add collapse.h for the collapse interface Kiryl Shutsemau
2026-09-23 11:56   ` David Hildenbrand (Arm)
2026-09-16  9:31 ` [PATCH v3 05/12] mm/collapse: state what a collapse may do in the policy Kiryl Shutsemau
2026-09-23 12:24   ` David Hildenbrand (Arm)
2026-09-24 13:49     ` Kiryl Shutsemau [this message]
2026-09-16  9:31 ` [PATCH v3 06/12] mm/collapse: drop the collapse_possible() wrapper Kiryl Shutsemau
2026-09-23 12:25   ` David Hildenbrand (Arm)
2026-09-16  9:31 ` [PATCH v3 07/12] mm/collapse: name the per-table scan reset for what it resets Kiryl Shutsemau
2026-09-23 12:26   ` David Hildenbrand (Arm)
2026-09-16  9:31 ` [PATCH v3 08/12] mm/collapse: separate scanning a PTE table from collapsing it Kiryl Shutsemau
2026-09-18  9:06   ` Baolin Wang
2026-09-23 13:04   ` David Hildenbrand (Arm)
2026-09-24 14:19     ` Kiryl Shutsemau
2026-09-16  9:31 ` [PATCH v3 09/12] mm/collapse: open-code collapse_single_pmd() in its two callers Kiryl Shutsemau
2026-09-18  9:31   ` Baolin Wang
2026-09-23 13:08   ` David Hildenbrand (Arm)
2026-09-24 14:56     ` Kiryl Shutsemau
2026-09-16  9:31 ` [PATCH v3 10/12] mm/collapse: work out the orders a VMA allows once per VMA Kiryl Shutsemau
2026-09-23 13:19   ` David Hildenbrand (Arm)
2026-09-24 15:04     ` Kiryl Shutsemau
2026-09-16  9:31 ` [PATCH v3 11/12] mm/collapse: declare the collapse interface in collapse.h Kiryl Shutsemau
2026-09-23 13:34   ` David Hildenbrand (Arm)
2026-09-24 15:22     ` Kiryl Shutsemau
2026-09-16  9:31 ` [PATCH v3 12/12] mm/collapse: implement MADV_COLLAPSE in madvise.c Kiryl Shutsemau
2026-09-16 22:48 ` [PATCH v3 00/12] mm/collapse: separate a collapse from its callers Andrew Morton
2026-09-17 12:26   ` Kiryl Shutsemau
2026-09-17 22:11     ` Andrew Morton
2026-09-23 13:52       ` David Hildenbrand (Arm)

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=arUVpLSG3Xj560m5@thinkstation \
    --to=kirill@shutemov.name \
    --cc=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=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®