Re: [PATCH] memcg: multi-memcg percpu charge cache

Jakub Kicinski
2025-04-23T01:10:24Z

On Wed, 16 Apr 2025 11:02:29 -0700 Shakeel Butt wrote:
> static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
> {
> struct memcg_stock_pcp *stock;
> - unsigned int stock_pages;
> + struct mem_cgroup *cached;
> + uint8_t stock_pages;

Is it okay to use uintX_t now?

> unsigned long flags;
> + bool evict = true;
> + int i;
>
> VM_WARN_ON_ONCE(mem_cgroup_is_root(memcg));
>
> - 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'

> memcg_uncharge(memcg, nr_pages);
> return;
> }

nits notwithstanding:

Acked-by: Jakub Kicinski <kuba@kernel.org>

Thanks!