On Tue, Mar 12, 2024 at 06:59:37PM +0000, Matthew Wilcox wrote: > On Tue, Mar 12, 2024 at 11:52:46AM -0700, Roman Gushchin wrote: > > On Fri, Mar 01, 2024 at 06:07:08PM +0100, Vlastimil Babka wrote: > > > @@ -1926,71 +1939,51 @@ static bool __memcg_slab_pre_alloc_hook(struct kmem_cache *s, > > > return false; > > > } > > > > > > - if (obj_cgroup_charge(objcg, flags, objects * obj_full_size(s))) > > > + if (obj_cgroup_charge(objcg, flags, size * obj_full_size(s))) > > > return false; > > > > > > - *objcgp = objcg; > > > + for (i = 0; i < size; i++) { > > > + slab = virt_to_slab(p[i]); > > > > Not specific to this change, but I wonder if it makes sense to introduce virt_to_slab() > > variant without any extra checks for this and similar cases, where we know for sure > > that p resides on a slab page. What do you think? > > You'd only save a single test_bit() ... is it really worth doing? > Cache misses are the expensive thing, not instructions. I agree here, unlikely it will produce a significant difference. > And debugging > time: if somehow p[i] becomes not-on-a-slab-anymore, getting a NULL > pointer splat here before we go any further might be worth all the CPU > time wasted doing that test_bit(). Well, Idk if it's a feasible concern here, hard to imagine how p[i] wouldn't belong to a slab page without something like a major memory corruption. Overall I agree it's not a big deal and the current code is fine. Thanks!