From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Lian Wang <lianux.mm@gmail.com>, Johannes Weiner <hannes@cmpxchg.org>
Cc: "Barry Song (Xiaomi)" <baohua@kernel.org>,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@kernel.org>,
Qi Zheng <zhengqi.arch@bytedance.com>,
Shakeel Butt <shakeel.butt@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>,
Kairui Song <kasong@tencent.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Wang Lian <wanglian@kylinos.cn>, Kunwu Chan <chentao@kylinos.cn>,
liz2nku@gmail.com, xueyuan.chen21@gmail.com
Subject: Re: [RFC PATCH v2] mm: Improve pgdat_balanced() to avoid over-reclamation for higher-order allocation
Date: Tue, 15 Sep 2026 10:30:50 +0800 [thread overview]
Message-ID: <1abcc4cf-fc84-4dcc-947f-8733df44e625@linux.alibaba.com> (raw)
In-Reply-To: <20260914113353.94964-1-lianux.mm@gmail.com>
Hi Lian,
On 9/14/26 7:33 PM, Lian Wang wrote:
> From: "Lian Wang (ProcessMission)" <lianux.mm@gmail.com>
>
> Hi Johannes, Barry, Baolin, Kairui, everyone,
Thanks for raising this issue again.
> We revisited the thread and Johannes's earlier analysis on the kswapd/kcompactd
> handoff. We agree that a single static `compact_gap()` cannot represent
> hundreds or thousands of concurrent higher-order requests. In such workloads,
> repeated kswapd wakeups often reflect real unsatisfied demand, and stopping
> kswapd too early can shift the burden to direct reclaim and direct compaction.
>
> At the same time, related reclaim issues are still appearing in several
> environments:
>
> - Barry observed order-3 network allocations causing persistent kswapd
> activity and device heating on phones, even though requesters can fall back
> quickly to order-0.
> - Baolin and Kairui have seen similar fragmentation-driven reclaim behavior
> on servers.
> - We have reproduced on PCs and VMs that order-0 memory and total available
> memory can remain plentiful while order-3 blocks are scarce, yet kswapd
> consumes substantial CPU and runs heavy reclaim/scan loops. We have not yet
> reproduced this consistently on our server systems.
>
> There is a useful parallel in Johannes's production work on reclaim storms in
> defrag_mode:
>
> https://lore.kernel.org/20260626182215.1107966-1-hannes@cmpxchg.org/
>
> The allocation paths differ, but both threads expose a similar feedback problem:
> reclaim may report progress in the number of freed pages, while not making useful
> allocation progress for the order, migratetype, or fallback intent that triggered
> it.
>
>> The compaction gap is sized for a single allocation, but
>> kswapd/kcompactd are a shared resource for potentially hundreds or
>> thousands of incoming requests.
>
> We share this concern and do not want to replace the existing incremental
> pipeline with one fixed value. We would like to separate two possibilities:
>
> 1. One high-order kswapd wakeup overshoots `compact_gap()` substantially
> before `sc->order` is reset and kcompactd is woken.
> 2. Each wakeup makes bounded progress, and the total overhead comes from
> repeated wakeups after best-effort callers have already fallen back to
> order-0.
>
> For the first case, limiting the high-order reclaim scan or per-wakeup reclaim
> budget when order-0 watermarks are already satisfied may preserve the repeated-
> wakeup pipeline while avoiding a large single-pass overshoot. For the second,
> we may need stronger accounting of outstanding higher-order demand, instead of
> treating every repeated best-effort attempt as a request that still needs
> background progress.
>
> Would it make sense to align on a common, parameterized reproducer and trace set
> before choosing between changing `pgdat_balanced()`, bounding the high-order
> reclaim budget, or improving demand accounting? A useful matrix could cover:
>
> - best-effort order-3 allocation with immediate order-0 fallback;
> - sustained and concurrent THP or pageblock-order demand;
> - default mode and defrag_mode;
> - phone, PC/VM, and NUMA server environments.
>
> We can share our reproducer and the PC/VM traces, and adapt the workload to
> collect per-wakeup `nr_to_reclaim`, `nr_reclaimed`, `nr_scanned`, order reset,
> kcompactd activity, allocation success, and fallback path details. It would be
> very helpful if Barry, Baolin, Kairui, and Johannes can tell us which parts of
> this matrix and which counters best represent the phone and server cases. Then
> we can compare scenarios with aligned measurements and work toward a solution that
> does not trade mobile reclaim storms for server direct-reclaim/compaction storms.
Like I said before [1], the problem we ran into is that in scenarios
where fragmentation caused kswapd to be woken up and reclaim too many
file folios (even when free memory was sufficient), leading to severe
I/O contention that impacted some applications.
In such fragmentation scenarios, I don't think we should reclaim a large
number of file folios, instead we should wake up kcompactd to perform
defragmentation. So in theory, I prefer Barry's earlier proposal to
adjust 'sc->nr_to_reclaim' [2]. But let's see what Johannes thinks.
Based on our problem, I think we can setup a simple test scenario: one
workload tries to allocate THP under fragmentation (and free memory was
sufficient now), while another fio workload accesses file folios
periodically. In this scenario, kswapd's reclaim should not affect the
fio workload's performance.
[1]
https://lore.kernel.org/all/8d4df864-2954-4eb6-b8d7-ae6595646e6e@linux.alibaba.com/
[2]
https://lore.kernel.org/all/CAGsJ_4x9vkv2G7d-gANf8kqUJVxQh_P9=AJxr98LFUgQeOTqow@mail.gmail.com/
next prev parent reply other threads:[~2026-09-15 2:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 2:18 Barry Song (Xiaomi)
2026-04-22 6:58 ` Baolin Wang
2026-04-22 10:56 ` Barry Song
2026-04-22 15:47 ` Johannes Weiner
2026-04-22 21:19 ` Barry Song
2026-09-14 11:33 ` Lian Wang
2026-09-15 2:30 ` Baolin Wang [this message]
2026-09-15 2:50 ` Lian Wang
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=1abcc4cf-fc84-4dcc-947f-8733df44e625@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=chentao@kylinos.cn \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liz2nku@gmail.com \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=wanglian@kylinos.cn \
--cc=weixugc@google.com \
--cc=xueyuan.chen21@gmail.com \
--cc=yuanchu@google.com \
--cc=zhengqi.arch@bytedance.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®