From patchwork Wed Oct 10 01:52:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10633811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04FFF5CAF for ; Wed, 10 Oct 2018 01:52:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7332298B6 for ; Wed, 10 Oct 2018 01:52:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB1B4298CA; Wed, 10 Oct 2018 01:52:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75050298DB for ; Wed, 10 Oct 2018 01:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbeJJJMl (ORCPT ); Wed, 10 Oct 2018 05:12:41 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:39878 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbeJJJMl (ORCPT ); Wed, 10 Oct 2018 05:12:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1539136373; x=1570672373; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=pqNKRbqnbylm6SIphQ5txbyQcPuJV/jCoLIpdxdyfVA=; b=S07LuC3aFgXqwp0gi5O/5X1ApMF0608jsob+4YtBY/q70Blt5yHyERYa gjjRtt1L2VMYR5uk78HxhgzI9chQe5ymWc6qtyBW/JKt/2NCszIGEP24D hyaOWzUdzImm29fmdJpeuYpC87dRsI7lpUsxHHya9UHz0wwaGlEDDpWaY xXWkJTYFYiqq92pQhjumwum7wR9P81Kbb5ljDjt3y3s6+e3TlZwlM5yJp FRt+HU/XMkA1nMV4NOJVkP9Xy99dq0sQBK8dXNiZWrUf/5rJP+3DcAfzO CQDE4MCLt8EVLmBBYV0oRu0zd1rx0WqE0yoqvNJ6Qfr8IF0LQHHefRCFs A==; X-IronPort-AV: E=Sophos;i="5.54,362,1534780800"; d="scan'208";a="92692979" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2018 09:52:53 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Oct 2018 18:38:19 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Oct 2018 18:52:52 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Christoph Hellwig , Matias Bjorling Subject: [PATCH 08/11] block: Improve zone reset execution Date: Wed, 10 Oct 2018 10:52:36 +0900 Message-Id: <20181010015239.24930-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010015239.24930-1-damien.lemoal@wdc.com> References: <20181010015239.24930-1-damien.lemoal@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig --- block/blk-lib.c | 13 ++++++------- block/blk-zoned.c | 29 ++++++++++++++++------------- block/blk.h | 2 ++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index d1b9dd03da25..d7bedee5f9ba 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -10,8 +10,7 @@ #include "blk.h" -static struct bio *next_bio(struct bio *bio, unsigned int nr_pages, - gfp_t gfp) +struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) { struct bio *new = bio_alloc(gfp, nr_pages); @@ -87,7 +86,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, req_sects = end_sect - sector; } - bio = next_bio(bio, 0, gfp_mask); + bio = blk_next_bio(bio, 0, gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio_set_op_attrs(bio, op, 0); @@ -189,7 +188,7 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector, max_write_same_sectors = UINT_MAX >> 9; while (nr_sects) { - bio = next_bio(bio, 1, gfp_mask); + bio = blk_next_bio(bio, 1, gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio->bi_vcnt = 1; @@ -265,7 +264,7 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, return -EOPNOTSUPP; while (nr_sects) { - bio = next_bio(bio, 0, gfp_mask); + bio = blk_next_bio(bio, 0, gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio->bi_opf = REQ_OP_WRITE_ZEROES; @@ -316,8 +315,8 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, return -EPERM; while (nr_sects != 0) { - bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), - gfp_mask); + bio = blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), + gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio_set_op_attrs(bio, REQ_OP_WRITE, 0); diff --git a/block/blk-zoned.c b/block/blk-zoned.c index f2c8b859fc18..ca2faef940af 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -13,6 +13,8 @@ #include #include +#include "blk.h" + static inline sector_t blk_zone_start(struct request_queue *q, sector_t sector) { @@ -277,16 +279,17 @@ int blkdev_reset_zones(struct block_device *bdev, struct request_queue *q = bdev_get_queue(bdev); sector_t zone_sectors; sector_t end_sector = sector + nr_sectors; - struct bio *bio; + struct bio *bio = NULL; + struct blk_plug plug; int ret; - if (!q) - return -ENXIO; - if (!blk_queue_is_zoned(q)) return -EOPNOTSUPP; - if (end_sector > bdev->bd_part->nr_sects) + if (bdev_read_only(bdev)) + return -EPERM; + + if (!nr_sectors || end_sector > bdev->bd_part->nr_sects) /* Out of range */ return -EINVAL; @@ -299,19 +302,14 @@ int blkdev_reset_zones(struct block_device *bdev, end_sector != bdev->bd_part->nr_sects) return -EINVAL; + blk_start_plug(&plug); while (sector < end_sector) { - bio = bio_alloc(gfp_mask, 0); + bio = blk_next_bio(bio, 0, gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio_set_op_attrs(bio, REQ_OP_ZONE_RESET, 0); - ret = submit_bio_wait(bio); - bio_put(bio); - - if (ret) - return ret; - sector += zone_sectors; /* This may take a while, so be nice to others */ @@ -319,7 +317,12 @@ int blkdev_reset_zones(struct block_device *bdev, } - return 0; + ret = submit_bio_wait(bio); + bio_put(bio); + + blk_finish_plug(&plug); + + return ret; } EXPORT_SYMBOL_GPL(blkdev_reset_zones); diff --git a/block/blk.h b/block/blk.h index 9db4e389582c..3d67844676fb 100644 --- a/block/blk.h +++ b/block/blk.h @@ -421,4 +421,6 @@ extern int blk_iolatency_init(struct request_queue *q); static inline int blk_iolatency_init(struct request_queue *q) { return 0; } #endif +struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp); + #endif /* BLK_INTERNAL_H */