Commit a822c83e authored by Joe Thornber's avatar Joe Thornber Committed by Mike Snitzer

dm thin: allocate the cell_sort_array dynamically

Given the pool's cell_sort_array holds 8192 pointers it triggers an
order 5 allocation via kmalloc.  This order 5 allocation is prone to
failure as system memory gets more fragmented over time.

Fix this by allocating the cell_sort_array using vmalloc.
Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org
parent 4c7e3093
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/sort.h> #include <linux/sort.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
...@@ -268,7 +269,7 @@ struct pool { ...@@ -268,7 +269,7 @@ struct pool {
process_mapping_fn process_prepared_mapping; process_mapping_fn process_prepared_mapping;
process_mapping_fn process_prepared_discard; process_mapping_fn process_prepared_discard;
struct dm_bio_prison_cell *cell_sort_array[CELL_SORT_ARRAY_SIZE]; struct dm_bio_prison_cell **cell_sort_array;
}; };
static enum pool_mode get_pool_mode(struct pool *pool); static enum pool_mode get_pool_mode(struct pool *pool);
...@@ -2777,6 +2778,7 @@ static void __pool_destroy(struct pool *pool) ...@@ -2777,6 +2778,7 @@ static void __pool_destroy(struct pool *pool)
{ {
__pool_table_remove(pool); __pool_table_remove(pool);
vfree(pool->cell_sort_array);
if (dm_pool_metadata_close(pool->pmd) < 0) if (dm_pool_metadata_close(pool->pmd) < 0)
DMWARN("%s: dm_pool_metadata_close() failed.", __func__); DMWARN("%s: dm_pool_metadata_close() failed.", __func__);
...@@ -2889,6 +2891,13 @@ static struct pool *pool_create(struct mapped_device *pool_md, ...@@ -2889,6 +2891,13 @@ static struct pool *pool_create(struct mapped_device *pool_md,
goto bad_mapping_pool; goto bad_mapping_pool;
} }
pool->cell_sort_array = vmalloc(sizeof(*pool->cell_sort_array) * CELL_SORT_ARRAY_SIZE);
if (!pool->cell_sort_array) {
*error = "Error allocating cell sort array";
err_p = ERR_PTR(-ENOMEM);
goto bad_sort_array;
}
pool->ref_count = 1; pool->ref_count = 1;
pool->last_commit_jiffies = jiffies; pool->last_commit_jiffies = jiffies;
pool->pool_md = pool_md; pool->pool_md = pool_md;
...@@ -2897,6 +2906,8 @@ static struct pool *pool_create(struct mapped_device *pool_md, ...@@ -2897,6 +2906,8 @@ static struct pool *pool_create(struct mapped_device *pool_md,
return pool; return pool;
bad_sort_array:
mempool_destroy(pool->mapping_pool);
bad_mapping_pool: bad_mapping_pool:
dm_deferred_set_destroy(pool->all_io_ds); dm_deferred_set_destroy(pool->all_io_ds);
bad_all_io_ds: bad_all_io_ds:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment