Re: [PATCH 1/5] mm: memcg: factor out trylock_stock() and unlock_stock()
From: Johannes Weiner
Date: Thu Mar 05 2026 - 08:09:26 EST
On Tue, Mar 03, 2026 at 10:23:54AM +0100, Vlastimil Babka (SUSE) wrote:
> 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>
Thanks!
> 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.
Oops, I almost missed that, but that sounds good to me.
Andrew, would you mind folding this in?
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 36612175e98e..178be98f2e49 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3160,7 +3160,7 @@ void __memcg_kmem_uncharge_page(struct page *page, int order)
obj_cgroup_put(objcg);
}
-static struct obj_stock_pcp *trylock_stock(void)
+static inline struct obj_stock_pcp *trylock_stock(void)
{
if (local_trylock(&obj_stock.lock))
return this_cpu_ptr(&obj_stock);
@@ -3168,7 +3168,7 @@ static struct obj_stock_pcp *trylock_stock(void)
return NULL;
}
-static void unlock_stock(struct obj_stock_pcp *stock)
+static inline void unlock_stock(struct obj_stock_pcp *stock)
{
if (stock)
local_unlock(&obj_stock.lock);