aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2015-01-23 05:16:16 -0500
committerMike Snitzer <snitzer@redhat.com>2015-01-23 11:06:08 -0500
commita59db67656021fa212e9b95a583f13c34eb67cd9 (patch)
tree6a9d52eb5cb2fc1db677636431e56e1797859a6c /drivers/md
parent9b1cc9f251affdd27f29fe46d0989ba76c33faf6 (diff)
dm cache: fix problematic dual use of a single migration count variable
Introduce a new variable to count the number of allocated migration structures. The existing variable cache->nr_migrations became overloaded. It was used to: i) track of the number of migrations in flight for the purposes of quiescing during suspend. ii) to estimate the amount of background IO occuring. Recent discard changes meant that REQ_DISCARD bios are processed with a migration. Discards are not background IO so nr_migrations was not incremented. However this could cause quiescing to complete early. (i) is now handled with a new variable cache->nr_allocated_migrations. cache->nr_migrations has been renamed cache->nr_io_migrations. cleanup_migration() is now called free_io_migration(), since it decrements that variable. Also, remove the unused cache->next_migration variable that got replaced with with prealloc_structs a while ago. Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm-cache-target.c89
1 files changed, 50 insertions, 39 deletions
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 1e96d7889f51..e1650539cc2f 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -221,7 +221,13 @@ struct cache {
221 struct list_head need_commit_migrations; 221 struct list_head need_commit_migrations;
222 sector_t migration_threshold; 222 sector_t migration_threshold;
223 wait_queue_head_t migration_wait; 223 wait_queue_head_t migration_wait;
224 atomic_t nr_migrations; 224 atomic_t nr_allocated_migrations;
225
226 /*
227 * The number of in flight migrations that are performing
228 * background io. eg, promotion, writeback.
229 */
230 atomic_t nr_io_migrations;
225 231
226 wait_queue_head_t quiescing_wait; 232 wait_queue_head_t quiescing_wait;
227 atomic_t quiescing; 233 atomic_t quiescing;
@@ -258,7 +264,6 @@ struct cache {
258 struct dm_deferred_set *all_io_ds; 264 struct dm_deferred_set *all_io_ds;
259 265
260 mempool_t *migration_pool; 266 mempool_t *migration_pool;
261 struct dm_cache_migration *next_migration;
262 267
263 struct dm_cache_policy *policy; 268 struct dm_cache_policy *policy;
264 unsigned policy_nr_args; 269 unsigned policy_nr_args;
@@ -350,10 +355,31 @@ static void free_prison_cell(struct cache *cache, struct dm_bio_prison_cell *cel
350 dm_bio_prison_free_cell(cache->prison, cell); 355 dm_bio_prison_free_cell(cache->prison, cell);
351} 356}
352 357
358static struct dm_cache_migration *alloc_migration(struct cache *cache)
359{
360 struct dm_cache_migration *mg;
361
362 mg = mempool_alloc(cache->migration_pool, GFP_NOWAIT);
363 if (mg) {
364 mg->cache = cache;
365 atomic_inc(&mg->cache->nr_allocated_migrations);
366 }
367
368 return mg;
369}
370
371static void free_migration(struct dm_cache_migration *mg)
372{
373 if (atomic_dec_and_test(&mg->cache->nr_allocated_migrations))
374 wake_up(&mg->cache->migration_wait);
375
376 mempool_free(mg, mg->cache->migration_pool);
377}
378
353static int prealloc_data_structs(struct cache *cache, struct prealloc *p) 379static int prealloc_data_structs(struct cache *cache, struct prealloc *p)
354{ 380{
355 if (!p->mg) { 381 if (!p->mg) {
356 p->mg = mempool_alloc(cache->migration_pool, GFP_NOWAIT); 382 p->mg = alloc_migration(cache);
357 if (!p->mg) 383 if (!p->mg)
358 return -ENOMEM; 384 return -ENOMEM;
359 } 385 }
@@ -382,7 +408,7 @@ static void prealloc_free_structs(struct cache *cache, struct prealloc *p)
382 free_prison_cell(cache, p->cell1); 408 free_prison_cell(cache, p->cell1);
383 409
384 if (p->mg) 410 if (p->mg)
385 mempool_free(p->mg, cache->migration_pool); 411 free_migration(p->mg);
386} 412}
387 413
388static struct dm_cache_migration *prealloc_get_migration(struct prealloc *p) 414static struct dm_cache_migration *prealloc_get_migration(struct prealloc *p)
@@ -854,24 +880,14 @@ static void remap_to_origin_then_cache(struct cache *cache, struct bio *bio,
854 * Migration covers moving data from the origin device to the cache, or 880 * Migration covers moving data from the origin device to the cache, or
855 * vice versa. 881 * vice versa.
856 *--------------------------------------------------------------*/ 882 *--------------------------------------------------------------*/
857static void free_migration(struct dm_cache_migration *mg) 883static void inc_io_migrations(struct cache *cache)
858{
859 mempool_free(mg, mg->cache->migration_pool);
860}
861
862static void inc_nr_migrations(struct cache *cache)
863{ 884{
864 atomic_inc(&cache->nr_migrations); 885 atomic_inc(&cache->nr_io_migrations);
865} 886}
866 887
867static void dec_nr_migrations(struct cache *cache) 888static void dec_io_migrations(struct cache *cache)
868{ 889{
869 atomic_dec(&cache->nr_migrations); 890 atomic_dec(&cache->nr_io_migrations);
870
871 /*
872 * Wake the worker in case we're suspending the target.
873 */
874 wake_up(&cache->migration_wait);
875} 891}
876 892
877static void __cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell, 893static void __cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell,
@@ -894,11 +910,10 @@ static void cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell,
894 wake_worker(cache); 910 wake_worker(cache);
895} 911}
896 912
897static void cleanup_migration(struct dm_cache_migration *mg) 913static void free_io_migration(struct dm_cache_migration *mg)
898{ 914{
899 struct cache *cache = mg->cache; 915 dec_io_migrations(mg->cache);
900 free_migration(mg); 916 free_migration(mg);
901 dec_nr_migrations(cache);
902} 917}
903 918
904static void migration_failure(struct dm_cache_migration *mg) 919static void migration_failure(struct dm_cache_migration *mg)
@@ -923,7 +938,7 @@ static void migration_failure(struct dm_cache_migration *mg)
923 cell_defer(cache, mg->new_ocell, true); 938 cell_defer(cache, mg->new_ocell, true);
924 } 939 }
925 940
926 cleanup_migration(mg); 941 free_io_migration(mg);
927} 942}
928 943
929static void migration_success_pre_commit(struct dm_cache_migration *mg) 944static void migration_success_pre_commit(struct dm_cache_migration *mg)
@@ -934,7 +949,7 @@ static void migration_success_pre_commit(struct dm_cache_migration *mg)
934 if (mg->writeback) { 949 if (mg->writeback) {
935 clear_dirty(cache, mg->old_oblock, mg->cblock); 950 clear_dirty(cache, mg->old_oblock, mg->cblock);
936 cell_defer(cache, mg->old_ocell, false); 951 cell_defer(cache, mg->old_ocell, false);
937 cleanup_migration(mg); 952 free_io_migration(mg);
938 return; 953 return;
939 954
940 } else if (mg->demote) { 955 } else if (mg->demote) {
@@ -944,14 +959,14 @@ static void migration_success_pre_commit(struct dm_cache_migration *mg)
944 mg->old_oblock); 959 mg->old_oblock);
945 if (mg->promote) 960 if (mg->promote)
946 cell_defer(cache, mg->new_ocell, true); 961 cell_defer(cache, mg->new_ocell, true);
947 cleanup_migration(mg); 962 free_io_migration(mg);
948 return; 963 return;
949 } 964 }
950 } else { 965 } else {
951 if (dm_cache_insert_mapping(cache->cmd, mg->cblock, mg->new_oblock)) { 966 if (dm_cache_insert_mapping(cache->cmd, mg->cblock, mg->new_oblock)) {
952 DMWARN_LIMIT("promotion failed; couldn't update on disk metadata"); 967 DMWARN_LIMIT("promotion failed; couldn't update on disk metadata");
953 policy_remove_mapping(cache->policy, mg->new_oblock); 968 policy_remove_mapping(cache->policy, mg->new_oblock);
954 cleanup_migration(mg); 969 free_io_migration(mg);
955 return; 970 return;
956 } 971 }
957 } 972 }
@@ -984,7 +999,7 @@ static void migration_success_post_commit(struct dm_cache_migration *mg)
984 } else { 999 } else {
985 if (mg->invalidate) 1000 if (mg->invalidate)
986 policy_remove_mapping(cache->policy, mg->old_oblock); 1001 policy_remove_mapping(cache->policy, mg->old_oblock);
987 cleanup_migration(mg); 1002 free_io_migration(mg);
988 } 1003 }
989 1004
990 } else { 1005 } else {
@@ -999,7 +1014,7 @@ static void migration_success_post_commit(struct dm_cache_migration *mg)
999 bio_endio(mg->new_ocell->holder, 0); 1014 bio_endio(mg->new_ocell->holder, 0);
1000 cell_defer(cache, mg->new_ocell, false); 1015 cell_defer(cache, mg->new_ocell, false);
1001 } 1016 }
1002 cleanup_migration(mg); 1017 free_io_migration(mg);
1003 } 1018 }
1004} 1019}
1005 1020
@@ -1251,7 +1266,7 @@ static void promote(struct cache *cache, struct prealloc *structs,
1251 mg->new_ocell = cell; 1266 mg->new_ocell = cell;
1252 mg->start_jiffies = jiffies; 1267 mg->start_jiffies = jiffies;
1253 1268
1254 inc_nr_migrations(cache); 1269 inc_io_migrations(cache);
1255 quiesce_migration(mg); 1270 quiesce_migration(mg);
1256} 1271}
1257 1272
@@ -1275,7 +1290,7 @@ static void writeback(struct cache *cache, struct prealloc *structs,
1275 mg->new_ocell = NULL; 1290 mg->new_ocell = NULL;
1276 mg->start_jiffies = jiffies; 1291 mg->start_jiffies = jiffies;
1277 1292
1278 inc_nr_migrations(cache); 1293 inc_io_migrations(cache);
1279 quiesce_migration(mg); 1294 quiesce_migration(mg);
1280} 1295}
1281 1296
@@ -1302,7 +1317,7 @@ static void demote_then_promote(struct cache *cache, struct prealloc *structs,
1302 mg->new_ocell = new_ocell; 1317 mg->new_ocell = new_ocell;
1303 mg->start_jiffies = jiffies; 1318 mg->start_jiffies = jiffies;
1304 1319
1305 inc_nr_migrations(cache); 1320 inc_io_migrations(cache);
1306 quiesce_migration(mg); 1321 quiesce_migration(mg);
1307} 1322}
1308 1323
@@ -1330,7 +1345,7 @@ static void invalidate(struct cache *cache, struct prealloc *structs,
1330 mg->new_ocell = NULL; 1345 mg->new_ocell = NULL;
1331 mg->start_jiffies = jiffies; 1346 mg->start_jiffies = jiffies;
1332 1347
1333 inc_nr_migrations(cache); 1348 inc_io_migrations(cache);
1334 quiesce_migration(mg); 1349 quiesce_migration(mg);
1335} 1350}
1336 1351
@@ -1412,7 +1427,7 @@ static void process_discard_bio(struct cache *cache, struct prealloc *structs,
1412 1427
1413static bool spare_migration_bandwidth(struct cache *cache) 1428static bool spare_migration_bandwidth(struct cache *cache)
1414{ 1429{
1415 sector_t current_volume = (atomic_read(&cache->nr_migrations) + 1) * 1430 sector_t current_volume = (atomic_read(&cache->nr_io_migrations) + 1) *
1416 cache->sectors_per_block; 1431 cache->sectors_per_block;
1417 return current_volume < cache->migration_threshold; 1432 return current_volume < cache->migration_threshold;
1418} 1433}
@@ -1764,7 +1779,7 @@ static void stop_quiescing(struct cache *cache)
1764 1779
1765static void wait_for_migrations(struct cache *cache) 1780static void wait_for_migrations(struct cache *cache)
1766{ 1781{
1767 wait_event(cache->migration_wait, !atomic_read(&cache->nr_migrations)); 1782 wait_event(cache->migration_wait, !atomic_read(&cache->nr_allocated_migrations));
1768} 1783}
1769 1784
1770static void stop_worker(struct cache *cache) 1785static void stop_worker(struct cache *cache)
@@ -1876,9 +1891,6 @@ static void destroy(struct cache *cache)
1876{ 1891{
1877 unsigned i; 1892 unsigned i;
1878 1893
1879 if (cache->next_migration)
1880 mempool_free(cache->next_migration, cache->migration_pool);
1881
1882 if (cache->migration_pool) 1894 if (cache->migration_pool)
1883 mempool_destroy(cache->migration_pool); 1895 mempool_destroy(cache->migration_pool);
1884 1896
@@ -2424,7 +2436,8 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2424 INIT_LIST_HEAD(&cache->quiesced_migrations); 2436 INIT_LIST_HEAD(&cache->quiesced_migrations);
2425 INIT_LIST_HEAD(&cache->completed_migrations); 2437 INIT_LIST_HEAD(&cache->completed_migrations);
2426 INIT_LIST_HEAD(&cache->need_commit_migrations); 2438 INIT_LIST_HEAD(&cache->need_commit_migrations);
2427 atomic_set(&cache->nr_migrations, 0); 2439 atomic_set(&cache->nr_allocated_migrations, 0);
2440 atomic_set(&cache->nr_io_migrations, 0);
2428 init_waitqueue_head(&cache->migration_wait); 2441 init_waitqueue_head(&cache->migration_wait);
2429 2442
2430 init_waitqueue_head(&cache->quiescing_wait); 2443 init_waitqueue_head(&cache->quiescing_wait);
@@ -2487,8 +2500,6 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2487 goto bad; 2500 goto bad;
2488 } 2501 }
2489 2502
2490 cache->next_migration = NULL;
2491
2492 cache->need_tick_bio = true; 2503 cache->need_tick_bio = true;
2493 cache->sized = false; 2504 cache->sized = false;
2494 cache->invalidate = false; 2505 cache->invalidate = false;