Skip to content

Commit 0b82cf6

Browse files
aarontomlinkawasaki
authored andcommitted
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 trace point 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 specific pool experiencing starvation (hardware or software scheduler), and the total pool depth. 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. Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Laurence Oberman <[email protected]> Tested-by: Laurence Oberman <[email protected]> Signed-off-by: Aaron Tomlin <[email protected]>
1 parent 6a0b974 commit 0b82cf6

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

block/blk-mq-tag.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/kmemleak.h>
1414

1515
#include <linux/delay.h>
16+
#include <trace/events/block.h>
1617
#include "blk.h"
1718
#include "blk-mq.h"
1819
#include "blk-mq-sched.h"
@@ -187,6 +188,9 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
187188
if (tag != BLK_MQ_NO_TAG)
188189
break;
189190

191+
trace_block_rq_tag_wait(data->q, data->hctx,
192+
data->rq_flags & RQF_SCHED_TAGS);
193+
190194
bt_prev = bt;
191195
io_schedule();
192196

include/trace/events/block.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,49 @@ DECLARE_EVENT_CLASS(block_rq,
226226
IOPRIO_PRIO_LEVEL(__entry->ioprio), __entry->comm)
227227
);
228228

229+
/**
230+
* block_rq_tag_wait - triggered when a request is starved of a tag
231+
* @q: request queue of the target device
232+
* @hctx: hardware context of the request experiencing starvation
233+
* @is_sched_tag: indicates whether the starved pool is the software scheduler
234+
*
235+
* Called immediately before the submitting context is forced to block due
236+
* to the exhaustion of available tags (i.e., physical hardware driver tags
237+
* or software scheduler tags). This trace point indicates that the context
238+
* will be placed into an uninterruptible state via io_schedule() until an
239+
* active request completes and relinquishes its assigned tag.
240+
*/
241+
TRACE_EVENT(block_rq_tag_wait,
242+
243+
TP_PROTO(struct request_queue *q, struct blk_mq_hw_ctx *hctx, bool is_sched_tag),
244+
245+
TP_ARGS(q, hctx, is_sched_tag),
246+
247+
TP_STRUCT__entry(
248+
__field( dev_t, dev )
249+
__field( u32, hctx_id )
250+
__field( u32, nr_tags )
251+
__field( bool, is_sched_tag )
252+
),
253+
254+
TP_fast_assign(
255+
__entry->dev = disk_devt(q->disk);
256+
__entry->hctx_id = hctx->queue_num;
257+
__entry->is_sched_tag = is_sched_tag;
258+
259+
if (is_sched_tag)
260+
__entry->nr_tags = hctx->sched_tags->nr_tags;
261+
else
262+
__entry->nr_tags = hctx->tags->nr_tags;
263+
),
264+
265+
TP_printk("%d,%d hctx=%u starved on %s tags (depth=%u)",
266+
MAJOR(__entry->dev), MINOR(__entry->dev),
267+
__entry->hctx_id,
268+
__entry->is_sched_tag ? "scheduler" : "hardware",
269+
__entry->nr_tags)
270+
);
271+
229272
/**
230273
* block_rq_insert - insert block operation request into queue
231274
* @rq: block IO operation request

0 commit comments

Comments
 (0)