[PATCH 5/7] mempool: separate out __mempool_create()

From: Tejun Heo
Date: Thu Dec 22 2011 - 16:46:52 EST


Separate out __mempool_create(), which handles creation of the mempool
without filling it, from mempool_create_node(). This will be used to
implemen percpu_mempool.

Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
---
mm/mempool.c | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/mm/mempool.c b/mm/mempool.c
index 4747283..85e2c28 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -104,11 +104,13 @@ mempool_t *mempool_create(int min_nr, mempool_alloc_t *alloc_fn,
}
EXPORT_SYMBOL(mempool_create);

-mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,
- mempool_free_t *free_fn, void *pool_data, int node_id)
+static mempool_t *__mempool_create(int min_nr, mempool_alloc_t *alloc_fn,
+ mempool_free_t *free_fn, void *pool_data,
+ int node_id, size_t mempool_bytes)
{
mempool_t *pool;
- pool = kmalloc_node(sizeof(*pool), GFP_KERNEL | __GFP_ZERO, node_id);
+
+ pool = kmalloc_node(mempool_bytes, GFP_KERNEL | __GFP_ZERO, node_id);
if (!pool)
return NULL;
pool->elements = kmalloc_node(min_nr * sizeof(void *),
@@ -124,9 +126,19 @@ mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,
pool->alloc = alloc_fn;
pool->free = free_fn;

- /*
- * First pre-allocate the guaranteed number of buffers.
- */
+ return pool;
+}
+
+mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,
+ mempool_free_t *free_fn, void *pool_data,
+ int node_id)
+{
+ mempool_t *pool;
+
+ pool = __mempool_create(min_nr, alloc_fn, free_fn, pool_data, node_id,
+ sizeof(*pool));
+
+ /* Pre-allocate the guaranteed number of buffers */
if (mempool_fill(pool, GFP_KERNEL)) {
mempool_destroy(pool);
return NULL;
--
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/