Commit 28f13702 authored by Jens Axboe's avatar Jens Axboe

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: default avatarJens Axboe <jens.axboe@oracle.com>
parent 6d63c275
...@@ -54,15 +54,16 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done); ...@@ -54,15 +54,16 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
static void drive_stat_acct(struct request *rq, int new_io) static void drive_stat_acct(struct request *rq, int new_io)
{ {
struct hd_struct *part;
int rw = rq_data_dir(rq); int rw = rq_data_dir(rq);
if (!blk_fs_request(rq) || !rq->rq_disk) if (!blk_fs_request(rq) || !rq->rq_disk)
return; return;
if (!new_io) { part = get_part(rq->rq_disk, rq->sector);
__all_stat_inc(rq->rq_disk, merges[rw], rq->sector); if (!new_io)
} else { __all_stat_inc(rq->rq_disk, part, merges[rw], rq->sector);
struct hd_struct *part = get_part(rq->rq_disk, rq->sector); else {
disk_round_stats(rq->rq_disk); disk_round_stats(rq->rq_disk);
rq->rq_disk->in_flight++; rq->rq_disk->in_flight++;
if (part) { if (part) {
...@@ -1538,9 +1539,10 @@ static int __end_that_request_first(struct request *req, int error, ...@@ -1538,9 +1539,10 @@ static int __end_that_request_first(struct request *req, int error,
} }
if (blk_fs_request(req) && req->rq_disk) { if (blk_fs_request(req) && req->rq_disk) {
struct hd_struct *part = get_part(req->rq_disk, req->sector);
const int rw = rq_data_dir(req); const int rw = rq_data_dir(req);
all_stat_add(req->rq_disk, sectors[rw], all_stat_add(req->rq_disk, part, sectors[rw],
nr_bytes >> 9, req->sector); nr_bytes >> 9, req->sector);
} }
...@@ -1727,8 +1729,8 @@ static void end_that_request_last(struct request *req, int error) ...@@ -1727,8 +1729,8 @@ static void end_that_request_last(struct request *req, int error)
const int rw = rq_data_dir(req); const int rw = rq_data_dir(req);
struct hd_struct *part = get_part(disk, req->sector); struct hd_struct *part = get_part(disk, req->sector);
__all_stat_inc(disk, ios[rw], req->sector); __all_stat_inc(disk, part, ios[rw], req->sector);
__all_stat_add(disk, ticks[rw], duration, req->sector); __all_stat_add(disk, part, ticks[rw], duration, req->sector);
disk_round_stats(disk); disk_round_stats(disk);
disk->in_flight--; disk->in_flight--;
if (part) { if (part) {
......
...@@ -755,11 +755,13 @@ diskstats(struct gendisk *disk, struct bio *bio, ulong duration, sector_t sector ...@@ -755,11 +755,13 @@ diskstats(struct gendisk *disk, struct bio *bio, ulong duration, sector_t sector
{ {
unsigned long n_sect = bio->bi_size >> 9; unsigned long n_sect = bio->bi_size >> 9;
const int rw = bio_data_dir(bio); const int rw = bio_data_dir(bio);
struct hd_struct *part;
all_stat_inc(disk, ios[rw], sector); part = get_part(disk, sector);
all_stat_add(disk, ticks[rw], duration, sector); all_stat_inc(disk, part, ios[rw], sector);
all_stat_add(disk, sectors[rw], n_sect, sector); all_stat_add(disk, part, ticks[rw], duration, sector);
all_stat_add(disk, io_ticks, duration, sector); all_stat_add(disk, part, sectors[rw], n_sect, sector);
all_stat_add(disk, part, io_ticks, duration, sector);
} }
void void
......
...@@ -178,17 +178,17 @@ static inline struct hd_struct *get_part(struct gendisk *gendiskp, ...@@ -178,17 +178,17 @@ static inline struct hd_struct *get_part(struct gendisk *gendiskp,
static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) { static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
int i; int i;
for_each_possible_cpu(i) for_each_possible_cpu(i)
memset(per_cpu_ptr(gendiskp->dkstats, i), value, memset(per_cpu_ptr(gendiskp->dkstats, i), value,
sizeof (struct disk_stats)); sizeof(struct disk_stats));
} }
#define __part_stat_add(part, field, addnd) \ #define __part_stat_add(part, field, addnd) \
(per_cpu_ptr(part->dkstats, smp_processor_id())->field += addnd) (per_cpu_ptr(part->dkstats, smp_processor_id())->field += addnd)
#define __all_stat_add(gendiskp, field, addnd, sector) \ #define __all_stat_add(gendiskp, part, field, addnd, sector) \
({ \ ({ \
struct hd_struct *part = get_part(gendiskp, sector); \
if (part) \ if (part) \
__part_stat_add(part, field, addnd); \ __part_stat_add(part, field, addnd); \
__disk_stat_add(gendiskp, field, addnd); \ __disk_stat_add(gendiskp, field, addnd); \
...@@ -203,8 +203,10 @@ static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) { ...@@ -203,8 +203,10 @@ static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
res; \ res; \
}) })
static inline void part_stat_set_all(struct hd_struct *part, int value) { static inline void part_stat_set_all(struct hd_struct *part, int value)
{
int i; int i;
for_each_possible_cpu(i) for_each_possible_cpu(i)
memset(per_cpu_ptr(part->dkstats, i), value, memset(per_cpu_ptr(part->dkstats, i), value,
sizeof(struct disk_stats)); sizeof(struct disk_stats));
...@@ -223,9 +225,8 @@ static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) ...@@ -223,9 +225,8 @@ static inline void disk_stat_set_all(struct gendisk *gendiskp, int value)
#define __part_stat_add(part, field, addnd) \ #define __part_stat_add(part, field, addnd) \
(part->dkstats.field += addnd) (part->dkstats.field += addnd)
#define __all_stat_add(gendiskp, field, addnd, sector) \ #define __all_stat_add(gendiskp, part, field, addnd, sector) \
({ \ ({ \
struct hd_struct *part = get_part(gendiskp, sector); \
if (part) \ if (part) \
part->dkstats.field += addnd; \ part->dkstats.field += addnd; \
__disk_stat_add(gendiskp, field, addnd); \ __disk_stat_add(gendiskp, field, addnd); \
...@@ -276,10 +277,10 @@ static inline void part_stat_set_all(struct hd_struct *part, int value) ...@@ -276,10 +277,10 @@ static inline void part_stat_set_all(struct hd_struct *part, int value)
#define part_stat_sub(gendiskp, field, subnd) \ #define part_stat_sub(gendiskp, field, subnd) \
part_stat_add(gendiskp, field, -subnd) part_stat_add(gendiskp, field, -subnd)
#define all_stat_add(gendiskp, field, addnd, sector) \ #define all_stat_add(gendiskp, part, field, addnd, sector) \
do { \ do { \
preempt_disable(); \ preempt_disable(); \
__all_stat_add(gendiskp, field, addnd, sector); \ __all_stat_add(gendiskp, part, field, addnd, sector); \
preempt_enable(); \ preempt_enable(); \
} while (0) } while (0)
...@@ -288,15 +289,15 @@ static inline void part_stat_set_all(struct hd_struct *part, int value) ...@@ -288,15 +289,15 @@ static inline void part_stat_set_all(struct hd_struct *part, int value)
#define all_stat_dec(gendiskp, field, sector) \ #define all_stat_dec(gendiskp, field, sector) \
all_stat_add(gendiskp, field, -1, sector) all_stat_add(gendiskp, field, -1, sector)
#define __all_stat_inc(gendiskp, field, sector) \ #define __all_stat_inc(gendiskp, part, field, sector) \
__all_stat_add(gendiskp, field, 1, sector) __all_stat_add(gendiskp, part, field, 1, sector)
#define all_stat_inc(gendiskp, field, sector) \ #define all_stat_inc(gendiskp, part, field, sector) \
all_stat_add(gendiskp, field, 1, sector) all_stat_add(gendiskp, part, field, 1, sector)
#define __all_stat_sub(gendiskp, field, subnd, sector) \ #define __all_stat_sub(gendiskp, part, field, subnd, sector) \
__all_stat_add(gendiskp, field, -subnd, sector) __all_stat_add(gendiskp, part, field, -subnd, sector)
#define all_stat_sub(gendiskp, field, subnd, sector) \ #define all_stat_sub(gendiskp, part, field, subnd, sector) \
all_stat_add(gendiskp, field, -subnd, sector) all_stat_add(gendiskp, part, field, -subnd, sector)
/* Inlines to alloc and free disk stats in struct gendisk */ /* Inlines to alloc and free disk stats in struct gendisk */
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment