blk-mq: add tracepoint block_rq_tag_wait
Subsystems (2)
PATCH 1/1 blk-mq: add tracepoint block_rq_tag_wait
In high-performance storage environments, particularly when utilising RAID controllers with shared tag sets (BLK_MQ_F_TAG_HCTX_SHARED), severe latency spikes can occur when fast devices (SSDs) are starved of hardware tags when sharing the same blk_mq_tag_set.
Currently, diagnosing this specific hardware queue contention is difficult. When a CPU thread exhausts the tag pool, blk_mq_get_tag() forces the current thread to block uninterruptible via io_schedule(). While this can be inferred via sched:sched_switch or dynamically traced by attaching a kprobe to blk_mq_mark_tag_wait(), there is no dedicated, out-of-the-box observability for this event.
This patch introduces the block_rq_tag_wait static tracepoint in the tag allocation slow-path. It triggers immediately before the thread yields the CPU, exposing the exact hardware context (hctx) that is starved, the total pool size, and the current active request count.
This provides storage engineers and performance monitoring agents with a zero-configuration, low-overhead mechanism to definitively identify shared-tag bottlenecks and tune I/O schedulers or cgroup throttling accordingly.
--- block/blk-mq-tag.c | 3 +++ include/trace/events/block.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
block/blk-mq-tag.c +3 -0
@@ -13,6 +13,7 @@#include <linux/kmemleak.h> #include <linux/delay.h> +#include <trace/events/block.h> #include "blk.h" #include "blk-mq.h" #include "blk-mq-sched.h"
@@ -187,6 +188,8 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)if (tag !=BLK_MQ_NO_TAG )break ; +trace_block_rq_tag_wait (data->q, data->hctx); + bt_prev = bt;io_schedule ();
include/trace/events/block.h +36 -0
@@ -226,6 +226,42 @@ DECLARE_EVENT_CLASS(block_rq, IOPRIO_PRIO_LEVEL(__entry->ioprio), __entry->comm) ); +/** +* block_rq_tag_wait - triggered when an I/O request is starved of a tag +* @q: queue containing the request +* @hctx: hardware context (queue) experiencing starvation +* +* Called immediately before the submitting thread is forced to block due +* to the exhaustion of available hardware tags. This tracepoint indicates +* that the thread will be placed into an uninterruptible state via +* io_schedule() until an active block I/O operation completes and +* relinquishes its assigned tag. +*/ +TRACE_EVENT (block_rq_tag_wait, + + TP_PROTO(struct request_queue *q, struct blk_mq_hw_ctx *hctx), + +TP_ARGS (q, hctx), + +TP_STRUCT__entry ( + __field( dev_t, dev ) + __field( u32, hctx_id ) + __field( u32, nr_tags ) +__field ( u32, active_requests ) + ), + +TP_fast_assign ( + __entry->dev = q->disk ? disk_devt(q->disk) : 0; + __entry->hctx_id = hctx ? hctx->queue_num : 0; + __entry->nr_tags = hctx && hctx->tags ? hctx->tags->nr_tags : 0; + __entry->active_requests = hctx ? atomic_read(&hctx->nr_active) : 0; + ), + +TP_printk ("%d,%d hctx=%u starved (active=%u/%u)" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->hctx_id, __entry->active_requests, __entry->nr_tags) +); +/** * block_rq_insert - insert block operation request into queue * @rq: block IO operation request
Signature · 1 line
2.51.0
Quoted 18 lines · Aaron Tomlin
In high-performance storage environments, particularly when utilising RAID controllers with shared tag sets (
BLK_MQ_F_TAG_HCTX_SHARED), severe latency spikes can occur when fast devices (SSDs) are starved of hardware tags when sharing the sameblk_mq_tag_set.Currently, diagnosing this specific hardware queue contention is difficult. When a CPU thread exhausts the tag pool,
blk_mq_get_tag()forces the current thread to block uninterruptible viaio_schedule(). While this can be inferred via sched:sched_switch or dynamically traced by attaching a kprobe toblk_mq_mark_tag_wait(), there is no dedicated, out-of-the-box observability for this event.This patch introduces the
block_rq_tag_waitstatic tracepoint in the tag allocation slow-path. It triggers immediately before the thread yields the CPU, exposing the exact hardware context (hctx) that is starved, the total pool size, and the current active request count.
Quoted 6 lines
This provides storage engineers and performance monitoring agents with a zero-configuration, low-overhead mechanism to definitively identify shared-tag bottlenecks and tune I/O schedulers or cgroup throttling accordingly.
Signed-off-by Aaron Tomlin <[email protected]>
Looks OK to me, but I have some suggestions below.
Quoted 31 lines
--- block/blk-mq-tag.c | 3 +++ include/trace/events/block.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)block/blk-mq-tag.c +3
-0@@ -13,6 +13,7 @@#include <linux/kmemleak.h> #include <linux/delay.h> +#include <trace/events/block.h> #include "blk.h" #include "blk-mq.h" #include "blk-mq-sched.h" @@ -187,6 +188,8 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)if (tag !=BLK_MQ_NO_TAG )break ; +trace_block_rq_tag_wait (data->q, data->hctx); + bt_prev = bt;io_schedule ();include/trace/events/block.h +0
-0
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 230
Quoted 5 lines
include/trace/events/block.h +2
-0@@ -226,6 +226,42 @@ DECLARE_EVENT_CLASS(block_rq, IOPRIO_PRIO_LEVEL(__entry->ioprio), __entry->comm) ); +/** +* block_rq_tag_wait - triggered when an I/O request is starved of a tag
when an I/O request -> when a request
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 231
Quoted 1 line
include/trace/events/block.h +1
-0+* @q: queue containing the request
request queue of the target device
("containing" is odd here)
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 232
Quoted 1 line
include/trace/events/block.h +1
-0+* @hctx: hardware context (queue) experiencing starvation
hardware context of the request
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 234
Quoted 2 lines
include/trace/events/block.h +2
-0+* +* Called immediately before the submitting thread is forced to block due
the submitting thread -> the submitting context
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 235
Quoted 1 line
include/trace/events/block.h +1
-0+* to the exhaustion of available hardware tags. This tracepoint indicates
s/tracepoint/trace point
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 236
Quoted 1 line
include/trace/events/block.h +1
-0+* that the thread will be placed into an uninterruptible state via
s/thread/context
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 238
Quoted 2 lines
include/trace/events/block.h +2
-0+* io_schedule() until an active block I/O operation completes and +* relinquishes its assigned tag.
until an active request completes
(BIOs do not have tags).
Quoted 6 lines
include/trace/events/block.h +6
-0+*/ +TRACE_EVENT(block_rq_tag_wait, + + TP_PROTO(struct request_queue *q, struct blk_mq_hw_ctx *hctx), + + TP_ARGS(q, hctx),
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 254
Quoted 10 lines
include/trace/events/block.h +10
-0+ +TP_STRUCT__entry ( +__field (dev_t ,dev ) +__field ( u32, hctx_id ) +__field ( u32, nr_tags ) +__field ( u32, active_requests ) + ), + +TP_fast_assign ( + __entry->dev = q->disk ? disk_devt(q->disk) : 0;
I do not think that q->disk can ever be NULL when there is a request being submitted.
Quoted 13 lines
include/trace/events/block.h +10
-0+ __entry->hctx_id = hctx ? hctx->queue_num :0 ; + __entry->nr_tags = hctx && hctx->tags ? hctx->tags->nr_tags :0 ; + __entry->active_requests = hctx ?atomic_read (&hctx->nr_active) :0 ; + ), + +TP_printk ("%d,%d hctx=%u starved (active=%u/%u)" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->hctx_id, __entry->active_requests, __entry->nr_tags) +); +/** * block_rq_insert - insert block operation request into queue * @rq: block IO operation request
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 147 lines · Damien Le Moal
Quoted 24 lines · Aaron Tomlin
In high-performance storage environments, particularly when utilising
RAID controllers with shared tag sets (BLK_MQ_F_TAG_HCTX_SHARED), severe
latency spikes can occur when fast devices (SSDs) are starved of hardware
tags when sharing the sameblk_mq_tag_set.Currently, diagnosing this specific hardware queue contention is difficult. When a CPU thread exhausts the tag pool,
blk_mq_get_tag()
forces the current thread to block uninterruptible viaio_schedule().
While this can be inferred via sched:sched_switch or dynamically traced by attaching a kprobe toblk_mq_mark_tag_wait(), there is no dedicated, out-of-the-box observability for this event.This patch introduces the
block_rq_tag_waitstatic tracepoint in the tag allocation slow-path. It triggers immediately before the thread yields the CPU, exposing the exact hardware context (hctx) that is starved, the total pool size, and the current active request
count.Quoted 6 lines
This provides storage engineers and performance monitoring agents with a zero-configuration, low-overhead mechanism to definitively identify shared-tag bottlenecks and tune I/O schedulers or cgroup throttling accordingly.
Signed-off-by Aaron Tomlin <[email protected]>Looks OK to me, but I have some suggestions below.
Quoted 35 lines
---
block/blk-mq-tag.c | 3 +++
include/trace/events/block.h | 36
++++++++++++++++++++++++++++++++++++2 files changed, 39 insertions(+)block/blk-mq-tag.c +0
-0@@ -13,6 +13,7 @@ #include <linux/kmemleak.h>
#include <linux/delay.h>
+#include <trace/events/block.h>
#include "blk.h"
#include "blk-mq.h"
#include "blk-mq-sched.h"block/blk-mq-tag.c +0
-0@@ -187,6 +188,8 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data) if (tag != BLK_MQ_NO_TAG) break;block/blk-mq-tag.c +2
-0+trace_block_rq_tag_wait (data->q, data->hctx); +
bt_prev= bt;
io_schedule();include/trace/events/block.h +0
-0@@ -226,6 +226,42 @@ DECLARE_EVENT_CLASS(block_rq,
IOPRIO_PRIO_LEVEL(__entry->ioprio), __entry-Quoted 6 lines
Quoted 1 line
comm)
);
+/**
+ *block_rq_tag_wait- triggered when an I/O request is starved of a tagwhen an I/O request -> when a request
Quoted 1 line
+ * @q: queue containing the request
request queue of the target device
("containing" is odd here)
Quoted 1 line
+ * @hctx: hardware context (queue) experiencing starvation
hardware context of the request
Quoted 3 lines
+ *
+ * Called immediately before the submitting thread is forced to block duethe submitting thread -> the submitting context
Quoted 2 lines
+ * to the exhaustion of available hardware tags. This tracepoint indicates
s/tracepoint/trace point
Quoted 2 lines
+ * that the thread will be placed into an uninterruptible state via
s/thread/context
Quoted 2 lines
+ *
io_schedule()until an active block I/O operation completes and
+ * relinquishes its assigned tag.until an active request completes
(BIOs do not have tags).
Quoted 21 lines
+ */
include/trace/events/block.h +3
-0+TRACE_EVENT(block_rq_tag_wait, + + TP_PROTO(struct request_queue *q, struct blk_mq_hw_ctx*hctx),
include/trace/events/block.h +5
-0+ +TP_ARGS (q, hctx), + + TP_STRUCT__entry( + __field(
dev_t, dev )include/trace/events/block.h +1
-0+ __field(u32,
hctx_id)include/trace/events/block.h +1
-0+ __field(u32,
nr_tags)include/trace/events/block.h +1
-0+ __field(u32,
active_requests)include/trace/events/block.h +4
-0+ ), + + TP_fast_assign( + __entry->dev = q->disk ? disk_devt(q-Quoted 1 line
Quoted 1 line
disk) : 0;
I do not think that
q->diskcan ever be NULL when there is a request being
submitted.Quoted 9 lines
include/trace/events/block.h +1
-0+ __entry->hctx_id = hctx ? hctx->queue_num: 0;
include/trace/events/block.h +1
-0+ __entry->nr_tags = hctx && hctx->tags ?
hctx->tags->nr_tags: 0;include/trace/events/block.h +1
-0+ __entry->active_requests = hctx ?
atomic_read(&hctx->nr_active): 0;include/trace/events/block.h +3
-0+ ), + + TP_printk("%d,%d hctx=%u starved (active=%u/%u)",
Quoted 9 lines
Quoted 8 lines
include/trace/events/block.h +2
-0+ MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->hctx_id, __entry->active_requests,
__entry->nr_tags)include/trace/events/block.h +2
-0+); +/**
*block_rq_insert- insert block operation request into queue
* @rq: block IO operation request
This visibility will be very useful. I plan to test it fully. Updates to follow
Thanks
Laurence Oberman
Quoted 1 line · Damien Le Moal
Looks OK to me, but I have some suggestions below.
Hi Damien,
Thank you for your feedback.
Quoted 5 lines
Quoted 3 lines
+/**
+ *block_rq_tag_wait- triggered when an I/O request is starved of a tagwhen an I/O request -> when a request
Acknowledged.
Quoted 6 lines
Quoted 2 lines
+ * @q: queue containing the request
request queue of the target device
("containing" is odd here)
Acknowledged.
Quoted 3 lines
Quoted 1 line
+ * @hctx: hardware context (queue) experiencing starvation
hardware context of the request
Acknowledged.
Quoted 4 lines
Quoted 2 lines
+ *
+ * Called immediately before the submitting thread is forced to block duethe submitting thread -> the submitting context
Acknowledged.
Quoted 4 lines
Quoted 2 lines
+ * to the exhaustion of available hardware tags. This tracepoint indicates
s/tracepoint/trace point
Acknowledged.
Quoted 4 lines
Quoted 2 lines
+ * that the thread will be placed into an uninterruptible state via
s/thread/context
Acknowledged.
Quoted 6 lines
Quoted 3 lines
+ *
io_schedule()until an active block I/O operation completes and
+ * relinquishes its assigned tag.until an active request completes
Acknowledged.
Quoted 11 lines
Quoted 11 lines
+ */
include/trace/events/block.h +10
-0+TRACE_EVENT(block_rq_tag_wait, + + TP_PROTO(struct request_queue *q, struct blk_mq_hw_ctx *hctx), + + TP_ARGS(q, hctx), + + TP_STRUCT__entry( + __field( dev_t, dev ) + __field( u32, hctx_id ) + __field( u32, nr_tags )
Quoted 8 lines
include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 254
Quoted 5 lines
include/trace/events/block.h +5
-0+__field ( u32, active_requests ) + ), + +TP_fast_assign ( + __entry->dev = q->disk ? disk_devt(q->disk) : 0;I do not think that
q->diskcan ever be NULL when there is a request being submitted.
Yes, I agree. In theory, a race with disk_release() cannot occur since the gendisk reference counter would still be elevated here.
Quoted 14 lines
Quoted 4 lines
include/trace/events/block.h +3
-0+ __entry->hctx_id = hctx ? hctx->queue_num :0 ; + __entry->nr_tags = hctx && hctx->tags ? hctx->tags->nr_tags :0 ; + __entry->active_requests = hctx ?atomic_read (&hctx->nr_active) :0 ;include/trace/events/block.h DECLARE_EVENT_CLASS(block_rq, · line 267
Quoted 10 lines
include/trace/events/block.h +7
-0+ ), + +TP_printk ("%d,%d hctx=%u starved (active=%u/%u)" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->hctx_id, __entry->active_requests, __entry->nr_tags) +); +/** * block_rq_insert - insert block operation request into queue * @rq: block IO operation request
Kind regards,
Signature · 1 line
Aaron Tomlin
Quoted 2 lines · Aaron Tomlin
Quoted 1 line · Damien Le Moal
Looks OK to me, but I have some suggestions below.
Hi Damien, Laurence,
Upon reviewing the source code once more, it becomes apparent that tracking "active requests" within this specific trace point is essentially redundant. If a thread is compelled to invoke io_schedule(), it is mathematically certain that the number of active requests perfectly equals the total number of tags.
Now, it would almost always print active=0 in the following scenarios:
1. "mq-deadline" Scheduler Starvation: The thread sleeps waiting for a scheduler tag. Because the request has not been dispatched to hardware yet, blk_mq_inc_active_requests() was never called. hctx->nr_active is 0.
2. NVMe Hardware Starvation, "none" scheduler: The thread sleeps waiting for a hardware tag. Because NVMe drives do not share tags, blk_mq_inc_active_requests() instantly aborts to save CPU-cycles. hctx->nr_active remains 0.
3. RAID Hardware Starvation, "none" scheduler: The thread sleeps waiting for a shared hardware tag. Because it is HCTX_SHARED, the kernel tracks the active requests in hctx->queue->nr_active_requests_shared_tags. The local hctx->nr_active counter is completely bypassed and remains 0.
Rather than attempting to print the active count, the trace point should be modified to indicate exactly which pool experienced starvation: the hardware pool or the software scheduler pool.
I will submit a follow-up patch.
Kind regards,
Signature · 1 line
Aaron Tomlin