Skip to content

Commit 5577022

Browse files
Vladimir Davydovaxboe
authored andcommitted
block: account iowait time when waiting for completion of IO request
Using wait_for_completion() for waiting for a IO request to be executed results in wrong iowait time accounting. For example, a system having the only task doing write() and fdatasync() on a block device can be reported being idle instead of iowaiting as it should because blkdev_issue_flush() calls wait_for_completion() which in turn calls schedule() that does not increment the iowait proc counter and thus does not turn on iowait time accounting. The patch makes block layer use wait_for_completion_io() instead of wait_for_completion() where appropriate to account iowait time correctly. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 686855f commit 5577022

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎block/blk-exec.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ int blk_execute_rq(struct request_queue *q, struct gendisk *bd_disk,
120120
/* Prevent hang_check timer from firing at us during very long I/O */
121121
hang_check = sysctl_hung_task_timeout_secs;
122122
if (hang_check)
123-
while (!wait_for_completion_timeout(&wait, hang_check * (HZ/2)));
123+
while (!wait_for_completion_io_timeout(&wait, hang_check * (HZ/2)));
124124
else
125-
wait_for_completion(&wait);
125+
wait_for_completion_io(&wait);
126126

127127
if (rq->errors)
128128
err = -EIO;

‎block/blk-flush.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
436436

437437
bio_get(bio);
438438
submit_bio(WRITE_FLUSH, bio);
439-
wait_for_completion(&wait);
439+
wait_for_completion_io(&wait);
440440

441441
/*
442442
* The driver must store the error location in ->bi_sector, if

‎block/blk-lib.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
126126

127127
/* Wait for bios in-flight */
128128
if (!atomic_dec_and_test(&bb.done))
129-
wait_for_completion(&wait);
129+
wait_for_completion_io(&wait);
130130

131131
if (!test_bit(BIO_UPTODATE, &bb.flags))
132132
ret = -EIO;
@@ -200,7 +200,7 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
200200

201201
/* Wait for bios in-flight */
202202
if (!atomic_dec_and_test(&bb.done))
203-
wait_for_completion(&wait);
203+
wait_for_completion_io(&wait);
204204

205205
if (!test_bit(BIO_UPTODATE, &bb.flags))
206206
ret = -ENOTSUPP;
@@ -262,7 +262,7 @@ int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
262262

263263
/* Wait for bios in-flight */
264264
if (!atomic_dec_and_test(&bb.done))
265-
wait_for_completion(&wait);
265+
wait_for_completion_io(&wait);
266266

267267
if (!test_bit(BIO_UPTODATE, &bb.flags))
268268
/* One of bios in the batch was completed with error.*/

0 commit comments

Comments
 (0)