From 63a7138671c50a6f2c27bbd1a308dc75967062a3 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 8 Feb 2008 12:41:03 +0100 Subject: block: fixup rq_init() a bit Rearrange fields in cache order and initialize some fields that we didn't previously init. Remove init of ->completion_data, it's part of a union with ->hash. Luckily clearing the rb node is the same as setting it to null! Signed-off-by: Jens Axboe --- block/blk-core.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'block') diff --git a/block/blk-core.c b/block/blk-core.c index 4afb39c82339..fba4ca7c6086 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -102,27 +102,38 @@ struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev) } EXPORT_SYMBOL(blk_get_backing_dev_info); +/* + * We can't just memset() the structure, since the allocation path + * already stored some information in the request. + */ void rq_init(struct request_queue *q, struct request *rq) { INIT_LIST_HEAD(&rq->queuelist); INIT_LIST_HEAD(&rq->donelist); - - rq->errors = 0; + rq->q = q; + rq->sector = rq->hard_sector = (sector_t) -1; + rq->nr_sectors = rq->hard_nr_sectors = 0; + rq->current_nr_sectors = rq->hard_cur_sectors = 0; rq->bio = rq->biotail = NULL; INIT_HLIST_NODE(&rq->hash); RB_CLEAR_NODE(&rq->rb_node); + rq->rq_disk = NULL; + rq->nr_phys_segments = 0; + rq->nr_hw_segments = 0; rq->ioprio = 0; + rq->special = NULL; rq->buffer = NULL; + rq->tag = -1; + rq->errors = 0; rq->ref_count = 1; - rq->q = q; - rq->special = NULL; + rq->cmd_len = 0; + memset(rq->cmd, 0, sizeof(rq->cmd)); rq->data_len = 0; + rq->sense_len = 0; rq->data = NULL; - rq->nr_phys_segments = 0; rq->sense = NULL; rq->end_io = NULL; rq->end_io_data = NULL; - rq->completion_data = NULL; rq->next_rq = NULL; } -- cgit v1.2.2 From 6f2576af5ba5913538fda7dfb7c6a17771025477 Mon Sep 17 00:00:00 2001 From: Jerome Marchand Date: Fri, 8 Feb 2008 11:04:35 +0100 Subject: Enhanced partition statistics: update partition statitics Updates the enhanced partition statistics in generic block layer besides the disk statistics. Signed-off-by: Jerome Marchand Signed-off-by: Jens Axboe --- block/blk-core.c | 34 ++++++++++++++++++++++++++++++---- block/blk-merge.c | 6 ++++++ 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'block') diff --git a/block/blk-core.c b/block/blk-core.c index fba4ca7c6086..2358fc5de5a4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -60,10 +60,15 @@ static void drive_stat_acct(struct request *rq, int new_io) return; if (!new_io) { - __disk_stat_inc(rq->rq_disk, merges[rw]); + __all_stat_inc(rq->rq_disk, merges[rw], rq->sector); } else { + struct hd_struct *part = get_part(rq->rq_disk, rq->sector); disk_round_stats(rq->rq_disk); rq->rq_disk->in_flight++; + if (part) { + part_round_stats(part); + part->in_flight++; + } } } @@ -997,6 +1002,21 @@ void disk_round_stats(struct gendisk *disk) } EXPORT_SYMBOL_GPL(disk_round_stats); +void part_round_stats(struct hd_struct *part) +{ + unsigned long now = jiffies; + + if (now == part->stamp) + return; + + if (part->in_flight) { + __part_stat_add(part, time_in_queue, + part->in_flight * (now - part->stamp)); + __part_stat_add(part, io_ticks, (now - part->stamp)); + } + part->stamp = now; +} + /* * queue lock must be held */ @@ -1530,7 +1550,8 @@ static int __end_that_request_first(struct request *req, int error, if (blk_fs_request(req) && req->rq_disk) { const int rw = rq_data_dir(req); - disk_stat_add(req->rq_disk, sectors[rw], nr_bytes >> 9); + all_stat_add(req->rq_disk, sectors[rw], + nr_bytes >> 9, req->sector); } total_bytes = bio_nbytes = 0; @@ -1715,11 +1736,16 @@ static void end_that_request_last(struct request *req, int error) if (disk && blk_fs_request(req) && req != &req->q->bar_rq) { unsigned long duration = jiffies - req->start_time; const int rw = rq_data_dir(req); + struct hd_struct *part = get_part(disk, req->sector); - __disk_stat_inc(disk, ios[rw]); - __disk_stat_add(disk, ticks[rw], duration); + __all_stat_inc(disk, ios[rw], req->sector); + __all_stat_add(disk, ticks[rw], duration, req->sector); disk_round_stats(disk); disk->in_flight--; + if (part) { + part_round_stats(part); + part->in_flight--; + } } if (req->end_io) diff --git a/block/blk-merge.c b/block/blk-merge.c index 845ef8131108..d3b84bbb776a 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -454,8 +454,14 @@ static int attempt_merge(struct request_queue *q, struct request *req, elv_merge_requests(q, req, next); if (req->rq_disk) { + struct hd_struct *part + = get_part(req->rq_disk, req->sector); disk_round_stats(req->rq_disk); req->rq_disk->in_flight--; + if (part) { + part_round_stats(part); + part->in_flight--; + } } req->ioprio = ioprio_best(req->ioprio, next->ioprio); -- cgit v1.2.2 From 28f39d553ee242000e62f6c589ee3dc6de3f9aaa Mon Sep 17 00:00:00 2001 From: Jerome Marchand Date: Fri, 8 Feb 2008 11:04:56 +0100 Subject: Enhanced partition statistics: procfs Reports enhanced partition statistics in /proc/diskstats. Signed-off-by: Jerome Marchand --- block/genhd.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'block') diff --git a/block/genhd.c b/block/genhd.c index de2ebb2fab43..53f2238e69c8 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -584,12 +584,28 @@ static int diskstats_show(struct seq_file *s, void *v) for (n = 0; n < gp->minors - 1; n++) { struct hd_struct *hd = gp->part[n]; - if (hd && hd->nr_sects) - seq_printf(s, "%4d %4d %s %u %u %u %u\n", - gp->major, n + gp->first_minor + 1, - disk_name(gp, n + 1, buf), - hd->ios[0], hd->sectors[0], - hd->ios[1], hd->sectors[1]); + if (!hd || !hd->nr_sects) + continue; + + preempt_disable(); + part_round_stats(hd); + preempt_enable(); + seq_printf(s, "%4d %4d %s %lu %lu %llu " + "%u %lu %lu %llu %u %u %u %u\n", + gp->major, n + gp->first_minor + 1, + disk_name(gp, n + 1, buf), + part_stat_read(hd, ios[0]), + part_stat_read(hd, merges[0]), + (unsigned long long)part_stat_read(hd, sectors[0]), + jiffies_to_msecs(part_stat_read(hd, ticks[0])), + part_stat_read(hd, ios[1]), + part_stat_read(hd, merges[1]), + (unsigned long long)part_stat_read(hd, sectors[1]), + jiffies_to_msecs(part_stat_read(hd, ticks[1])), + hd->in_flight, + jiffies_to_msecs(part_stat_read(hd, io_ticks)), + jiffies_to_msecs(part_stat_read(hd, time_in_queue)) + ); } return 0; -- cgit v1.2.2 From c3c930d93365c495fbc1df28649da7cd4b97f4af Mon Sep 17 00:00:00 2001 From: Jerome Marchand Date: Fri, 8 Feb 2008 12:06:21 +0100 Subject: Enhanced partition statistics: remove old partition statistics Removes the now unused old partition statistic code. Signed-off-by: Jerome Marchand Signed-off-by: Jens Axboe --- block/blk-core.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'block') diff --git a/block/blk-core.c b/block/blk-core.c index 2358fc5de5a4..e9754dc98ec4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1219,10 +1219,6 @@ static inline void blk_partition_remap(struct bio *bio) if (bio_sectors(bio) && bdev != bdev->bd_contains) { struct hd_struct *p = bdev->bd_part; - const int rw = bio_data_dir(bio); - - p->sectors[rw] += bio_sectors(bio); - p->ios[rw]++; bio->bi_sector += p->start_sect; bio->bi_bdev = bdev->bd_contains; -- cgit v1.2.2