diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2008-05-07 04:15:46 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-05-07 04:15:46 -0400 |
commit | 28f13702f03e527fcb979747a882cf366c489c50 (patch) | |
tree | 08cf04c696bf0facb083bbfbdd867e5949c5fa14 | |
parent | 6d63c275572d1e6f00d4fa154f16fbb0d8c2d2bf (diff) |
block: avoid duplicate calls to get_part() in disk stat code
get_part() is fairly expensive, as it O(N) loops over partitions
to find the right one. In lots of normal IO paths we end up looking
up the partition twice, to make matters even worse. Change the
stat add code to accept a passed in partition instead.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r-- | block/blk-core.c | 18 | ||||
-rw-r--r-- | drivers/block/aoe/aoecmd.c | 10 | ||||
-rw-r--r-- | include/linux/genhd.h | 35 |
3 files changed, 34 insertions, 29 deletions
diff --git a/block/blk-core.c b/block/blk-core.c index 1b7dddf94f4f..2987fe47b5ee 100644 --- a/block/blk-core.c +++ b/block/blk-core.c | |||
@@ -54,15 +54,16 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done); | |||
54 | 54 | ||
55 | static void drive_stat_acct(struct request *rq, int new_io) | 55 | static void drive_stat_acct(struct request *rq, int new_io) |
56 | { | 56 | { |
57 | struct hd_struct *part; | ||
57 | int rw = rq_data_dir(rq); | 58 | int rw = rq_data_dir(rq); |
58 | 59 | ||
59 | if (!blk_fs_request(rq) || !rq->rq_disk) | 60 | if (!blk_fs_request(rq) || !rq->rq_disk) |
60 | return; | 61 | return; |
61 | 62 | ||
62 | if (!new_io) { | 63 | part = get_part(rq->rq_disk, rq->sector); |
63 | __all_stat_inc(rq->rq_disk, merges[rw], rq->sector); | 64 | if (!new_io) |
64 | } else { | 65 | __all_stat_inc(rq->rq_disk, part, merges[rw], rq->sector); |
65 | struct hd_struct *part = get_part(rq->rq_disk, rq->sector); | 66 | else { |
66 | disk_round_stats(rq->rq_disk); | 67 | disk_round_stats(rq->rq_disk); |
67 | rq->rq_disk->in_flight++; | 68 | rq->rq_disk->in_flight++; |
68 | if (part) { | 69 | if (part) { |
@@ -1538,10 +1539,11 @@ static int __end_that_request_first(struct request *req, int error, | |||
1538 | } | 1539 | } |
1539 | 1540 | ||
1540 | if (blk_fs_request(req) && req->rq_disk) { | 1541 | if (blk_fs_request(req) && req->rq_disk) { |
1542 | struct hd_struct *part = get_part(req->rq_disk, req->sector); | ||
1541 | const int rw = rq_data_dir(req); | 1543 | const int rw = rq_data_dir(req); |
1542 | 1544 | ||
1543 | all_stat_add(req->rq_disk, sectors[rw], | 1545 | all_stat_add(req->rq_disk, part, sectors[rw], |
1544 | nr_bytes >> 9, req->sector); | 1546 | nr_bytes >> 9, req->sector); |
1545 | } | 1547 | } |
1546 | 1548 | ||
1547 | total_bytes = bio_nbytes = 0; | 1549 | total_bytes = bio_nbytes = 0; |
@@ -1727,8 +1729,8 @@ static void end_that_request_last(struct request *req, int error) | |||
1727 | const int rw = rq_data_dir(req); | 1729 | const int rw = rq_data_dir(req); |
1728 | struct hd_struct *part = get_part(disk, req->sector); | 1730 | struct hd_struct *part = get_part(disk, req->sector); |
1729 | 1731 | ||
1730 | __all_stat_inc(disk, ios[rw], req->sector); | 1732 | __all_stat_inc(disk, part, ios[rw], req->sector); |
1731 | __all_stat_add(disk, ticks[rw], duration, req->sector); | 1733 | __all_stat_add(disk, part, ticks[rw], duration, req->sector); |
1732 | disk_round_stats(disk); | 1734 | disk_round_stats(disk); |
1733 | disk->in_flight--; | 1735 | disk->in_flight--; |
1734 | if (part) { | 1736 | if (part) { |
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c index 8fc429cf82b6..41f818be2f7e 100644 --- a/drivers/block/aoe/aoecmd.c +++ b/drivers/block/aoe/aoecmd.c | |||
@@ -755,11 +755,13 @@ diskstats(struct gendisk *disk, struct bio *bio, ulong duration, sector_t sector | |||
755 | { | 755 | { |
756 | unsigned long n_sect = bio->bi_size >> 9; | 756 | unsigned long n_sect = bio->bi_size >> 9; |
757 | const int rw = bio_data_dir(bio); | 757 | const int rw = bio_data_dir(bio); |
758 | struct hd_struct *part; | ||
758 | 759 | ||
759 | all_stat_inc(disk, ios[rw], sector); | 760 | part = get_part(disk, sector); |
760 | all_stat_add(disk, ticks[rw], duration, sector); | 761 | all_stat_inc(disk, part, ios[rw], sector); |
761 | all_stat_add(disk, sectors[rw], n_sect, sector); | 762 | all_stat_add(disk, part, ticks[rw], duration, sector); |
762 | all_stat_add(disk, io_ticks, duration, sector); | 763 | all_stat_add(disk, part, sectors[rw], n_sect, sector); |
764 | all_stat_add(disk, part, io_ticks, duration, sector); | ||
763 | } | 765 | } |
764 | 766 | ||
765 | void | 767 | void |
diff --git a/include/linux/genhd.h b/include/linux/genhd.h index ecd2bf63fc84..e9874e7fcdf9 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h | |||
@@ -178,17 +178,17 @@ static inline struct hd_struct *get_part(struct gendisk *gendiskp, | |||
178 | 178 | ||
179 | static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) { | 179 | static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) { |
180 | int i; | 180 | int i; |
181 | |||
181 | for_each_possible_cpu(i) | 182 | for_each_possible_cpu(i) |
182 | memset(per_cpu_ptr(gendiskp->dkstats, i), value, | 183 | memset(per_cpu_ptr(gendiskp->dkstats, i), value, |
183 | sizeof (struct disk_stats)); | 184 | sizeof(struct disk_stats)); |
184 | } | 185 | } |
185 | 186 | ||
186 | #define __part_stat_add(part, field, addnd) \ | 187 | #define __part_stat_add(part, field, addnd) \ |
187 | (per_cpu_ptr(part->dkstats, smp_processor_id())->field += addnd) | 188 | (per_cpu_ptr(part->dkstats, smp_processor_id())->field += addnd) |
188 | 189 | ||
189 | #define __all_stat_add(gendiskp, field, addnd, sector) \ | 190 | #define __all_stat_add(gendiskp, part, field, addnd, sector) \ |
190 | ({ \ | 191 | ({ \ |
191 | struct hd_struct *part = get_part(gendiskp, sector); \ | ||
192 | if (part) \ | 192 | if (part) \ |
193 | __part_stat_add(part, field, addnd); \ | 193 | __part_stat_add(part, field, addnd); \ |
194 | __disk_stat_add(gendiskp, field, addnd); \ | 194 | __disk_stat_add(gendiskp, field, addnd); \ |
@@ -203,11 +203,13 @@ static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) { | |||
203 | res; \ | 203 | res; \ |
204 | }) | 204 | }) |
205 | 205 | ||
206 | static inline void part_stat_set_all(struct hd_struct *part, int value) { | 206 | static inline void part_stat_set_all(struct hd_struct *part, int value) |
207 | { | ||
207 | int i; | 208 | int i; |
209 | |||
208 | for_each_possible_cpu(i) | 210 | for_each_possible_cpu(i) |
209 | memset(per_cpu_ptr(part->dkstats, i), value, | 211 | memset(per_cpu_ptr(part->dkstats, i), value, |
210 | sizeof(struct disk_stats)); | 212 | sizeof(struct disk_stats)); |
211 | } | 213 | } |
212 | 214 | ||
213 | #else /* !CONFIG_SMP */ | 215 | #else /* !CONFIG_SMP */ |
@@ -223,9 +225,8 @@ static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) | |||
223 | #define __part_stat_add(part, field, addnd) \ | 225 | #define __part_stat_add(part, field, addnd) \ |
224 | (part->dkstats.field += addnd) | 226 | (part->dkstats.field += addnd) |
225 | 227 | ||
226 | #define __all_stat_add(gendiskp, field, addnd, sector) \ | 228 | #define __all_stat_add(gendiskp, part, field, addnd, sector) \ |
227 | ({ \ | 229 | ({ \ |
228 | struct hd_struct *part = get_part(gendiskp, sector); \ | ||
229 | if (part) \ | 230 | if (part) \ |
230 | part->dkstats.field += addnd; \ | 231 | part->dkstats.field += addnd; \ |
231 | __disk_stat_add(gendiskp, field, addnd); \ | 232 | __disk_stat_add(gendiskp, field, addnd); \ |
@@ -276,10 +277,10 @@ static inline void part_stat_set_all(struct hd_struct *part, int value) | |||
276 | #define part_stat_sub(gendiskp, field, subnd) \ | 277 | #define part_stat_sub(gendiskp, field, subnd) \ |
277 | part_stat_add(gendiskp, field, -subnd) | 278 | part_stat_add(gendiskp, field, -subnd) |
278 | 279 | ||
279 | #define all_stat_add(gendiskp, field, addnd, sector) \ | 280 | #define all_stat_add(gendiskp, part, field, addnd, sector) \ |
280 | do { \ | 281 | do { \ |
281 | preempt_disable(); \ | 282 | preempt_disable(); \ |
282 | __all_stat_add(gendiskp, field, addnd, sector); \ | 283 | __all_stat_add(gendiskp, part, field, addnd, sector); \ |
283 | preempt_enable(); \ | 284 | preempt_enable(); \ |
284 | } while (0) | 285 | } while (0) |
285 | 286 | ||
@@ -288,15 +289,15 @@ static inline void part_stat_set_all(struct hd_struct *part, int value) | |||
288 | #define all_stat_dec(gendiskp, field, sector) \ | 289 | #define all_stat_dec(gendiskp, field, sector) \ |
289 | all_stat_add(gendiskp, field, -1, sector) | 290 | all_stat_add(gendiskp, field, -1, sector) |
290 | 291 | ||
291 | #define __all_stat_inc(gendiskp, field, sector) \ | 292 | #define __all_stat_inc(gendiskp, part, field, sector) \ |
292 | __all_stat_add(gendiskp, field, 1, sector) | 293 | __all_stat_add(gendiskp, part, field, 1, sector) |
293 | #define all_stat_inc(gendiskp, field, sector) \ | 294 | #define all_stat_inc(gendiskp, part, field, sector) \ |
294 | all_stat_add(gendiskp, field, 1, sector) | 295 | all_stat_add(gendiskp, part, field, 1, sector) |
295 | 296 | ||
296 | #define __all_stat_sub(gendiskp, field, subnd, sector) \ | 297 | #define __all_stat_sub(gendiskp, part, field, subnd, sector) \ |
297 | __all_stat_add(gendiskp, field, -subnd, sector) | 298 | __all_stat_add(gendiskp, part, field, -subnd, sector) |
298 | #define all_stat_sub(gendiskp, field, subnd, sector) \ | 299 | #define all_stat_sub(gendiskp, part, field, subnd, sector) \ |
299 | all_stat_add(gendiskp, field, -subnd, sector) | 300 | all_stat_add(gendiskp, part, field, -subnd, sector) |
300 | 301 | ||
301 | /* Inlines to alloc and free disk stats in struct gendisk */ | 302 | /* Inlines to alloc and free disk stats in struct gendisk */ |
302 | #ifdef CONFIG_SMP | 303 | #ifdef CONFIG_SMP |