Skip to content

Commit

Permalink
slub: adjust memcg caches when creating cache alias
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vladimir Davydov authored and Linus Torvalds committed Apr 7, 2014
1 parent b852990 commit 84d0ddd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -3748,14 +3748,27 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,

s = find_mergeable(size, align, flags, name, ctor);
if (s) {
int i;
struct kmem_cache *c;

s->refcount++;

/*
* Adjust the object sizes so that we clear
* the complete object on kzalloc.
*/
s->object_size = max(s->object_size, (int)size);
s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));

for_each_memcg_cache_index(i) {
c = cache_from_memcg_idx(s, i);
if (!c)
continue;
c->object_size = s->object_size;
c->inuse = max_t(int, c->inuse,
ALIGN(size, sizeof(void *)));
}

if (sysfs_slab_alias(s, name)) {
s->refcount--;
s = NULL;
Expand Down

0 comments on commit 84d0ddd

Please sign in to comment.