Skip to contentSkip to conversation

block: fix inflight statistics of part0

PATCH Superseded Jeffle Xu 2 participants 6 messages Nov 26, 2020 – Dec 2, 2020 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeffle Xu

author
#0 lore raw

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
index 55bcee5dc032..04b6b4d21ce6 100644
@@ -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
author
#1 lore raw

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      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
index 55bcee5dc032..04b6b4d21ce6 100644
@@ -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;
#2 lore raw
In reply to Jeffle Xu
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 ?? ?? ??128

Partition 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?

author
#3 lore raw

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       33

On 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 ?? ?? ??128

Partition 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
Reviewed-by on v1 1/1
#4 lore raw
In reply to Jeffle Xu
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.

Looks good:

But can you resend with your information on the old kernels, and maybe even with a Fixes tag?

author
#5 lore raw
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 ?? ?? ??128

Partition 0 should be specially handled since it represents the whole disk.

Quoted 9 lines
Quoted 1 line

Looks good:

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