Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 283028
b: refs/heads/master
c: 0565d31
h: refs/heads/master
v: v3
  • Loading branch information
Tejun Heo authored and Linus Torvalds committed Jan 11, 2012
1 parent 61c3cfb commit 4bb7efc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5b990546e33477c34ee6fbc20fad6584386b46c3
refs/heads/master: 0565d317768cc66b13e37184f29d9f270c2886dc
30 changes: 11 additions & 19 deletions trunk/mm/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ static void *remove_element(mempool_t *pool)
return pool->elements[--pool->curr_nr];
}

static void free_pool(mempool_t *pool)
/**
* mempool_destroy - deallocate a memory pool
* @pool: pointer to the memory pool which was allocated via
* mempool_create().
*
* Free all reserved elements in @pool and @pool itself. This function
* only sleeps if the free_fn() function sleeps.
*/
void mempool_destroy(mempool_t *pool)
{
while (pool->curr_nr) {
void *element = remove_element(pool);
Expand All @@ -36,6 +44,7 @@ static void free_pool(mempool_t *pool)
kfree(pool->elements);
kfree(pool);
}
EXPORT_SYMBOL(mempool_destroy);

/**
* mempool_create - create a memory pool
Expand Down Expand Up @@ -86,7 +95,7 @@ mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,

element = pool->alloc(GFP_KERNEL, pool->pool_data);
if (unlikely(!element)) {
free_pool(pool);
mempool_destroy(pool);
return NULL;
}
add_element(pool, element);
Expand Down Expand Up @@ -171,23 +180,6 @@ int mempool_resize(mempool_t *pool, int new_min_nr, gfp_t gfp_mask)
}
EXPORT_SYMBOL(mempool_resize);

/**
* mempool_destroy - deallocate a memory pool
* @pool: pointer to the memory pool which was allocated via
* mempool_create().
*
* this function only sleeps if the free_fn() function sleeps. The caller
* has to guarantee that all elements have been returned to the pool (ie:
* freed) prior to calling mempool_destroy().
*/
void mempool_destroy(mempool_t *pool)
{
/* Check for outstanding elements */
BUG_ON(pool->curr_nr != pool->min_nr);
free_pool(pool);
}
EXPORT_SYMBOL(mempool_destroy);

/**
* mempool_alloc - allocate an element from a specific memory pool
* @pool: pointer to the memory pool which was allocated via
Expand Down

0 comments on commit 4bb7efc

Please sign in to comment.