Skip to content

Commit 5bdb8ec

Browse files
Tang Yizhouaxboe
authored andcommitted
block: propagate in_flight to whole disk on partition I/O
Now when I/O is submitted to a partition, the per-CPU in_flight[] counter is incremented only on the partition's block_device, not on the underlying whole disk. This leads to a problem which can be shown by a fio test: lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS mydev 252:1 0 20G 0 disk └─mydev1 259:0 0 10G 0 part iostat -xp 1 Device r/s rkB/s ... aqu-sz %util mydev 128153.00 512612.00 ... 13.22 72.20 mydev1 128154.00 512616.00 ... 13.22 100.00 %util is different between mydev and mydev1, which is unexpected. This is the cumulative effect of a series of patches. The root cause is commit e016b78 ("block: return just one value from part_in_flight"), which deleted the branch in part_in_flight() that aggregated the whole-disk in_flight count on top of the partition's. Then the second commit is commit 10ec5e8 ("block: merge part_{inc,dev}_in_flight into their only callers"), which folded the whole-disk in_flight accounting into generic_start_io_acct() and generic_end_io_acct(). Those two helpers were then removed by commit e722fff ("block: remove generic_{start,end}_io_acct"), and from that point on the whole disk's in_flight is no longer accounted at all. In update_io_ticks(), if calling bdev_count_inflight() finds that the inflight value of the whole device is 0, the accumulation of io_ticks will be skipped, causing the reported util% value to be underestimated. Fix it by restoring the whole-disk in_flight accounting. Fixes: e016b78 ("block: return just one value from part_in_flight") Suggested-by: Leon Hwang <leon.huangfu@shopee.com> Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Tang Yizhou <yizhou.tang@shopee.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20260526021555.359500-1-yizhou.tang@shopee.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0fd835f commit 5bdb8ec

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

block/blk-core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ unsigned long bdev_start_io_acct(struct block_device *bdev, enum req_op op,
10381038
{
10391039
part_stat_lock();
10401040
update_io_ticks(bdev, start_time, false);
1041-
part_stat_local_inc(bdev, in_flight[op_is_write(op)]);
1041+
bdev_inc_in_flight(bdev, op);
10421042
part_stat_unlock();
10431043

10441044
return start_time;
@@ -1069,7 +1069,7 @@ void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
10691069
part_stat_inc(bdev, ios[sgrp]);
10701070
part_stat_add(bdev, sectors[sgrp], sectors);
10711071
part_stat_add(bdev, nsecs[sgrp], jiffies_to_nsecs(duration));
1072-
part_stat_local_dec(bdev, in_flight[op_is_write(op)]);
1072+
bdev_dec_in_flight(bdev, op);
10731073
part_stat_unlock();
10741074
}
10751075
EXPORT_SYMBOL(bdev_end_io_acct);

block/blk-merge.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,7 @@ static void blk_account_io_merge_request(struct request *req)
721721
if (req->rq_flags & RQF_IO_STAT) {
722722
part_stat_lock();
723723
part_stat_inc(req->part, merges[op_stat_group(req_op(req))]);
724-
part_stat_local_dec(req->part,
725-
in_flight[op_is_write(req_op(req))]);
724+
bdev_dec_in_flight(req->part, req_op(req));
726725
part_stat_unlock();
727726
}
728727
}

block/blk-mq.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,7 @@ static inline void blk_account_io_done(struct request *req, u64 now)
10821082
update_io_ticks(req->part, jiffies, true);
10831083
part_stat_inc(req->part, ios[sgrp]);
10841084
part_stat_add(req->part, nsecs[sgrp], now - req->start_time_ns);
1085-
part_stat_local_dec(req->part,
1086-
in_flight[op_is_write(req_op(req))]);
1085+
bdev_dec_in_flight(req->part, req_op(req));
10871086
part_stat_unlock();
10881087
}
10891088
}
@@ -1113,7 +1112,7 @@ static inline void blk_account_io_start(struct request *req)
11131112

11141113
part_stat_lock();
11151114
update_io_ticks(req->part, jiffies, false);
1116-
part_stat_local_inc(req->part, in_flight[op_is_write(req_op(req))]);
1115+
bdev_inc_in_flight(req->part, req_op(req));
11171116
part_stat_unlock();
11181117
}
11191118

block/blk.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/bio-integrity.h>
66
#include <linux/blk-crypto.h>
7+
#include <linux/part_stat.h>
78
#include <linux/lockdep.h>
89
#include <linux/memblock.h> /* for max_pfn/max_low_pfn */
910
#include <linux/sched/sysctl.h>
@@ -487,6 +488,26 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)
487488
q->last_merge = NULL;
488489
}
489490

491+
static inline void bdev_inc_in_flight(struct block_device *bdev,
492+
enum req_op op)
493+
{
494+
bool rw = op_is_write(op);
495+
496+
part_stat_local_inc(bdev, in_flight[rw]);
497+
if (bdev_is_partition(bdev))
498+
part_stat_local_inc(bdev_whole(bdev), in_flight[rw]);
499+
}
500+
501+
static inline void bdev_dec_in_flight(struct block_device *bdev,
502+
enum req_op op)
503+
{
504+
bool rw = op_is_write(op);
505+
506+
part_stat_local_dec(bdev, in_flight[rw]);
507+
if (bdev_is_partition(bdev))
508+
part_stat_local_dec(bdev_whole(bdev), in_flight[rw]);
509+
}
510+
490511
/*
491512
* Internal io_context interface
492513
*/

0 commit comments

Comments
 (0)