All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Brendan Jackman <brendan.jackman@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Brendan Jackman <jackmanb@google.com>, Zi Yan <ziy@nvidia.com>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R . Howlett" <liam@infradead.org>,
	Mike Rapoport <rppt@kernel.org>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 4/4] mm: page_alloc: fix non-movable reclaim storm in defrag_mode
Date: Fri, 24 Jul 2026 14:07:31 -0400	[thread overview]
Message-ID: <amOp4wV3Yl6PKx_1@cmpxchg.org> (raw)
In-Reply-To: <DK6WANTYCK4H.CRSXHW3ST1Q5@linux.dev>

On Fri, Jul 24, 2026 at 03:09:49PM +0000, Brendan Jackman wrote:
> On Wed Jul 22, 2026 at 2:56 PM UTC, Johannes Weiner wrote:
> > As we deployed defrag_mode into Meta production, pressure spikes and
> > excessive swapping were observed on some workloads. Tracing confirmed
> > that this is unmovable/reclaimable requests spinning in the allocator
> > and direct reclaim, causing excessive amounts of swap.
> >
> > The initial plan for defrag_mode was to rely on kswapd/kcompactd to
> > produce blocks, and if those are overwhelmed under high pressure, let
> > the allocator fall back (__rmqueue_steal()) after its retry loops.
> > However, that retrying results in more reclaim on some of these
> > workloads than we'd hoped, sometimes excessively so, spurred on by the
> > !costly order conditions in should_reclaim_retry().
> >
> > The storms are dependent on the request type. Reclaim will inevitably
> > make room in existing movable blocks, since that's where the LRU pages
> > live. So if movable requests retry on reclaim, they make progress.
> >
> > When non-movable requests spin in reclaim that isn't productive. They
> > cannot use the individually freed pages, and the process is unlikely
> > to accidentally free whole blocks to meet the ALLOC_NOFRAGMENT bar.
> > They spin and overreclaim excessively, which tanks performance and
> > triggers userspace guards like swap exhaustion or pressure based OOM.
> >
> > To fix this, send non-movable requests, regardless of order, into
> > pageblock reclaim/compaction. This way, they help move things along to
> > meet the ALLOC_NOFRAGMENT bar. After this patch, the reclaim storms
> > and excess OOM rates are no longer observed in production.
> >
> > The longer-term plan is still to have all requests, including the
> > movable ones, help make blocks to spread the cost of defragmenting
> > more evenly and fairly; combined with proper watermarking to reduce
> > allocation latencies in the common case. However, doing this naively
> > unearths scaling and concurrency limitations in compaction that need
> > to be addressed first. Promoting just non-movables for now is the
> > minimally viable bug fix for the above issue.
> 
> Please forgive the noob question, I'm still struggling to get a really
> good mental handle on this stuff. But what about compact_first here?
> When we're promoting the order for compaction does it also make sense to
> promote compaction itself?

My understanding is that this is just an optimization for requests
that are more likely shape-limited (block contiguity) rather than
capacity-limited (free order-0). In that case we do a quick async
compaction attempt first and skip a potentially unnecessary but still
disruptive reclaim invocation.

However, it does seem to me there is a bit of redundancy between the
allocator and reclaim: direct reclaim also has that early bailout
condition on compaction_ready() for costly orders.

In defrag_mode, since reclaim is promoted to pageblock_order (costly),
we always bail reclaim on compaction_ready(). So I would assume there
is not much difference from which we call first - although I have not
tested it.

> I'm aware you said "minimally viable bug fix" so it's fine if this falls
> outside of that, I'm just trying to poke around to improve my
> understanding.

It works in production, but I'm not entirely happy yet with the retry
logic. I also find it somewhat difficult to understand, especially the
split between should_reclaim_retry() and should_compact_retry().

I'm working on unifying them and put the defrag_mode order promotion
directly into the slowpath function. This way we can use "work_order"
and "order" throughout the functions and its callees as appropriate.

But yeah this is follow-up work to the fix here.

      reply	other threads:[~2026-07-24 18:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 14:56 [PATCH v2 0/4] mm: fix reclaim storms in defrag_mode Johannes Weiner
2026-07-22 14:56 ` [PATCH v2 1/4] mm: page_alloc: __GFP_FS lockdep annotation for direct compaction Johannes Weiner
2026-07-22 14:56 ` [PATCH v2 2/4] mm: compaction: support non-movable compaction for pageblock requests Johannes Weiner
2026-07-22 16:23   ` Gregory Price
2026-07-22 14:56 ` [PATCH v2 3/4] mm: page_alloc: move capture_control to the page allocator Johannes Weiner
2026-07-22 16:59   ` Gregory Price
2026-07-22 14:56 ` [PATCH v2 4/4] mm: page_alloc: fix non-movable reclaim storm in defrag_mode Johannes Weiner
2026-07-22 17:10   ` Brendan Jackman
2026-07-22 23:22   ` Andrew Morton
2026-07-23 10:22     ` Vlastimil Babka (SUSE)
2026-07-23 14:08       ` Johannes Weiner
2026-07-23 14:17         ` Vlastimil Babka (SUSE)
2026-07-24  0:02           ` Andrew Morton
2026-07-24  5:58             ` Greg Kroah-Hartman
2026-07-24  0:00       ` Andrew Morton
2026-07-23 15:13   ` Vlastimil Babka (SUSE)
2026-07-24 15:09   ` Brendan Jackman
2026-07-24 18:07     ` Johannes Weiner [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=amOp4wV3Yl6PKx_1@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.jackman@linux.dev \
    --cc=david@kernel.org \
    --cc=jackmanb@google.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.