From: Harry Yoo <harry@kernel.org>
To: Qi Zheng <qi.zheng@linux.dev>,
akpm@linux-foundation.org, david@kernel.org, kasong@tencent.com,
shakeel.butt@linux.dev, baohua@kernel.org,
axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
hannes@cmpxchg.org, muchun.song@linux.dev,
peiyang_he@smail.nju.edu.cn, mhocko@kernel.org,
roman.gushchin@linux.dev, ljs@kernel.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Qi Zheng <zhengqi.arch@bytedance.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v2] mm: mglru: fix stale batch updates after memcg reparenting
Date: Thu, 25 Jun 2026 15:32:17 +0900 [thread overview]
Message-ID: <1d78e1c1-0cdb-435e-b278-670bce9148b3@kernel.org> (raw)
In-Reply-To: <f18bf1b1-ccf7-4d77-9389-07311d2d1613@linux.dev>
[-- Attachment #1.1: Type: text/plain, Size: 2045 bytes --]
On 6/25/26 3:11 PM, Qi Zheng wrote:
> On 6/25/26 12:16 PM, Harry Yoo wrote:
>>
> [...]
>
>>
>>> So lock_batch_lruvec() can be implemented like this:
>>>
>>> #ifdef CONFIG_MEMCG
>>> static struct lruvec *lock_batch_lruvec(struct lruvec *lruvec)
>>> {
>>> struct pglist_data *pgdat = lruvec_pgdat(lruvec);
>>> struct mem_cgroup *memcg = lruvec_memcg(lruvec);
>>>
>>> rcu_read_lock();
>>>
>>> /*
>>> * The memcg can be NULL when the memory controller is disabled.
>>> * Otherwise, the caller keeps the memcg owning @lruvec alive.
>>> */
>>> if (!memcg || !css_is_dying(&memcg->css))
>>> goto lock;
>>>
>>> do {
>>> memcg = parent_mem_cgroup(memcg);
>>> } while (memcg && css_is_dying(&memcg->css));
>>> lruvec = mem_cgroup_lruvec(memcg, pgdat);
>>>
>>> lock:
>>> spin_lock_irq(&lruvec->lru_lock);
>>>
>>> return lruvec;
>>> }
>>> #else
>>> static struct lruvec *lock_batch_lruvec(struct lruvec *lruvec)
>>> {
>>> lruvec_lock_irq(lruvec);
>>>
>>> return lruvec;
>>> }
>>> #endif
>>>
>>> Does this make sense?
>>
>> Yes, looks good to me!
>
> OK, this sync method makes more sense as it doesn't require adding a
> new lrugen->reparente. I'll go with this method and update v3.
Thanks!
Just one thing to clarify...
So, when we check something that's updated _before_ grace period
(CSS_DYING), RCU is sufficient.
But in folio_lruvec_lock*(), that is not the case because reparenting
is performed in the RCU work, under the lruvec lock. So the check needs
to be done under RCU and the lruvec lock.
This is quite subtle :D
> Hi Barry and Baolin, what do you think? Since the sync method has been
> changed, I will temporarily drop your previous Reviewed-by tags in v3. ;)
And hopefully Peiyang would kindly double check v3 still not reproduced
on the machine :)
--
Cheers,
Harry / Hyeonggon
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-06-25 6:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 2:42 [PATCH v2] mm: mglru: fix stale batch updates after memcg reparenting Qi Zheng
2026-06-23 2:56 ` Qi Zheng
2026-06-23 4:03 ` Baolin Wang
2026-06-23 6:17 ` Harry Yoo
2026-06-23 7:16 ` Qi Zheng
2026-06-23 8:18 ` Harry Yoo
2026-06-23 9:14 ` Qi Zheng
2026-06-24 4:29 ` Harry Yoo
2026-06-24 7:11 ` Qi Zheng
2026-06-25 4:16 ` Harry Yoo
2026-06-25 6:11 ` Qi Zheng
2026-06-25 6:32 ` Harry Yoo [this message]
2026-06-25 7:37 ` Qi Zheng
2026-06-25 8:09 ` Peiyang He
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=1d78e1c1-0cdb-435e-b278-670bce9148b3@kernel.org \
--to=harry@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.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=peiyang_he@smail.nju.edu.cn \
--cc=qi.zheng@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=weixugc@google.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