Re: [PATCH] memcg: consolidate private id refcount get/put helpers
From: Johannes Weiner
Date: Fri Feb 13 2026 - 15:09:16 EST
On Fri, Feb 13, 2026 at 06:03:32PM +0800, Kairui Song wrote:
> From: Kairui Song <kasong@xxxxxxxxxxx>
>
> We currently have two different sets of helpers for getting or putting
> the private IDs' refcount for order 0 and large folios. This is
> redundant. Just use one and always acquire the refcount of the swapout
> folio size unless it's zero, and put the refcount using the folio size
> if the charge failed, since the folio size can't change. Then there is
> no need to update the refcount for tail pages.
>
> Same for freeing, then only one pair of get/put helper is needed now.
>
> The performance might be slightly better, too: both "inc unless zero"
> and "add unless zero" use the same cmpxchg implementation. For large
> folios, we saved an atomic operation. And for both order 0 and large
> folios, we saved a branch.
>
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
Nice improvement!
Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>