From: Shakeel Butt <shakeel.butt@linux.dev>
To: kasong@tencent.com
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
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>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Chris Li <chrisl@kernel.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Ridong Chen <ridong.chen@linux.dev>,
Lian Wang <lianux.mm@gmail.com>, Yu Zhao <yuzhao@google.com>,
Zi Yan <ziy@nvidia.com>, Qi Zheng <qi.zheng@linux.dev>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Kairui Song <ryncsn@gmail.com>
Subject: Re: [PATCH v5 1/6] mm/memcontrol: move the lru_zone_size sanity check to the reader side
Date: Wed, 2 Sep 2026 08:42:07 -0700 [thread overview]
Message-ID: <aphDtvu4xDCW3cOK@linux.dev> (raw)
In-Reply-To: <20260902-mglru-flags-cleanup-v5-1-9db761d779ef@tencent.com>
On Wed, Sep 02, 2026 at 05:50:54PM +0800, Kairui Song via B4 Relay wrote:
> From: Kairui Song <kasong@tencent.com>
>
> Instead of using an unsigned long and checking the counter value at
> the updater side, turn the counter into a signed long and check at the
> reader side. This reduces overhead and simplifies the code.
>
> commit ca707239e8a7 ("mm: update_lru_size warn and reset bad lru_size")
> added a sanity check for memcg counter underflow: lru_zone_size is
> unsigned, so an underflow wraps it around and returns an enormously
> large number, then the memcg shrinker loops almost forever as the
> calculated number of folios to shrink is huge. It also checked if a
> zero value matches the empty LRU list, so the positive and negative
> deltas had to be handled separately. However that emptiness check was
> already removed by commit b4536f0c829c ("mm, memcg: fix the active list
> aging for lowmem requests when memcg is enabled"), so handling the
> deltas separately is no longer needed.
>
> The remaining update-side check is costly and cannot really catch the
> leak it is after anyway. It runs on every LRU folio, and if a folio was
> removed without updating the counter while other folios remain on the
> LRU, the WARN only triggers much later, from a likely innocent
> callsite. While readers are much rarer than writers, only the reclaim
> and reparenting paths read it, once per batch.
>
> Checking at the reader side instead leaves the update path a plain
> addition, and puts the warning where the value is actually consumed.
>
> Note this changes the behavior on underflow: the correction is removed
> and a negative value is kept. A massive leak of the LRU size counter
> would indicate that something else has gone very wrong, and one should
> fix that leaking site instead. Besides, the original behavior might
> cause false positives, or make things worse if the accounting happens
> after the actual insertion: the value is not leaked, just delayed, so
> force-fixing it would cause a bigger problem. The warning now only kicks
> in when a consumer actually uses it, in which case the reader gets zero.
>
> Reviewed-by: Ridong Chen <ridong.chen@linux.dev>
> Reviewed-by: Barry Song <baohua@kernel.org>
> Signed-off-by: Kairui Song <kasong@tencent.com>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
next prev parent reply other threads:[~2026-09-02 15:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 9:50 [PATCH v5 0/6] mm/mglru: clean up folio counters and flag usage Kairui Song via B4 Relay
2026-09-02 9:50 ` Kairui Song
2026-09-02 9:50 ` [PATCH v5 1/6] mm/memcontrol: move the lru_zone_size sanity check to the reader side Kairui Song via B4 Relay
2026-09-02 9:50 ` Kairui Song
2026-09-02 15:42 ` Shakeel Butt [this message]
2026-09-02 9:50 ` [PATCH v5 2/6] mm/mglru: introduce helpers for manipulating gen and refs flags Kairui Song via B4 Relay
2026-09-02 9:50 ` Kairui Song
2026-09-02 9:50 ` [PATCH v5 3/6] mm/migrate: copy all referenced state via folio_migrate_lru_refs Kairui Song via B4 Relay
2026-09-02 9:50 ` Kairui Song
2026-09-02 9:50 ` [PATCH v5 4/6] mm/mglru: move max_seq read into walk_update_folio Kairui Song via B4 Relay
2026-09-02 9:50 ` Kairui Song
2026-09-02 9:50 ` [PATCH v5 5/6] mm/mglru: use explicit tier range in read_ctrl_pos() Kairui Song via B4 Relay
2026-09-02 9:50 ` Kairui Song
2026-09-02 9:50 ` [PATCH v5 6/6] mm/mglru: fix potential generation folio number leak Kairui Song via B4 Relay
2026-09-02 9:50 ` Kairui Song
2026-09-03 6:42 ` Barry Song
2026-09-02 21:11 ` [PATCH v5 0/6] mm/mglru: clean up folio counters and flag usage Andrew Morton
2026-09-02 22:31 ` Barry Song (Xiaomi)
2026-09-03 2:48 ` Kairui Song
2026-09-03 2:21 ` 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=aphDtvu4xDCW3cOK@linux.dev \
--to=shakeel.butt@linux.dev \
--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=cgroups@vger.kernel.org \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=qi.zheng@linux.dev \
--cc=ridong.chen@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=ryncsn@gmail.com \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=yuzhao@google.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 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.