aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-cache-target.c
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2014-11-11 06:58:32 -0500
committerMike Snitzer <snitzer@redhat.com>2014-11-12 20:14:59 -0500
commitd1d9220cbaeecce910f3ecfeb71cc897a678eb68 (patch)
tree5bdc1b75df308bc21321292d33fb956b0a9998cc /drivers/md/dm-cache-target.c
parent7ae34e7778966d39f66397491eb114b613202c20 (diff)
dm cache: emit a warning message if there are a lot of cache blocks
Loading and saving millions of block mappings takes time. We may as well explain what's going on, and encourage people to use a larger cache block size. Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/dm-cache-target.c')
-rw-r--r--drivers/md/dm-cache-target.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 6e36a0753105..abdd45d07bf6 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -2301,6 +2301,19 @@ static sector_t calculate_discard_block_size(sector_t cache_block_size,
2301 return discard_block_size; 2301 return discard_block_size;
2302} 2302}
2303 2303
2304static void set_cache_size(struct cache *cache, dm_cblock_t size)
2305{
2306 dm_block_t nr_blocks = from_cblock(size);
2307
2308 if (nr_blocks > (1 << 20) && cache->cache_size != size)
2309 DMWARN_LIMIT("You have created a cache device with a lot of individual cache blocks (%llu)\n"
2310 "All these mappings can consume a lot of kernel memory, and take some time to read/write.\n"
2311 "Please consider increasing the cache block size to reduce the overall cache block count.",
2312 (unsigned long long) nr_blocks);
2313
2314 cache->cache_size = size;
2315}
2316
2304#define DEFAULT_MIGRATION_THRESHOLD 2048 2317#define DEFAULT_MIGRATION_THRESHOLD 2048
2305 2318
2306static int cache_create(struct cache_args *ca, struct cache **result) 2319static int cache_create(struct cache_args *ca, struct cache **result)
@@ -2356,10 +2369,10 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2356 2369
2357 cache->sectors_per_block_shift = -1; 2370 cache->sectors_per_block_shift = -1;
2358 cache_size = block_div(cache_size, ca->block_size); 2371 cache_size = block_div(cache_size, ca->block_size);
2359 cache->cache_size = to_cblock(cache_size); 2372 set_cache_size(cache, to_cblock(cache_size));
2360 } else { 2373 } else {
2361 cache->sectors_per_block_shift = __ffs(ca->block_size); 2374 cache->sectors_per_block_shift = __ffs(ca->block_size);
2362 cache->cache_size = to_cblock(ca->cache_sectors >> cache->sectors_per_block_shift); 2375 set_cache_size(cache, to_cblock(ca->cache_sectors >> cache->sectors_per_block_shift));
2363 } 2376 }
2364 2377
2365 r = create_cache_policy(cache, ca, error); 2378 r = create_cache_policy(cache, ca, error);
@@ -2856,7 +2869,7 @@ static int resize_cache_dev(struct cache *cache, dm_cblock_t new_size)
2856 return r; 2869 return r;
2857 } 2870 }
2858 2871
2859 cache->cache_size = new_size; 2872 set_cache_size(cache, new_size);
2860 2873
2861 return 0; 2874 return 0;
2862} 2875}