Skip to content

Commit e244c9e

Browse files
rientjestorvalds
authored andcommitted
mm, mempool: disallow mempools based on slab caches with constructors
All occurrences of mempools based on slab caches with object constructors have been removed from the tree, so disallow creating them. We can only dereference mem->ctor in mm/mempool.c without including mm/slab.h in include/linux/mempool.h. So simply note the restriction, just like the comment restricting usage of __GFP_ZERO, and warn on kernels with CONFIG_DEBUG_VM() if such a mempool is allocated from. We don't want to incur this check on every element allocation, so use VM_BUG_ON(). Signed-off-by: David Rientjes <rientjes@google.com> Cc: Dave Kleikamp <shaggy@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Sebastian Ott <sebott@linux.vnet.ibm.com> Cc: Mikulas Patocka <mpatocka@redhat.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ee14624 commit e244c9e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

include/linux/mempool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ extern void mempool_free(void *element, mempool_t *pool);
3636

3737
/*
3838
* A mempool_alloc_t and mempool_free_t that get the memory from
39-
* a slab that is passed in through pool_data.
39+
* a slab cache that is passed in through pool_data.
40+
* Note: the slab cache may not have a ctor function.
4041
*/
4142
void *mempool_alloc_slab(gfp_t gfp_mask, void *pool_data);
4243
void mempool_free_slab(void *element, void *pool_data);

mm/mempool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/mempool.h>
1616
#include <linux/blkdev.h>
1717
#include <linux/writeback.h>
18+
#include "slab.h"
1819

1920
static void add_element(mempool_t *pool, void *element)
2021
{
@@ -334,6 +335,7 @@ EXPORT_SYMBOL(mempool_free);
334335
void *mempool_alloc_slab(gfp_t gfp_mask, void *pool_data)
335336
{
336337
struct kmem_cache *mem = pool_data;
338+
VM_BUG_ON(mem->ctor);
337339
return kmem_cache_alloc(mem, gfp_mask);
338340
}
339341
EXPORT_SYMBOL(mempool_alloc_slab);

0 commit comments

Comments
 (0)