Skip to content

Commit 1336981

Browse files
dennisszhouaxboe
authored andcommitted
block: fix blk-iolatency accounting underflow
The blk-iolatency controller measures the time from rq_qos_throttle() to rq_qos_done_bio() and attributes this time to the first bio that needs to create the request. This means if a bio is plug-mergeable or bio-mergeable, it gets to bypass the blk-iolatency controller. The recent series [1], to tag all bios w/ blkgs undermined how iolatency was determining which bios it was charging and should process in rq_qos_done_bio(). Because all bios are being tagged, this caused the atomic_t for the struct rq_wait inflight count to underflow and result in a stall. This patch adds a new flag BIO_TRACKED to let controllers know that a bio is going through the rq_qos path. blk-iolatency now checks if this flag is set to see if it should process the bio in rq_qos_done_bio(). Overloading BLK_QUEUE_ENTERED works, but makes the flag rules confusing. BIO_THROTTLED was another candidate, but the flag is set for all bios that have gone through blk-throttle code. Overloading a flag comes with the burden of making sure that when either implementation changes, a change in setting rules for one doesn't cause a bug in the other. So here, we unfortunately opt for adding a new flag. [1] https://lore.kernel.org/lkml/20181205171039.73066-1-dennis@kernel.org/ Fixes: 5cdf2e3 ("blkcg: associate blkg when associating a device") Signed-off-by: Dennis Zhou <dennis@kernel.org> Cc: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c16d6b5 commit 1336981

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

block/blk-iolatency.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static void blkcg_iolatency_done_bio(struct rq_qos *rqos, struct bio *bio)
593593
bool enabled = false;
594594

595595
blkg = bio->bi_blkg;
596-
if (!blkg)
596+
if (!blkg || !bio_flagged(bio, BIO_TRACKED))
597597
return;
598598

599599
iolat = blkg_to_lat(bio->bi_blkg);

block/blk-rq-qos.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ static inline void rq_qos_done_bio(struct request_queue *q, struct bio *bio)
168168

169169
static inline void rq_qos_throttle(struct request_queue *q, struct bio *bio)
170170
{
171+
/*
172+
* BIO_TRACKED lets controllers know that a bio went through the
173+
* normal rq_qos path.
174+
*/
175+
bio_set_flag(bio, BIO_TRACKED);
171176
if (q->rq_qos)
172177
__rq_qos_throttle(q->rq_qos, bio);
173178
}

include/linux/blk_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ struct bio {
228228
#define BIO_TRACE_COMPLETION 10 /* bio_endio() should trace the final completion
229229
* of this bio. */
230230
#define BIO_QUEUE_ENTERED 11 /* can use blk_queue_enter_live() */
231+
#define BIO_TRACKED 12 /* set if bio goes through the rq_qos path */
231232

232233
/* See BVEC_POOL_OFFSET below before adding new flags */
233234

0 commit comments

Comments
 (0)