Skip to content

Commit 9054650

Browse files
committed
block: relax jiffies rounding for timeouts
In doing high IOPS testing, blk-mq is generally pretty well optimized. There are a few things that stuck out as using more CPU than what is really warranted, and one thing is the round_jiffies_up() that we do twice for each request. That accounts for about 0.8% of the CPU in my testing. We can make this cheaper by avoiding an integer division, by just adding a rough HZ mask that we can AND with instead. The timeouts are only on a second granularity already, we don't have to be that accurate here and this patch barely changes that. All we care about is nice grouping. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 8789009 commit 9054650

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎block/blk-timeout.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,29 @@ void blk_abort_request(struct request *req)
8888
}
8989
EXPORT_SYMBOL_GPL(blk_abort_request);
9090

91+
static unsigned long blk_timeout_mask __read_mostly;
92+
93+
int __init blk_timeout_init(void)
94+
{
95+
blk_timeout_mask = roundup_pow_of_two(HZ) - 1;
96+
return 0;
97+
}
98+
99+
late_initcall(blk_timeout_init);
100+
101+
/*
102+
* Just a rough estimate, we don't care about specific values for timeouts.
103+
*/
104+
static inline unsigned long blk_round_jiffies(unsigned long j)
105+
{
106+
return (j + blk_timeout_mask) + 1;
107+
}
108+
91109
unsigned long blk_rq_timeout(unsigned long timeout)
92110
{
93111
unsigned long maxt;
94112

95-
maxt = round_jiffies_up(jiffies + BLK_MAX_TIMEOUT);
113+
maxt = blk_round_jiffies(jiffies + BLK_MAX_TIMEOUT);
96114
if (time_after(timeout, maxt))
97115
timeout = maxt;
98116

@@ -129,7 +147,7 @@ void blk_add_timer(struct request *req)
129147
* than an existing one, modify the timer. Round up to next nearest
130148
* second.
131149
*/
132-
expiry = blk_rq_timeout(round_jiffies_up(expiry));
150+
expiry = blk_rq_timeout(blk_round_jiffies(expiry));
133151

134152
if (!timer_pending(&q->timeout) ||
135153
time_before(expiry, q->timeout.expires)) {

0 commit comments

Comments
 (0)