[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <agazegt7js4jrbbng2di33xggfswxgrdrojoiqh4vaqxxmdidj@zmyzkgfuhykl>
Date: Wed, 23 Apr 2025 15:59:18 -0700
From: Shakeel Butt <shakeel.butt@...ux.dev>
To: Jakub Kicinski <kuba@...nel.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Johannes Weiner <hannes@...xchg.org>, Michal Hocko <mhocko@...nel.org>,
Roman Gushchin <roman.gushchin@...ux.dev>, Muchun Song <muchun.song@...ux.dev>,
Vlastimil Babka <vbabka@...e.cz>, Eric Dumazet <edumazet@...gle.com>,
Soheil Hassas Yeganeh <soheil@...gle.com>, linux-mm@...ck.org, cgroups@...r.kernel.org,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
Meta kernel team <kernel-team@...a.com>
Subject: Re: [PATCH] memcg: multi-memcg percpu charge cache
On Wed, Apr 23, 2025 at 03:30:46PM -0700, Jakub Kicinski wrote:
> On Wed, 23 Apr 2025 15:16:56 -0700 Shakeel Butt wrote:
> > > > - if (!local_trylock_irqsave(&memcg_stock.stock_lock, flags)) {
> > > > + if (nr_pages > MEMCG_CHARGE_BATCH ||
> > > > + !local_trylock_irqsave(&memcg_stock.stock_lock, flags)) {
> > > > /*
> > > > - * In case of unlikely failure to lock percpu stock_lock
> > > > - * uncharge memcg directly.
> > > > + * In case of larger than batch refill or unlikely failure to
> > > > + * lock the percpu stock_lock, uncharge memcg directly.
> > > > */
> > >
> > > We're bypassing the cache for > CHARGE_BATCH because the u8 math
> > > may overflow? Could be useful to refocus the comment on the 'why'
> >
> > We actually never put more than MEMCG_CHARGE_BATCH in the cache and thus
> > we can use u8 as type here. Though we may increase the batch size in
> > future, so I should put a BUILD_BUG_ON somewhere here.
>
> No idea if this matters enough to deserve its own commit but basically
> I was wondering if that behavior change is a separate optimization.
>
> Previously we'd check if the cache was for the releasing cgroup and sum
> was over BATCH - drain its stock completely. Now we bypass looking at
> the cache if nr_pages > BATCH so the cgroup may retain some stock.
Yes indeed there is a little bit behavior change as you have explained.
The older behavior (fully drain if nr_pages > BATCH) might be due to
single per-cpu memcg cache limitation and in my opinion is problematic
in some scenarios. If you see commit 5387c90490f7 ("mm/memcg: improve
refill_obj_stock() performance"), a very similar behavior for objcg
cache was having a performance impact and was optimized by only allowing
the drain for some code paths. With multi-memcg support, I think we
don't need to worry about it. Multi-objcg per-cpu cache is also on my
TODO list.
Powered by blists - more mailing lists