Skip to content

Commit 528ec5a

Browse files
Mike Christieaxboe
authored andcommitted
dm: pass dm stats data dir instead of bi_rw
It looks like dm stats cares about the data direction (READ vs WRITE) and does not need the bio/request flags. Commands like REQ_FLUSH, REQ_DISCARD and REQ_WRITE_SAME are currently always set with REQ_WRITE, so the extra check for REQ_DISCARD in dm_stats_account_io is not needed. This patch has it use the bio and request data_dir helpers instead of accessing the bi_rw/cmd_flags directly. This makes the next patches that remove the operation from the cmd_flags and bi_rw easier, because we will no longer have the REQ_WRITE bit set for operations like discards. Signed-off-by: Mike Christie <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 162b99e commit 528ec5a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

drivers/md/dm-stats.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,10 @@ static void dm_stat_round(struct dm_stat *s, struct dm_stat_shared *shared,
514514
}
515515

516516
static void dm_stat_for_entry(struct dm_stat *s, size_t entry,
517-
unsigned long bi_rw, sector_t len,
517+
int idx, sector_t len,
518518
struct dm_stats_aux *stats_aux, bool end,
519519
unsigned long duration_jiffies)
520520
{
521-
unsigned long idx = bi_rw & REQ_WRITE;
522521
struct dm_stat_shared *shared = &s->stat_shared[entry];
523522
struct dm_stat_percpu *p;
524523

@@ -584,7 +583,7 @@ static void dm_stat_for_entry(struct dm_stat *s, size_t entry,
584583
#endif
585584
}
586585

587-
static void __dm_stat_bio(struct dm_stat *s, unsigned long bi_rw,
586+
static void __dm_stat_bio(struct dm_stat *s, int bi_rw,
588587
sector_t bi_sector, sector_t end_sector,
589588
bool end, unsigned long duration_jiffies,
590589
struct dm_stats_aux *stats_aux)
@@ -645,8 +644,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
645644
last = raw_cpu_ptr(stats->last);
646645
stats_aux->merged =
647646
(bi_sector == (ACCESS_ONCE(last->last_sector) &&
648-
((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
649-
(ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
647+
((bi_rw == WRITE) ==
648+
(ACCESS_ONCE(last->last_rw) == WRITE))
650649
));
651650
ACCESS_ONCE(last->last_sector) = end_sector;
652651
ACCESS_ONCE(last->last_rw) = bi_rw;

drivers/md/dm.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,9 @@ static void start_io_acct(struct dm_io *io)
723723
atomic_inc_return(&md->pending[rw]));
724724

725725
if (unlikely(dm_stats_used(&md->stats)))
726-
dm_stats_account_io(&md->stats, bio->bi_rw, bio->bi_iter.bi_sector,
727-
bio_sectors(bio), false, 0, &io->stats_aux);
726+
dm_stats_account_io(&md->stats, bio_data_dir(bio),
727+
bio->bi_iter.bi_sector, bio_sectors(bio),
728+
false, 0, &io->stats_aux);
728729
}
729730

730731
static void end_io_acct(struct dm_io *io)
@@ -738,8 +739,9 @@ static void end_io_acct(struct dm_io *io)
738739
generic_end_io_acct(rw, &dm_disk(md)->part0, io->start_time);
739740

740741
if (unlikely(dm_stats_used(&md->stats)))
741-
dm_stats_account_io(&md->stats, bio->bi_rw, bio->bi_iter.bi_sector,
742-
bio_sectors(bio), true, duration, &io->stats_aux);
742+
dm_stats_account_io(&md->stats, bio_data_dir(bio),
743+
bio->bi_iter.bi_sector, bio_sectors(bio),
744+
true, duration, &io->stats_aux);
743745

744746
/*
745747
* After this is decremented the bio must not be touched if it is
@@ -1121,9 +1123,9 @@ static void rq_end_stats(struct mapped_device *md, struct request *orig)
11211123
if (unlikely(dm_stats_used(&md->stats))) {
11221124
struct dm_rq_target_io *tio = tio_from_request(orig);
11231125
tio->duration_jiffies = jiffies - tio->duration_jiffies;
1124-
dm_stats_account_io(&md->stats, orig->cmd_flags, blk_rq_pos(orig),
1125-
tio->n_sectors, true, tio->duration_jiffies,
1126-
&tio->stats_aux);
1126+
dm_stats_account_io(&md->stats, rq_data_dir(orig),
1127+
blk_rq_pos(orig), tio->n_sectors, true,
1128+
tio->duration_jiffies, &tio->stats_aux);
11271129
}
11281130
}
11291131

@@ -2082,8 +2084,9 @@ static void dm_start_request(struct mapped_device *md, struct request *orig)
20822084
struct dm_rq_target_io *tio = tio_from_request(orig);
20832085
tio->duration_jiffies = jiffies;
20842086
tio->n_sectors = blk_rq_sectors(orig);
2085-
dm_stats_account_io(&md->stats, orig->cmd_flags, blk_rq_pos(orig),
2086-
tio->n_sectors, false, 0, &tio->stats_aux);
2087+
dm_stats_account_io(&md->stats, rq_data_dir(orig),
2088+
blk_rq_pos(orig), tio->n_sectors, false, 0,
2089+
&tio->stats_aux);
20872090
}
20882091

20892092
/*

0 commit comments

Comments
 (0)