Skip to content

Commit

Permalink
dm cache: track IO to the origin device using io_tracker
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Joe Thornber authored and Mike Snitzer committed May 29, 2015
1 parent 77289d3 commit 066dbaa
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions drivers/md/dm-cache-target.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,16 @@ struct cache {
*/
spinlock_t invalidation_lock;
struct list_head invalidation_requests;

struct io_tracker origin_tracker;
};

struct per_bio_data {
bool tick:1;
unsigned req_nr:2;
struct dm_deferred_entry *all_io_entry;
struct dm_hook_info hook_info;
sector_t len;

/*
* writethrough fields. These MUST remain at the end of this
Expand Down Expand Up @@ -768,6 +771,7 @@ static struct per_bio_data *init_per_bio_data(struct bio *bio, size_t data_size)
pb->tick = false;
pb->req_nr = dm_bio_get_target_bio_nr(bio);
pb->all_io_entry = NULL;
pb->len = 0;

return pb;
}
Expand Down Expand Up @@ -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);
}

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)
{
unsigned long flags;

if (!bio_triggers_commit(cache, bio)) {
generic_make_request(bio);
accounted_request(cache, bio);
return;
}

Expand Down Expand Up @@ -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
* 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)
Expand Down Expand Up @@ -1722,7 +1757,7 @@ static void process_deferred_flush_bios(struct cache *cache, bool submit_bios)
* These bios have already been through inc_ds()
*/
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)
Expand All @@ -1742,7 +1777,7 @@ static void process_deferred_writethrough_bios(struct cache *cache)
* These bios have already been through inc_ds()
*/
while ((bio = bio_list_pop(&bios)))
generic_make_request(bio);
accounted_request(cache, bio);
}

static void writeback_some_dirty_blocks(struct cache *cache)
Expand Down Expand Up @@ -2602,6 +2637,8 @@ static int cache_create(struct cache_args *ca, struct cache **result)
spin_lock_init(&cache->invalidation_lock);
INIT_LIST_HEAD(&cache->invalidation_requests);

iot_init(&cache->origin_tracker);

*result = cache;
return 0;

Expand Down Expand Up @@ -2791,9 +2828,13 @@ static int cache_map(struct dm_target *ti, struct bio *bio)
struct cache *cache = ti->private;

r = __cache_map(cache, bio, &cell);
if (r == DM_MAPIO_REMAPPED && cell) {
inc_ds(cache, bio, cell);
cell_defer(cache, cell, false);
if (r == DM_MAPIO_REMAPPED) {
accounted_begin(cache, bio);

if (cell) {
inc_ds(cache, bio, cell);
cell_defer(cache, cell, false);
}
}

return r;
Expand All @@ -2815,6 +2856,7 @@ static int cache_end_io(struct dm_target *ti, struct bio *bio, int error)
}

check_for_quiesced_migrations(cache, pb);
accounted_complete(cache, bio);

return 0;
}
Expand Down

0 comments on commit 066dbaa

Please sign in to comment.