Skip to content

Commit 84d0ddd

Browse files
Vladimir Davydovtorvalds
authored andcommitted
slub: adjust memcg caches when creating cache alias
Otherwise, kzalloc() called from a memcg won't clear the whole object. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Cc: Michal Hocko <mhocko@suse.cz> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: David Rientjes <rientjes@google.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Glauber Costa <glommer@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b852990 commit 84d0ddd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

mm/slub.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3748,14 +3748,27 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
37483748

37493749
s = find_mergeable(size, align, flags, name, ctor);
37503750
if (s) {
3751+
int i;
3752+
struct kmem_cache *c;
3753+
37513754
s->refcount++;
3755+
37523756
/*
37533757
* Adjust the object sizes so that we clear
37543758
* the complete object on kzalloc.
37553759
*/
37563760
s->object_size = max(s->object_size, (int)size);
37573761
s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
37583762

3763+
for_each_memcg_cache_index(i) {
3764+
c = cache_from_memcg_idx(s, i);
3765+
if (!c)
3766+
continue;
3767+
c->object_size = s->object_size;
3768+
c->inuse = max_t(int, c->inuse,
3769+
ALIGN(size, sizeof(void *)));
3770+
}
3771+
37593772
if (sysfs_slab_alias(s, name)) {
37603773
s->refcount--;
37613774
s = NULL;

0 commit comments

Comments
 (0)