Skip to content

Commit 8174daf

Browse files
committed
Merge tag 'slab-for-7.0-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab
Pull slab fixes from Vlastimil Babka: - Fix for a memory leak that can occur when already so low on memory that we can't allocate a new slab anymore (Qing Wang) - Fix for a case where slabobj_ext array for a slab might be allocated from the same slab, making it permanently non-freeable (Harry Yoo) * tag 'slab-for-7.0-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab: slab: fix memory leak when refill_sheaf() fails mm/slab: fix an incorrect check in obj_exts_alloc_size()
2 parents 92e989a + 464b1c1 commit 8174daf

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

mm/slub.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,13 +2119,6 @@ static inline size_t obj_exts_alloc_size(struct kmem_cache *s,
21192119
size_t sz = sizeof(struct slabobj_ext) * slab->objects;
21202120
struct kmem_cache *obj_exts_cache;
21212121

2122-
/*
2123-
* slabobj_ext array for KMALLOC_CGROUP allocations
2124-
* are served from KMALLOC_NORMAL caches.
2125-
*/
2126-
if (!mem_alloc_profiling_enabled())
2127-
return sz;
2128-
21292122
if (sz > KMALLOC_MAX_CACHE_SIZE)
21302123
return sz;
21312124

@@ -2797,6 +2790,7 @@ static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf)
27972790
if (s->flags & SLAB_KMALLOC)
27982791
mark_obj_codetag_empty(sheaf);
27992792

2793+
VM_WARN_ON_ONCE(sheaf->size > 0);
28002794
kfree(sheaf);
28012795

28022796
stat(s, SHEAF_FREE);
@@ -2828,6 +2822,7 @@ static int refill_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf,
28282822
return 0;
28292823
}
28302824

2825+
static void sheaf_flush_unused(struct kmem_cache *s, struct slab_sheaf *sheaf);
28312826

28322827
static struct slab_sheaf *alloc_full_sheaf(struct kmem_cache *s, gfp_t gfp)
28332828
{
@@ -2837,6 +2832,7 @@ static struct slab_sheaf *alloc_full_sheaf(struct kmem_cache *s, gfp_t gfp)
28372832
return NULL;
28382833

28392834
if (refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
2835+
sheaf_flush_unused(s, sheaf);
28402836
free_empty_sheaf(s, sheaf);
28412837
return NULL;
28422838
}
@@ -4623,6 +4619,7 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
46234619
* we must be very low on memory so don't bother
46244620
* with the barn
46254621
*/
4622+
sheaf_flush_unused(s, empty);
46264623
free_empty_sheaf(s, empty);
46274624
}
46284625
} else {

0 commit comments

Comments
 (0)