Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Barry Song <baohua@kernel.org>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>,
	Joanne Koong <joannelkoong@gmail.com>,
	akpm@linux-foundation.org, ljs@kernel.org, usama.arif@linux.dev,
	alex@ghiti.fr, ziy@nvidia.com, baolin.wang@linux.alibaba.com,
	liam@infradead.org, npache@redhat.com, ryan.roberts@arm.com,
	dev.jain@arm.com, lance.yang@linux.dev, vbabka@kernel.org,
	rppt@kernel.org, surenb@google.com, mhocko@suse.com,
	willy@infradead.org, linux-mm@kvack.org
Subject: Re: [PATCH v1 2/2] mm/memory: add anonymous mTHP folios to deferred split list
Date: Mon, 3 Aug 2026 10:45:10 -0400	[thread overview]
Message-ID: <anCpdjEoDNgVbfzP@cmpxchg.org> (raw)
In-Reply-To: <CAGsJ_4xhbEAiLFt-3N7738zJDoJ=hPRYLpP3tpU2sGOz=ORiaQ@mail.gmail.com>

On Sat, Aug 01, 2026 at 03:33:42PM +0800, Barry Song wrote:
> On Fri, Jul 31, 2026 at 11:04 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
> > This is kind of tangential, but I'm curious if you would have
> > experimented with larger folios AND the THP shrinker?
> >
> 
> Haven't tried it yet.
> 
> A key difference between Android and server workloads is that Android
> typically has many applications running with frequent
> foreground/background transitions. When an app moves to the
> background, much of its memory may be compressed. When it returns to
> the foreground, it often allocates a large amount of new memory,
> creating significant memory pressure.
> 
> If we need around 200 ms to cold/warm start an app, allocating 2 MB
> folios and later splitting them into smaller ones via the THP shrinker
> could cause us to hit this shrinker path directly during the app launch
> process. For example, we may spend the first 100 ms allocating 2 MB
> folios and then the next 100 ms shrinking them back under memory
> pressure. This would be quite ironic for Android :-)
> 
> Since Android app launches can demand a large amount of memory on
> devices with limited RAM, keeping burst allocations small is also
> important.

Makes sense, thanks for the insight.

It works for many DC services because it's just a bit of extra startup
cost, while then getting predictable THP coverage for exactly those
areas where it makes sense, and the TLB benefits pay off over long
service runtimes.

> > In Meta, 2M thp=always without the shrinker would also not have been
> > tolerable. It OOMed immediately on a large number of services. The
> > shrinker *is* what allowed us to use such large folios to begin with,
> > without the internal memory waste problem.
> 
> My understanding is that Meta's use case is a service that is already
> running with 2 MB pages, and later additional services start and
> require more memory. In that case, shrinking THPs from the existing
> service to free memory for the new services makes sense to me.

It's simpler than that. We had existing services, scaled to machine
capacity, running with basepages. When we enabled 2M pages, they
started thrashing and OOMing from areas with poor virtual packing.

The shrinker makes it possible to run with THPs enabled, period. This
is why I'm concerned about making the search for waste less
efficient. It would likely regress things in production immediately.

> > Here is an idea: the THP shrinker will not consider anything unused
> > that has <= max_ptes_none zero pages. See thp_underused(). Joanne was
> > proposing to scale this knob down relative to the folio size for mTHP
> > shrinking. What if instead we kept the meaning absolute?
> >
> > The knob is an expression of how much waste the user is willing to
> > tolerate per folio. If the folio order in question couldn't possibly
> > have that much waste in the first place, we don't have to queue it?
> >
> > Something like this:
> >
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index 2bccb0a53a0a..1670e9869bd3 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -4364,6 +4364,9 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped)
> >         if (!partially_mapped && !split_underused_thp)
> >                 return;
> >
> > +       if (!partially_mapped && folio_nr_pages(folio) <= khugepaged_max_ptes_none)
> > +               return;
> > +
> >         /*
> >          * Exclude swapcache: originally to avoid a corrupt deferred split
> >          * queue. Nowadays that is fully prevented by __memcg1_swapout();
> >
> > The setting defaults to the PMD-1, so out of the box we wouldn't queue
> > any new orders. It would allow that 2MB on 64k ARM usecase, without
> > jeopardizing smaller mTHP usecases like Barry's.
> >
> > Thoughts?
> 
> My understanding is that adding smaller folios to the deferred split
> list is not the right approach. We could end up with a very large list
> where we cannot distinguish partially unmapped folios from fully mapped
> ones. For example, the deferred split list could contain 100 fully mapped
> folios but only a single partially mapped folio.
> Moreover, for smaller large folios, the number of zero subpages
> is likely to be small and short-lived.
> 
> However, this is probably fine for larger large folios, since it is
> unlikely to significantly increase the size of the deferred split
> list. In other words, the deferred split list should remain manageable.
> For the same reason, larger large folios may not benefit much from the
> LRU cache either.
> 
> So if we have some mechanism to prevent users from doing things that
> are not beneficial, such as adding smaller large folios to the list, it
> seems reasonable to me.

Just to clarify, we're on the same page, right? I was proposing a
mechanism to do just that.

> As a side note (I'm not quite sure whether this is relevant to this
> discussion), one thing we tried previously as an out-of-tree proof of
> concept was:
> 
> for (pfn = start_phys_pfn; pfn < end_phys_pfn;) {
>      folio = get_folio_from_pfn();
>      if (folio_is_zero_fill(folio))
>             swap_out(folio);
>      pfn += folio_nr_pages();
> }
>
> Then I was using my previous patch to remap it to zero-pfn if someone
> reads it:
> https://lore.kernel.org/linux-mm/20241212073711.82300-1-21cnbao@gmail.com/
> 
> This does not depend on any list-related logic. We can scan all PFNs
> within a short time.

Hm there are 268 million PFNs on a 1TB host. I don't think that can
scale?

Compaction used to be linear scans, but needed to grow the freelist
search and a whole bunch of position hinting to stay ahead of scaling
bottlenecks.


  reply	other threads:[~2026-08-03 14:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 20:17 [PATCH v1 0/2] mm: split underused anonymous mTHP folios Joanne Koong
2026-07-07 20:17 ` [PATCH v1 1/2] mm/huge_memory: extend thp_underused() to " Joanne Koong
2026-07-08  4:03   ` Joanne Koong
2026-07-07 20:17 ` [PATCH v1 2/2] mm/memory: add anonymous mTHP folios to deferred split list Joanne Koong
2026-07-08  7:56   ` David Hildenbrand (Arm)
2026-07-08  9:58     ` Usama Arif
2026-07-29 12:36       ` David Hildenbrand (Arm)
2026-07-29 13:43         ` Usama Arif
2026-07-29 14:02           ` Usama Arif
2026-07-30 13:28           ` David Hildenbrand (Arm)
2026-07-08 17:52     ` Joanne Koong
2026-07-29 12:38       ` David Hildenbrand (Arm)
2026-07-29 15:04         ` Johannes Weiner
2026-07-30 13:46           ` David Hildenbrand (Arm)
2026-07-30 15:37             ` Johannes Weiner
2026-07-30 21:31               ` Barry Song
2026-07-30 23:32                 ` Barry Song
2026-07-31 15:04                 ` Johannes Weiner
2026-08-01  7:33                   ` Barry Song
2026-08-03 14:45                     ` Johannes Weiner [this message]
2026-08-03 21:20                       ` Barry Song
2026-08-04  0:48                         ` Johannes Weiner
2026-08-04  2:03                           ` Barry Song
2026-08-04 14:03                             ` Johannes Weiner
2026-08-04 14:11                               ` David Hildenbrand (Arm)
2026-08-04 18:54                                 ` Johannes Weiner
2026-08-04 14:39                             ` Usama Arif
2026-08-04 22:07                               ` Barry Song
2026-08-04 23:26                                 ` Joanne Koong
2026-07-08  7:46 ` [PATCH v1 0/2] mm: split underused anonymous mTHP folios David Hildenbrand (Arm)
2026-07-08 18:19   ` Joanne Koong
2026-07-30 13:52     ` David Hildenbrand (Arm)
2026-07-30 23:10       ` Joanne Koong

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=anCpdjEoDNgVbfzP@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=joannelkoong@gmail.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=npache@redhat.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.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