Skip to content

Commit a2d6b3a

Browse files
damien-lemoalaxboe
authored andcommitted
block: Improve zone reset execution
There is no need to synchronously execute all REQ_OP_ZONE_RESET BIOs necessary to reset a range of zones. Similarly to what is done for discard BIOs in blk-lib.c, all zone reset BIOs can be chained and executed asynchronously and a synchronous call done only for the last BIO of the chain. Modify blkdev_reset_zones() to operate similarly to blkdev_issue_discard() using the next_bio() helper for chaining BIOs. To avoid code duplication of that function in blk_zoned.c, rename next_bio() into blk_next_bio() and declare it as a block internal function in blk.h. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 65e4e3e commit a2d6b3a

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

block/blk-lib.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
#include "blk.h"
1212

13-
static struct bio *next_bio(struct bio *bio, unsigned int nr_pages,
14-
gfp_t gfp)
13+
struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)
1514
{
1615
struct bio *new = bio_alloc(gfp, nr_pages);
1716

@@ -63,7 +62,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
6362

6463
end_sect = sector + req_sects;
6564

66-
bio = next_bio(bio, 0, gfp_mask);
65+
bio = blk_next_bio(bio, 0, gfp_mask);
6766
bio->bi_iter.bi_sector = sector;
6867
bio_set_dev(bio, bdev);
6968
bio_set_op_attrs(bio, op, 0);
@@ -165,7 +164,7 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
165164
max_write_same_sectors = UINT_MAX >> 9;
166165

167166
while (nr_sects) {
168-
bio = next_bio(bio, 1, gfp_mask);
167+
bio = blk_next_bio(bio, 1, gfp_mask);
169168
bio->bi_iter.bi_sector = sector;
170169
bio_set_dev(bio, bdev);
171170
bio->bi_vcnt = 1;
@@ -241,7 +240,7 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
241240
return -EOPNOTSUPP;
242241

243242
while (nr_sects) {
244-
bio = next_bio(bio, 0, gfp_mask);
243+
bio = blk_next_bio(bio, 0, gfp_mask);
245244
bio->bi_iter.bi_sector = sector;
246245
bio_set_dev(bio, bdev);
247246
bio->bi_opf = REQ_OP_WRITE_ZEROES;
@@ -292,8 +291,8 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
292291
return -EPERM;
293292

294293
while (nr_sects != 0) {
295-
bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects),
296-
gfp_mask);
294+
bio = blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects),
295+
gfp_mask);
297296
bio->bi_iter.bi_sector = sector;
298297
bio_set_dev(bio, bdev);
299298
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);

block/blk-zoned.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/rbtree.h>
1414
#include <linux/blkdev.h>
1515

16+
#include "blk.h"
17+
1618
static inline sector_t blk_zone_start(struct request_queue *q,
1719
sector_t sector)
1820
{
@@ -277,16 +279,17 @@ int blkdev_reset_zones(struct block_device *bdev,
277279
struct request_queue *q = bdev_get_queue(bdev);
278280
sector_t zone_sectors;
279281
sector_t end_sector = sector + nr_sectors;
280-
struct bio *bio;
282+
struct bio *bio = NULL;
283+
struct blk_plug plug;
281284
int ret;
282285

283-
if (!q)
284-
return -ENXIO;
285-
286286
if (!blk_queue_is_zoned(q))
287287
return -EOPNOTSUPP;
288288

289-
if (end_sector > bdev->bd_part->nr_sects)
289+
if (bdev_read_only(bdev))
290+
return -EPERM;
291+
292+
if (!nr_sectors || end_sector > bdev->bd_part->nr_sects)
290293
/* Out of range */
291294
return -EINVAL;
292295

@@ -299,27 +302,27 @@ int blkdev_reset_zones(struct block_device *bdev,
299302
end_sector != bdev->bd_part->nr_sects)
300303
return -EINVAL;
301304

305+
blk_start_plug(&plug);
302306
while (sector < end_sector) {
303307

304-
bio = bio_alloc(gfp_mask, 0);
308+
bio = blk_next_bio(bio, 0, gfp_mask);
305309
bio->bi_iter.bi_sector = sector;
306310
bio_set_dev(bio, bdev);
307311
bio_set_op_attrs(bio, REQ_OP_ZONE_RESET, 0);
308312

309-
ret = submit_bio_wait(bio);
310-
bio_put(bio);
311-
312-
if (ret)
313-
return ret;
314-
315313
sector += zone_sectors;
316314

317315
/* This may take a while, so be nice to others */
318316
cond_resched();
319317

320318
}
321319

322-
return 0;
320+
ret = submit_bio_wait(bio);
321+
bio_put(bio);
322+
323+
blk_finish_plug(&plug);
324+
325+
return ret;
323326
}
324327
EXPORT_SYMBOL_GPL(blkdev_reset_zones);
325328

block/blk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,6 @@ extern int blk_iolatency_init(struct request_queue *q);
488488
static inline int blk_iolatency_init(struct request_queue *q) { return 0; }
489489
#endif
490490

491+
struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp);
492+
491493
#endif /* BLK_INTERNAL_H */

0 commit comments

Comments
 (0)