Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mempool: kvmalloc pool

Add mempool_init_kvmalloc_pool() and mempool_create_kvmalloc_pool(),
which wrap kvmalloc() instead of kmalloc() - kmalloc() with a vmalloc()
fallback.

This is part of a bcachefs cleanup - dropping an internal kvpmalloc()
helper (which predates kvmalloc()) along with mempool helpers; this
replaces the bcachefs-private kvpmalloc_pool.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-mm@kvack.org

+26
+13
include/linux/mempool.h
··· 95 95 (void *) size); 96 96 } 97 97 98 + void *mempool_kvmalloc(gfp_t gfp_mask, void *pool_data); 99 + void mempool_kvfree(void *element, void *pool_data); 100 + 101 + static inline int mempool_init_kvmalloc_pool(mempool_t *pool, int min_nr, size_t size) 102 + { 103 + return mempool_init(pool, min_nr, mempool_kvmalloc, mempool_kvfree, (void *) size); 104 + } 105 + 106 + static inline mempool_t *mempool_create_kvmalloc_pool(int min_nr, size_t size) 107 + { 108 + return mempool_create(min_nr, mempool_kvmalloc, mempool_kvfree, (void *) size); 109 + } 110 + 98 111 /* 99 112 * A mempool_alloc_t and mempool_free_t for a simple page allocator that 100 113 * allocates pages of the order specified by pool_data
+13
mm/mempool.c
··· 590 590 } 591 591 EXPORT_SYMBOL(mempool_kfree); 592 592 593 + void *mempool_kvmalloc(gfp_t gfp_mask, void *pool_data) 594 + { 595 + size_t size = (size_t)pool_data; 596 + return kvmalloc(size, gfp_mask); 597 + } 598 + EXPORT_SYMBOL(mempool_kvmalloc); 599 + 600 + void mempool_kvfree(void *element, void *pool_data) 601 + { 602 + kvfree(element); 603 + } 604 + EXPORT_SYMBOL(mempool_kvfree); 605 + 593 606 /* 594 607 * A simple mempool-backed page allocator that allocates pages 595 608 * of the order specified by pool_data.