Re: [PATCH 1/5] mm: memcg: factor out trylock_stock() and unlock_stock()
From: Vlastimil Babka (SUSE)
Date: Tue Mar 03 2026 - 04:24:54 EST
On 3/2/26 20:50, Johannes Weiner wrote:
> From: Johannes Weiner <jweiner@xxxxxxxx>
>
> Consolidate the local lock acquisition and the local stock
> lookup. This allows subsequent patches to use !!stock as an easy way
> to disambiguate the locked vs. contended cases through the callstack.
>
> Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
nit:
> ---
> mm/memcontrol.c | 25 +++++++++++++++++++------
> 1 file changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 753d76e96cc6..a975ab3aee10 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3208,6 +3208,19 @@ void __memcg_kmem_uncharge_page(struct page *page, int order)
> obj_cgroup_put(objcg);
> }
>
> +static struct obj_stock_pcp *trylock_stock(void)
> +{
> + if (local_trylock(&obj_stock.lock))
> + return this_cpu_ptr(&obj_stock);
> +
> + return NULL;
> +}
> +
> +static void unlock_stock(struct obj_stock_pcp *stock)
> +{
> + local_unlock(&obj_stock.lock);
> +}
Could have added inline's there. The compiler heuristics can be sometimes
unpredictable.