Re: [PATCH RFC 05/12] mm/slab: abstract slabobj_ext.objcg access
"Vlastimil Babka (SUSE)" <[email protected]>
| Newsgroups | org.kernel.vger.cgroups,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
On 7/16/26 03:27, Suren Baghdasaryan wrote: > On Wed, Jul 15, 2026 at 3:11 AM Vlastimil Babka (SUSE) > <[email protected]> wrote: >> --- a/mm/slab.h >> +++ b/mm/slab.h >> @@ -555,7 +555,7 @@ static inline bool need_kmalloc_no_objext(void) >> */ >> struct slabobj_ext { >> #ifdef CONFIG_MEMCG >> - struct obj_cgroup *objcg; >> + struct obj_cgroup *_objcg; >> #endif >> #ifdef CONFIG_MEM_ALLOC_PROFILING >> union codetag_ref ref; >> @@ -661,6 +661,13 @@ slab_obj_ext(struct kmem_cache *s, struct slab *slab, unsigned long obj_exts, >> return kasan_reset_tag(obj_ext); >> } >> >> +#ifdef CONFIG_MEMCG >> +static inline struct obj_cgroup **slab_obj_ext_objcgp(struct slabobj_ext *obj_ext) > > I understand why you need to return obj_cgroup** but maybe instead we > can have a separate setter function and just return a pointer here? Yeah I rewrote it now and it looks better. Thanks! It ended up like this due to some previous attempt I made. > That would also help catch cases when someone wants to set > obj_ext._objcg that was optimized away (for that the setter would need > an additional parameter to identify whether we allocated optimized > objext vector). It would need passing the slab parameter to assert slab_obj_ext_has_codetag() in debug mode. I don't think it's worth it given the get/set is only called from few specialized places. > >> +{ >> + return &obj_ext->_objcg; >> +} >> +#endif >> + >> int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, >> gfp_t gfp, unsigned int alloc_flags); >> >> diff --git a/mm/slub.c b/mm/slub.c >> index 5e3f53bcd0d3..48e10198a3ce 100644 >> --- a/mm/slub.c >> +++ b/mm/slub.c >> @@ -2523,7 +2523,7 @@ bool memcg_slab_post_charge(void *p, gfp_t flags) >> if (obj_exts) { >> get_slab_obj_exts(obj_exts); >> obj_ext = slab_obj_ext(s, slab, obj_exts, p); >> - if (unlikely(obj_ext->objcg)) { >> + if (unlikely(*slab_obj_ext_objcgp(obj_ext))) { >> put_slab_obj_exts(obj_exts); >> return true; >> } >> >> -- >> 2.55.0 >>