aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/slub_def.h1
-rw-r--r--mm/slub.c14
2 files changed, 13 insertions, 2 deletions
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index f74716b59ce2..d65159d1d4f5 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -16,6 +16,7 @@ struct kmem_cache_cpu {
16 struct page *page; 16 struct page *page;
17 int node; 17 int node;
18 unsigned int offset; 18 unsigned int offset;
19 unsigned int objsize;
19}; 20};
20 21
21struct kmem_cache_node { 22struct kmem_cache_node {
diff --git a/mm/slub.c b/mm/slub.c
index 6d4346ba0c29..1d48f383e97d 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1576,7 +1576,7 @@ static void __always_inline *slab_alloc(struct kmem_cache *s,
1576 local_irq_restore(flags); 1576 local_irq_restore(flags);
1577 1577
1578 if (unlikely((gfpflags & __GFP_ZERO) && object)) 1578 if (unlikely((gfpflags & __GFP_ZERO) && object))
1579 memset(object, 0, s->objsize); 1579 memset(object, 0, c->objsize);
1580 1580
1581 return object; 1581 return object;
1582} 1582}
@@ -1858,8 +1858,9 @@ static void init_kmem_cache_cpu(struct kmem_cache *s,
1858{ 1858{
1859 c->page = NULL; 1859 c->page = NULL;
1860 c->freelist = NULL; 1860 c->freelist = NULL;
1861 c->offset = s->offset / sizeof(void *);
1862 c->node = 0; 1861 c->node = 0;
1862 c->offset = s->offset / sizeof(void *);
1863 c->objsize = s->objsize;
1863} 1864}
1864 1865
1865static void init_kmem_cache_node(struct kmem_cache_node *n) 1866static void init_kmem_cache_node(struct kmem_cache_node *n)
@@ -2852,12 +2853,21 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
2852 down_write(&slub_lock); 2853 down_write(&slub_lock);
2853 s = find_mergeable(size, align, flags, name, ctor); 2854 s = find_mergeable(size, align, flags, name, ctor);
2854 if (s) { 2855 if (s) {
2856 int cpu;
2857
2855 s->refcount++; 2858 s->refcount++;
2856 /* 2859 /*
2857 * Adjust the object sizes so that we clear 2860 * Adjust the object sizes so that we clear
2858 * the complete object on kzalloc. 2861 * the complete object on kzalloc.
2859 */ 2862 */
2860 s->objsize = max(s->objsize, (int)size); 2863 s->objsize = max(s->objsize, (int)size);
2864
2865 /*
2866 * And then we need to update the object size in the
2867 * per cpu structures
2868 */
2869 for_each_online_cpu(cpu)
2870 get_cpu_slab(s, cpu)->objsize = s->objsize;
2861 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *))); 2871 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
2862 up_write(&slub_lock); 2872 up_write(&slub_lock);
2863 if (sysfs_slab_alias(s, name)) 2873 if (sysfs_slab_alias(s, name))