From: Kairui Song <ryncsn@gmail.com>
To: Hui Zhu <hui.zhu@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@kernel.org>, Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>,
Kairui Song <kasong@tencent.com>, Barry Song <baohua@kernel.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Hui Zhu <zhuhui@kylinos.cn>
Subject: Re: [PATCH] mm/mglru: check need_resched() in fill/drain_evictable()
Date: Thu, 12 Nov 2026 16:03:54 +0800 [thread overview]
Message-ID: <avVx_1BEP7fIzGDK@KASONG-MC4> (raw)
In-Reply-To: <20261112075827.255602-1-hui.zhu@linux.dev>
On Thu, Nov 12, 2026 at 03:58:27PM +0800, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> lru_gen_change_state() migrates folios in batches of up to
> MAX_LRU_BATCH (4096) folios under lruvec_lock_irq(). A full batch
> keeps local interrupts off for up to about a millisecond, and CPUs
> contending for the same lru_lock spin with interrupts disabled for
> that long.
>
> The caller already reschedules between batches, but a batch itself
> only ends after 4096 folios. Stop it early when a resched is
> pending; the caller restarts the migration where it left off. A
> remote resched_curr() sets TIF_NEED_RESCHED directly in the target's
> thread_info, so the flag can still be set with interrupts off.
>
> This follows walk_pud_range(), which already pairs need_resched()
> with a MAX_LRU_BATCH cap, and commit 6e9be217a3ce ("mm/mglru: use a
> smaller batch for reclaim").
>
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
> mm/vmscan.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 6a1af9b92349..47f2cb25eb46 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -5533,7 +5533,8 @@ static bool fill_evictable(struct lruvec *lruvec)
> success = lru_gen_add_folio(lruvec, folio, !active);
> VM_WARN_ON_ONCE(!success);
>
> - if (!--remaining)
> + /* stop early to shorten the irq-off section */
> + if (!--remaining || need_resched())
Hi Hui,
I've been thinking about a different design, what if we just
delete the `--remaining` check completely, and check
spin_is_contended on the lruvec and need_resched()?
In the optimal case we don't need to keep lock/unlock the lruvec
at all so this is faster. And it still avoids lock contention or
blocked schedule, and it might be even more responsive as we are
release the lock earlier on contention.
next prev parent reply other threads:[~2026-11-12 8:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 7:58 [PATCH] mm/mglru: check need_resched() in fill/drain_evictable() Hui Zhu
2026-11-12 8:03 ` Kairui Song [this message]
2026-11-12 8:09 ` Michal Hocko
2026-11-12 8:58 ` Kairui Song
2026-11-12 9:01 ` Hui Zhu
2026-11-12 15:50 ` Kairui Song
2026-11-12 8:50 ` Kairui Song
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=avVx_1BEP7fIzGDK@KASONG-MC4 \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hui.zhu@linux.dev \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=zhuhui@kylinos.cn \
/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