From patchwork Fri Oct 12 10:08:47 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: 10638345 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 DAC8369B1 for ; Fri, 12 Oct 2018 10:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC3F02B845 for ; Fri, 12 Oct 2018 10:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C024E2B854; Fri, 12 Oct 2018 10:09:17 +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 595062B845 for ; Fri, 12 Oct 2018 10:09:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbeJLRkz (ORCPT ); Fri, 12 Oct 2018 13:40:55 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:63750 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728423AbeJLRky (ORCPT ); Fri, 12 Oct 2018 13:40:54 -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=1539338955; x=1570874955; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=BS9ewfn935aQfsf01xIKpqoRVjNmKZSGO+Yz/BXDAgk=; b=OMwbaeDKjE9PTVsgYrxGN6S/mCywSNWu4OBVWRykdmOTUjG9Bp4MGkyg 4m3JXuMcEiQXB5PIkH01VMPlZYRewPoEyGjQp1G2gb8CQA8L8EnGonhcV x5ZAbbdmun3HqT9c8xo/8YE5B5VV2LjnDfJ3KnvhXlPg6ogkjaa+gZT2Q KFT0z1BYDOdoviUOAPNtLccrl7XcHn0S6fF2jGhHaG+j99msbndgKFUrY GjidPFg5aljKLJ1RorCgHoiL7ksukHrDa5IzM3q5zVwwJemV8CzUK92Tz TtdJcTg8/RAbv6lhBiiltJKwFJe0yBWW6GhAlLzsFYUS/z+dbpnAVukS0 Q==; X-IronPort-AV: E=Sophos;i="5.54,371,1534780800"; d="scan'208";a="96419703" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 18:09:04 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 12 Oct 2018 02:54:23 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Oct 2018 03:09:03 -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 v4 08/11] block: Improve zone reset execution Date: Fri, 12 Oct 2018 19:08:47 +0900 Message-Id: <20181012100850.23316-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012100850.23316-1-damien.lemoal@wdc.com> References: <20181012100850.23316-1-damien.lemoal@wdc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 Reviewed-by: Hannes Reinecke --- 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 bb4ed69f917f..5d967fd39fbd 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 */