block: fix inflight statistics of part0
PATCH 1/1 block: fix inflight statistics of part0
The inflight of partition 0 doesn't include inflight IOs to all sub-partitions, since currently mq calculates inflight of specific partition by simply camparing the value of the partition pointer.
Thus the following case is possible:
$ cat /sys/block/vda/inflight 0 0 $ cat /sys/block/vda/vda1/inflight 0 128
Partition 0 should be specially handled since it represents the whole disk.
--- block/blk-mq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-mq.c +2 -1
@@ -105,7 +105,8 @@ static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx, {struct mq_inflight *mi = priv; -if (rq->part == mi->part &&blk_mq_rq_state (rq) ==MQ_RQ_IN_FLIGHT ) +if ((!mi->part->partno || rq->part == mi->part) && +blk_mq_rq_state (rq) ==MQ_RQ_IN_FLIGHT ) mi->inflight[rq_data_dir (rq)]++;return true;
Signature · 1 line
2.27.0
Hello, any comment? Is this indeed a BUG or just a deliberate design?
Signature · 2 lines
Thanks, Jeffle
Quoted 34 lines · Jeffle Xu
The inflight of partition 0 doesn't include inflight IOs to all sub-partitions, since currently mq calculates inflight of specific partition by simply camparing the value of the partition pointer.
Thus the following case is possible:
$ cat /sys/block/vda/inflight 0 0 $ cat /sys/block/vda/vda1/inflight 0 128Partition 0 should be specially handled since it represents the whole disk.
Signed-off-by Jeffle Xu <[email protected]>--- block/blk-mq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)block/blk-mq.c +2
-1@@ -105,7 +105,8 @@ static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx, {struct mq_inflight *mi = priv; -if (rq->part == mi->part &&blk_mq_rq_state (rq) ==MQ_RQ_IN_FLIGHT ) +if ((!mi->part->partno || rq->part == mi->part) && +blk_mq_rq_state (rq) ==MQ_RQ_IN_FLIGHT ) mi->inflight[rq_data_dir (rq)]++;return true;
Quoted 6 lines · Jeffle Xu
The inflight of partition 0 doesn't include inflight IOs to all sub-partitions, since currently mq calculates inflight of specific partition by simply camparing the value of the partition pointer.
Thus the following case is possible:
Quoted 7 lines
$ cat /sys/block/vda/inflight ?? ?? ?? ??0 ?? ?? ?? ??0 $ cat /sys/block/vda/vda1/inflight ?? ?? ?? ??0 ?? ?? ??128Partition 0 should be specially handled since it represents the whole disk.
I'm not sure and can see arguments for either side. In doubt we should stick to historic behavior, can you check what old kernels (especially before blk-mq) did?
The traditional single queue block device has no problem. Following is the output when I writes to sda3 on version v3.10.
$cat /sys/block/sda/sda3/inflight
0 33
$cat /sys/block/sda/inflight
0 33On the other hand, we can analyze this from the code. Following code path for single-queue block device is from v4.19.
1. When reading '/sys/block/sda/inflight', the statistics is actually fetched from part 0.
part_inflight_show
part_in_flight_rw
inflight[0] = atomic_read(&part->in_flight[0]); inflight[1] = atomic_read(&part->in_flight[1]);
2. part 0 will always be updated whenever sub partition is updated.
blk_queue_bio
add_acct_request
blk_account_io_start
part_inc_in_flight
atomic_inc(&part->in_flight[rw])
if (part->partno)
atomic_inc(part0.in_flight[rw]);Quoted 19 lines · Christoph Hellwig
Quoted 6 lines · Jeffle Xu
The inflight of partition 0 doesn't include inflight IOs to all sub-partitions, since currently mq calculates inflight of specific partition by simply camparing the value of the partition pointer.
Thus the following case is possible:
Quoted 7 lines
$ cat /sys/block/vda/inflight ?? ?? ?? ??0 ?? ?? ?? ??0 $ cat /sys/block/vda/vda1/inflight ?? ?? ?? ??0 ?? ?? ??128Partition 0 should be specially handled since it represents the whole disk.
I'm not sure and can see arguments for either side. In doubt we should stick to historic behavior, can you check what old kernels (especially before blk-mq) did?
Signature · 2 lines
Thanks, Jeffle
Quoted 11 lines · Jeffle Xu
The inflight of partition 0 doesn't include inflight IOs to all sub-partitions, since currently mq calculates inflight of specific partition by simply camparing the value of the partition pointer.
Thus the following case is possible:
$ cat /sys/block/vda/inflight ?? ?? ?? ??0 ?? ?? ?? ??0 $ cat /sys/block/vda/vda1/inflight ?? ?? ?? ??0 ?? ?? ??128
Quoted 4 lines
Partition 0 should be specially handled since it represents the whole disk.
Signed-off-by Jeffle Xu <[email protected]>
Looks good:
But can you resend with your information on the old kernels, and maybe even with a Fixes tag?
Quoted 15 lines · Christoph Hellwig
Quoted 14 lines · Jeffle Xu
The inflight of partition 0 doesn't include inflight IOs to all sub-partitions, since currently mq calculates inflight of specific partition by simply camparing the value of the partition pointer.
Thus the following case is possible:
$ cat /sys/block/vda/inflight ?? ?? ?? ??0 ?? ?? ?? ??0 $ cat /sys/block/vda/vda1/inflight ?? ?? ?? ??0 ?? ?? ??128Partition 0 should be specially handled since it represents the whole disk.
Quoted 9 lines
Quoted 1 line
Signed-off-by Jeffle Xu <[email protected]>Looks good:
Reviewed-by Christoph Hellwig <[email protected]>But can you resend with your information on the old kernels, and maybe even with a Fixes tag?
Thanks, I will send a v2 version later.
Signature · 2 lines
Thanks, Jeffle