From: Dev Jain <dev.jain@arm.com>
To: Bo Zhang <zhangbo0325@gmail.com>
Cc: akpm@linux-foundation.org, vbabka@kernel.org, david@kernel.org,
surenb@google.com, mhocko@suse.com, brendan.jackman@linux.dev,
hannes@cmpxchg.org, ziy@nvidia.com, ljs@kernel.org,
liam@infradead.org, rppt@kernel.org, qi.zheng@linux.dev,
shakeel.butt@linux.dev, kasong@tencent.com, baohua@kernel.org,
axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
zhaonanzhe@xiaomi.com, lipengfei28@xiaomi.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Bo Zhang <zhangbo56@xiaomi.com>
Subject: Re: [RFC PATCH v2 2/4] mm: compaction: target mTHP order for proactive compaction
Date: Tue, 20 Oct 2026 12:18:06 +0530 [thread overview]
Message-ID: <0aae72c3-7f46-4236-8cbb-d3e6f3c66e62@arm.com> (raw)
In-Reply-To: <20261019150315.2018934-1-zhangbo56@xiaomi.com>
On 19/10/26 8:33 pm, Bo Zhang wrote:
> On 19/10/26 1:42 pm, Dev Jain wrote:
>> I wonder if this function should be left alone?
>>
>> compaction_proactiveness, as I understand is given as a sysfs knob to
>> ensure that the user can control how much power they want to invest into
>> compacting. So suppose the value is 20, and the highest mTHP order is
>> only 2. This gives wmark = 90 * 2 / 9 = 20. So, even if 80% of the memory
>> can serve order-2 allocations, we will still perform compaction for
>> order-2. This seems "extremely proactive" :)
>
> Thanks a lot for looking at this closely, and you are right that the
> scaling factor is the weakest part of this patch. I called it out as an
> open question in the cover letter and I don't have a solid theoretical
> basis for the linear order/COMPACTION_HPAGE_ORDER form.
>
> What pushed me towards scaling the watermark at all was the opposite
> problem on the measurement side: without any scaling, the order-9
> threshold is essentially never reached for a small order, so proactive
> compaction effectively never runs for order-2.
>
> I instrumented fragmentation_score_node() for order-2 on an 8G,
> data=journal kernel-build workload and sampled it at ~100ms. On the
> unpatched kernel the order-2 score looks like this:
>
> order-2 score (unpatched, same workload):
> mean 17.3
> p90 47
> p99 91
> max 100
>
> fraction of time the score exceeds a given threshold:
> > 90 (unscaled, the current order-9 wmark): 1.0%
> > 20 (scaled down to order-2): 27.2%
>
> So with the current (unscaled) watermark, the order-2 score crosses the
> trigger only 1% of the time, which in practice proactive compaction almost
> never fires for order-2.
I get it, so the workload is rapidly allocating mTHP, and kcompactd does not
kick in time, leading to direct compaction (compact_stall) or fallback.
But I think this is a tradeoff with the current design in Linux and has nothing
to do with our mTHP usecase right? Even with PMD sized THP we may have the same
problem.
I think the uncontroversial bit of your patchset is the fact that currently we
migrate large folios just to free up a 2M region. To make forward progress it
will be great if you can find a workload which gets us an improvement without
the threshold changes and we could get those patches merged first.
I am saying that because the reason you keep crossing the 90% threshold is
due to the nature of the workload and that you set 32k mTHP to always. I doubt
on a real system you will cross the threshold this rapidly since mTHP would be
mostly "madvise" and that mTHP-requiring workload wouldn't be the only workload
running.
Given that, one thing that comes to mind is this algorithm - kcompactd wakes up, sees
that the threshold got crossed again, which means it woke up too late. So
it should manipulate the threshold or its wake up time. We need a signal to
say that the mTHP allocation is too abundant and we need background compaction
more frequently.
This algorithm may be in contradiction with the sysctl ... so instead of changing
the threshold, we could lower the wakeup time.
This is similar to how the pcp list changes its threshold if too much allocation
is happening.
>
> That said, your example shows the linear scaling clearly overshoots in
> the other direction: a scaled wmark of ~20 can keep compacting while a
> large fraction of memory is already usable, which is not what the
> proactiveness knob is supposed to express. So I agree the current formula
> is not the right answer.
>
> I'd appreciate your thoughts on the direction here. A couple of options
> I can see:
>
> 1. Leave fragmentation_score_wmark() alone and instead make the score
> itself order-aware / normalized, so that a given proactiveness value
> maps to a comparable amount of work regardless of the target order.
> This keeps the knob's meaning intact.
The challenge is the normalization algorithm, the problem is that there is
nothing we can deduce apart from the fact that
frag_score (order x) <= frag_score (order y) where x <= y.
>
> 2. Keep scaling the watermark but with a floor / non-linear mapping so
> it cannot collapse to a value that triggers when memory is clearly
> sufficient.
>
> I haven't settled on either yet and would rather hear which direction you
> think makes more sense before reworking it.
>
> Also, thanks for the review on patch 4 -- good to know the
> costly/non-costly split seems like a reasonable compromise.
>
> Thanks,
> Bo
next prev parent reply other threads:[~2026-10-20 6:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 0:14 [RFC PATCH v2 0/4] mm: compaction: mTHP-friendly memory compaction Bo Zhang
2026-10-01 0:14 ` [RFC PATCH v2 1/4] mm: compaction: parameterize fragmentation score by order Bo Zhang
2026-10-01 0:14 ` [RFC PATCH v2 2/4] mm: compaction: target mTHP order for proactive compaction Bo Zhang
2026-10-19 8:12 ` Dev Jain
2026-10-19 14:50 ` Xueyuan Chen
2026-10-19 15:03 ` Bo Zhang
2026-10-20 6:48 ` Dev Jain [this message]
2026-10-19 15:47 ` Bo Zhang
2026-10-01 0:14 ` [RFC PATCH v2 3/4] mm: compaction: skip isolating large folios that already satisfy mTHP Bo Zhang
2026-10-01 0:14 ` [RFC PATCH v2 4/4] mm: compaction: skip unmovable blocks for non-costly proactive mTHP compaction Bo Zhang
2026-10-19 9:43 ` Dev Jain
2026-10-19 15:50 ` [RFC PATCH v2 0/4] mm: compaction: mTHP-friendly memory compaction Xueyuan Chen
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=0aae72c3-7f46-4236-8cbb-d3e6f3c66e62@arm.com \
--to=dev.jain@arm.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=brendan.jackman@linux.dev \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lipengfei28@xiaomi.com \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=zhangbo0325@gmail.com \
--cc=zhangbo56@xiaomi.com \
--cc=zhaonanzhe@xiaomi.com \
--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®