[Devel] [PATCH VZ9 1/2] mempool: add kvmalloc/kvfree version
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Mon Nov 18 08:54:15 MSK 2024
We need it to amke a memory pool for 4M (10-th order) allocations. Due
to big allocation size it seems prudent to do it via vmalloc interface.
https://virtuozzo.atlassian.net/browse/VSTOR-94596
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
include/linux/mempool.h | 15 +++++++++++++++
mm/mempool.c | 13 +++++++++++++
2 files changed, 28 insertions(+)
diff --git a/include/linux/mempool.h b/include/linux/mempool.h
index 7bd58a0f6bb05..6b7ef339d4881 100644
--- a/include/linux/mempool.h
+++ b/include/linux/mempool.h
@@ -97,6 +97,21 @@ static inline mempool_t *mempool_create_kmalloc_pool(int min_nr, size_t size)
(void *) size);
}
+void *mempool_kvmalloc(gfp_t gfp_mask, void *pool_data);
+void mempool_kvfree(void *element, void *pool_data);
+
+static inline int mempool_init_kvmalloc_pool(mempool_t *pool, int min_nr, size_t size)
+{
+ return mempool_init(pool, min_nr, mempool_kvmalloc,
+ mempool_kvfree, (void *) size);
+}
+
+static inline mempool_t *mempool_create_kvmalloc_pool(int min_nr, size_t size)
+{
+ return mempool_create(min_nr, mempool_kvmalloc, mempool_kvfree,
+ (void *) size);
+}
+
/*
* A mempool_alloc_t and mempool_free_t for a simple page allocator that
* allocates pages of the order specified by pool_data
diff --git a/mm/mempool.c b/mm/mempool.c
index 9da0cd72bd190..06be37a711d9b 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -539,6 +539,19 @@ void mempool_kfree(void *element, void *pool_data)
}
EXPORT_SYMBOL(mempool_kfree);
+void *mempool_kvmalloc(gfp_t gfp_mask, void *pool_data)
+{
+ size_t size = (size_t)pool_data;
+ return kvmalloc(size, gfp_mask);
+}
+EXPORT_SYMBOL(mempool_kvmalloc);
+
+void mempool_kvfree(void *element, void *pool_data)
+{
+ kvfree(element);
+}
+EXPORT_SYMBOL(mempool_kvfree);
+
/*
* A simple mempool-backed page allocator that allocates pages
* of the order specified by pool_data.
--
2.47.0
More information about the Devel
mailing list