Commit ddcf35d3 authored by Michael Callahan's avatar Michael Callahan Committed by Jens Axboe
Browse files

block: Add and use op_stat_group() for indexing disk_stat fields.



Add and use a new op_stat_group() function for indexing partition stat
fields rather than indexing them by rq_data_dir() or bio_data_dir().
This function works similarly to op_is_sync() in that it takes the
request::cmd_flags or bio::bi_opf flags and determines which stats
should et updated.

In addition, the second parameter to generic_start_io_acct() and
generic_end_io_acct() is now a REQ_OP rather than simply a read or
write bit and it uses op_stat_group() on the parameter to determine
the stat group.

Note that the partition in_flight counts are not part of the per-cpu
statistics and as such are not indexed via this function.  It's now
indexed by op_is_write().

tj: Refreshed on top of v4.17.  Updated to pass around REQ_OP.

Signed-off-by: default avatarMichael Callahan <michaelcallahan@fb.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Joshua Morris <josh.h.morris@us.ibm.com>
Cc: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Matias Bjorling <mb@lightnvm.io>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Alasdair Kergon <agk@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent dbae2c55
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -1728,29 +1728,31 @@ void bio_check_pages_dirty(struct bio *bio)
}
EXPORT_SYMBOL_GPL(bio_check_pages_dirty);

void generic_start_io_acct(struct request_queue *q, int rw,
void generic_start_io_acct(struct request_queue *q, int op,
			   unsigned long sectors, struct hd_struct *part)
{
	const int sgrp = op_stat_group(op);
	int cpu = part_stat_lock();

	part_round_stats(q, cpu, part);
	part_stat_inc(cpu, part, ios[rw]);
	part_stat_add(cpu, part, sectors[rw], sectors);
	part_inc_in_flight(q, part, rw);
	part_stat_inc(cpu, part, ios[sgrp]);
	part_stat_add(cpu, part, sectors[sgrp], sectors);
	part_inc_in_flight(q, part, op_is_write(op));

	part_stat_unlock();
}
EXPORT_SYMBOL(generic_start_io_acct);

void generic_end_io_acct(struct request_queue *q, int rw,
void generic_end_io_acct(struct request_queue *q, int req_op,
			 struct hd_struct *part, unsigned long start_time)
{
	unsigned long duration = jiffies - start_time;
	const int sgrp = op_stat_group(req_op);
	int cpu = part_stat_lock();

	part_stat_add(cpu, part, ticks[rw], duration);
	part_stat_add(cpu, part, ticks[sgrp], duration);
	part_round_stats(q, cpu, part);
	part_dec_in_flight(q, part, rw);
	part_dec_in_flight(q, part, op_is_write(req_op));

	part_stat_unlock();
}
+6 −6
Original line number Diff line number Diff line
@@ -2702,13 +2702,13 @@ EXPORT_SYMBOL_GPL(blk_rq_err_bytes);
void blk_account_io_completion(struct request *req, unsigned int bytes)
{
	if (blk_do_io_stat(req)) {
		const int rw = rq_data_dir(req);
		const int sgrp = op_stat_group(req_op(req));
		struct hd_struct *part;
		int cpu;

		cpu = part_stat_lock();
		part = req->part;
		part_stat_add(cpu, part, sectors[rw], bytes >> 9);
		part_stat_add(cpu, part, sectors[sgrp], bytes >> 9);
		part_stat_unlock();
	}
}
@@ -2722,7 +2722,7 @@ void blk_account_io_done(struct request *req, u64 now)
	 */
	if (blk_do_io_stat(req) && !(req->rq_flags & RQF_FLUSH_SEQ)) {
		unsigned long duration;
		const int rw = rq_data_dir(req);
		const int sgrp = op_stat_group(req_op(req));
		struct hd_struct *part;
		int cpu;

@@ -2730,10 +2730,10 @@ void blk_account_io_done(struct request *req, u64 now)
		cpu = part_stat_lock();
		part = req->part;

		part_stat_inc(cpu, part, ios[rw]);
		part_stat_add(cpu, part, ticks[rw], duration);
		part_stat_inc(cpu, part, ios[sgrp]);
		part_stat_add(cpu, part, ticks[sgrp], duration);
		part_round_stats(req->q, cpu, part);
		part_dec_in_flight(req->q, part, rw);
		part_dec_in_flight(req->q, part, rq_data_dir(req));

		hd_struct_put(part);
		part_stat_unlock();
+2 −2
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ static void _drbd_start_io_acct(struct drbd_device *device, struct drbd_request
{
	struct request_queue *q = device->rq_queue;

	generic_start_io_acct(q, bio_data_dir(req->master_bio),
	generic_start_io_acct(q, bio_op(req->master_bio),
				req->i.size >> 9, &device->vdisk->part0);
}

@@ -47,7 +47,7 @@ static void _drbd_end_io_acct(struct drbd_device *device, struct drbd_request *r
{
	struct request_queue *q = device->rq_queue;

	generic_end_io_acct(q, bio_data_dir(req->master_bio),
	generic_end_io_acct(q, bio_op(req->master_bio),
			    &device->vdisk->part0, req->start_jif);
}

+3 −3
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ static const struct block_device_operations rsxx_fops = {

static void disk_stats_start(struct rsxx_cardinfo *card, struct bio *bio)
{
	generic_start_io_acct(card->queue, bio_data_dir(bio), bio_sectors(bio),
	generic_start_io_acct(card->queue, bio_op(bio), bio_sectors(bio),
			     &card->gendisk->part0);
}

@@ -120,7 +120,7 @@ static void disk_stats_complete(struct rsxx_cardinfo *card,
				struct bio *bio,
				unsigned long start_time)
{
	generic_end_io_acct(card->queue, bio_data_dir(bio),
	generic_end_io_acct(card->queue, bio_op(bio),
			    &card->gendisk->part0, start_time);
}

+2 −3
Original line number Diff line number Diff line
@@ -1277,11 +1277,10 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
			int offset, unsigned int op, struct bio *bio)
{
	unsigned long start_time = jiffies;
	int rw_acct = op_is_write(op) ? REQ_OP_WRITE : REQ_OP_READ;
	struct request_queue *q = zram->disk->queue;
	int ret;

	generic_start_io_acct(q, rw_acct, bvec->bv_len >> SECTOR_SHIFT,
	generic_start_io_acct(q, op, bvec->bv_len >> SECTOR_SHIFT,
			&zram->disk->part0);

	if (!op_is_write(op)) {
@@ -1293,7 +1292,7 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
		ret = zram_bvec_write(zram, bvec, index, offset, bio);
	}

	generic_end_io_acct(q, rw_acct, &zram->disk->part0, start_time);
	generic_end_io_acct(q, op, &zram->disk->part0, start_time);

	zram_slot_lock(zram, index);
	zram_accessed(zram, index);
Loading