Commit 066dbaa3 authored by Joe Thornber's avatar Joe Thornber Committed by Mike Snitzer

dm cache: track IO to the origin device using io_tracker

Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 77289d32
...@@ -355,6 +355,8 @@ struct cache { ...@@ -355,6 +355,8 @@ struct cache {
*/ */
spinlock_t invalidation_lock; spinlock_t invalidation_lock;
struct list_head invalidation_requests; struct list_head invalidation_requests;
struct io_tracker origin_tracker;
}; };
struct per_bio_data { struct per_bio_data {
...@@ -362,6 +364,7 @@ struct per_bio_data { ...@@ -362,6 +364,7 @@ struct per_bio_data {
unsigned req_nr:2; unsigned req_nr:2;
struct dm_deferred_entry *all_io_entry; struct dm_deferred_entry *all_io_entry;
struct dm_hook_info hook_info; struct dm_hook_info hook_info;
sector_t len;
/* /*
* writethrough fields. These MUST remain at the end of this * writethrough fields. These MUST remain at the end of this
...@@ -768,6 +771,7 @@ static struct per_bio_data *init_per_bio_data(struct bio *bio, size_t data_size) ...@@ -768,6 +771,7 @@ static struct per_bio_data *init_per_bio_data(struct bio *bio, size_t data_size)
pb->tick = false; pb->tick = false;
pb->req_nr = dm_bio_get_target_bio_nr(bio); pb->req_nr = dm_bio_get_target_bio_nr(bio);
pb->all_io_entry = NULL; pb->all_io_entry = NULL;
pb->len = 0;
return pb; return pb;
} }
...@@ -865,12 +869,43 @@ static void inc_ds(struct cache *cache, struct bio *bio, ...@@ -865,12 +869,43 @@ static void inc_ds(struct cache *cache, struct bio *bio,
pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds); pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds);
} }
static bool accountable_bio(struct cache *cache, struct bio *bio)
{
return ((bio->bi_bdev == cache->origin_dev->bdev) &&
!(bio->bi_rw & REQ_DISCARD));
}
static void accounted_begin(struct cache *cache, struct bio *bio)
{
size_t pb_data_size = get_per_bio_data_size(cache);
struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size);
if (accountable_bio(cache, bio)) {
pb->len = bio_sectors(bio);
iot_io_begin(&cache->origin_tracker, pb->len);
}
}
static void accounted_complete(struct cache *cache, struct bio *bio)
{
size_t pb_data_size = get_per_bio_data_size(cache);
struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size);
iot_io_end(&cache->origin_tracker, pb->len);
}
static void accounted_request(struct cache *cache, struct bio *bio)
{
accounted_begin(cache, bio);
generic_make_request(bio);
}
static void issue(struct cache *cache, struct bio *bio) static void issue(struct cache *cache, struct bio *bio)
{ {
unsigned long flags; unsigned long flags;
if (!bio_triggers_commit(cache, bio)) { if (!bio_triggers_commit(cache, bio)) {
generic_make_request(bio); accounted_request(cache, bio);
return; return;
} }
...@@ -1166,7 +1201,7 @@ static void issue_overwrite(struct dm_cache_migration *mg, struct bio *bio) ...@@ -1166,7 +1201,7 @@ static void issue_overwrite(struct dm_cache_migration *mg, struct bio *bio)
* No need to inc_ds() here, since the cell will be held for the * No need to inc_ds() here, since the cell will be held for the
* duration of the io. * duration of the io.
*/ */
generic_make_request(bio); accounted_request(mg->cache, bio);
} }
static bool bio_writes_complete_block(struct cache *cache, struct bio *bio) static bool bio_writes_complete_block(struct cache *cache, struct bio *bio)
...@@ -1722,7 +1757,7 @@ static void process_deferred_flush_bios(struct cache *cache, bool submit_bios) ...@@ -1722,7 +1757,7 @@ static void process_deferred_flush_bios(struct cache *cache, bool submit_bios)
* These bios have already been through inc_ds() * These bios have already been through inc_ds()
*/ */
while ((bio = bio_list_pop(&bios))) while ((bio = bio_list_pop(&bios)))
submit_bios ? generic_make_request(bio) : bio_io_error(bio); submit_bios ? accounted_request(cache, bio) : bio_io_error(bio);
} }
static void process_deferred_writethrough_bios(struct cache *cache) static void process_deferred_writethrough_bios(struct cache *cache)
...@@ -1742,7 +1777,7 @@ static void process_deferred_writethrough_bios(struct cache *cache) ...@@ -1742,7 +1777,7 @@ static void process_deferred_writethrough_bios(struct cache *cache)
* These bios have already been through inc_ds() * These bios have already been through inc_ds()
*/ */
while ((bio = bio_list_pop(&bios))) while ((bio = bio_list_pop(&bios)))
generic_make_request(bio); accounted_request(cache, bio);
} }
static void writeback_some_dirty_blocks(struct cache *cache) static void writeback_some_dirty_blocks(struct cache *cache)
...@@ -2602,6 +2637,8 @@ static int cache_create(struct cache_args *ca, struct cache **result) ...@@ -2602,6 +2637,8 @@ static int cache_create(struct cache_args *ca, struct cache **result)
spin_lock_init(&cache->invalidation_lock); spin_lock_init(&cache->invalidation_lock);
INIT_LIST_HEAD(&cache->invalidation_requests); INIT_LIST_HEAD(&cache->invalidation_requests);
iot_init(&cache->origin_tracker);
*result = cache; *result = cache;
return 0; return 0;
...@@ -2791,10 +2828,14 @@ static int cache_map(struct dm_target *ti, struct bio *bio) ...@@ -2791,10 +2828,14 @@ static int cache_map(struct dm_target *ti, struct bio *bio)
struct cache *cache = ti->private; struct cache *cache = ti->private;
r = __cache_map(cache, bio, &cell); r = __cache_map(cache, bio, &cell);
if (r == DM_MAPIO_REMAPPED && cell) { if (r == DM_MAPIO_REMAPPED) {
accounted_begin(cache, bio);
if (cell) {
inc_ds(cache, bio, cell); inc_ds(cache, bio, cell);
cell_defer(cache, cell, false); cell_defer(cache, cell, false);
} }
}
return r; return r;
} }
...@@ -2815,6 +2856,7 @@ static int cache_end_io(struct dm_target *ti, struct bio *bio, int error) ...@@ -2815,6 +2856,7 @@ static int cache_end_io(struct dm_target *ti, struct bio *bio, int error)
} }
check_for_quiesced_migrations(cache, pb); check_for_quiesced_migrations(cache, pb);
accounted_complete(cache, bio);
return 0; return 0;
} }
......
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