From patchwork Wed Nov 30 20:28:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 9454853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B8F96074E for ; Wed, 30 Nov 2016 20:29:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F53F284A2 for ; Wed, 30 Nov 2016 20:29:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03E33284A3; Wed, 30 Nov 2016 20:29:34 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 78E4F28497 for ; Wed, 30 Nov 2016 20:29:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757814AbcK3U3a (ORCPT ); Wed, 30 Nov 2016 15:29:30 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:16841 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753868AbcK3U33 (ORCPT ); Wed, 30 Nov 2016 15:29:29 -0500 X-IronPort-AV: E=Sophos;i="5.31,574,1473091200"; d="scan'";a="41649604" Received: from mail-co1nam03lp0020.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) ([216.32.181.20]) by ob1.hgst.iphmx.com with ESMTP; 01 Dec 2016 04:29:28 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Vx2Ub6V07AnRhqwm2od2ECkyHRmsZI+fdVMprrr4FcY=; b=DXv5zdz1yQWZ4IPH7a2OUVgUlopxWrOzqayLLi3QnUJklpdDTbWS1OaF7ShNEm8S3NUpr4/GzO/vScwQeqpkzncd1MaZD8wFVWvrasyj6YQm3oTgrPJUoxX9HGXwcQZiNSnlEdsQfEyD6ZDEQ32pyGlF+MlmHFdkA7EqNbx5vk8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Chaitanya.Kulkarni@wdc.com; Received: from ztester-Precision-T3600.hgst.com (199.255.44.5) by CO2PR04MB2184.namprd04.prod.outlook.com (10.166.93.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Wed, 30 Nov 2016 20:29:26 +0000 From: Chaitanya Kulkarni To: axboe@fb.com Cc: martin.petersen@oracle.com, keith.busch@intel.com, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, Chaitanya Kulkarni Subject: [PATCH V2 1/5] block: add async variant of blkdev_issue_zeroout Date: Wed, 30 Nov 2016 12:28:58 -0800 Message-Id: <1480537742-15190-1-git-send-email-chaitanya.kulkarni@hgst.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [199.255.44.5] X-ClientProxiedBy: BY2PR06CA0019.namprd06.prod.outlook.com (10.166.106.157) To CO2PR04MB2184.namprd04.prod.outlook.com (10.166.93.154) X-MS-Office365-Filtering-Correlation-Id: 16447a23-0015-48f0-9737-08d4195f94e3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CO2PR04MB2184; X-Microsoft-Exchange-Diagnostics: 1; CO2PR04MB2184; 3:eBPzVACfGs0bO42CkuvhEuhFEafjATuo7pGyoH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fVK6imWqQgV8Jzweuq+Z1EgnBGT7a5H152y3SvPV0mP1xkC7ml9Bv4tK+9EYnYN2TrX39tTUjx+1QiVH3MZrbDBBY3i9GblopIIck8lTSafIzBTyyk7Tft7cxodB0iwZDX0jYxKmr0VlHBaC2GSs9jz3fYYfNBUPVb1Ogbhfji4YERAVZbl90dXFhrs2v51hy/MRxx7S+KT7/SY/XQRu7ICju67clw0zDIUouBRz81ydcTJAErn+GbZo3iXjCkMu9r1ArZ2oDD4BhyVJny7iTLL1IW2QN98ePgSwkGlQ+RQHVUdBSM3/CtSeicbb4nBnjD8nAhRTJvm3sWgcxYd7D1tBleu+Q+RiLY2cUgYA+l/Lf4LLgm/wlp7G2Vesgnj+mW3kbZ5ZE48ryz5czt+9Km9e4MGdVRn+iHX5n5LqpzpwGfiCldoAJiFttsh8YJf+h3oQD098IadGV8qJ69xUoRHhCqcFPyja0QT4R X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(79135771888625); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:CO2PR04MB2184; BCL:0; PCL:0; RULEID:; SRVR:CO2PR04MB2184; X-Microsoft-Exchange-Diagnostics: 1; CO2PR04MB2184; 4:vx+dz/ZJ7Im0Kjjk6a6amGa9Wc3eRm7aKWbmmRtMdQd9kcdc+u5hSdzrXO9o6i1UJYTptA/F+GtcnZtkkLXa4j+Phq3bCmhaq8tGFa7rpGPrksAmhVB27J0j80Wuq2NATlHepWZTMTAdk4Lp3H6yipCrMSrttIoC0k4vmU9DZ4CRb8TwmGkmJAwn9Ly3Nk47stM/JlEq69aGS7y9B670N4mcIHcggWh0YeRb3uuju184h6C5R/tSgx/rrG+MHAp+Q5xnvXJTTrMK99CJwqm/aGtWtPGDabHFN8fx7YvhuonBsiWIFA1FTm2DU2uKwyyzjXNNlynlPDFrZ9U576YKY6t+SDaavZ6p6AA/elp9NckKxEPRobix5ghntbyhhANJLT4DOlxVQe1Vfx5jKBnTyrnScxndIya0SMLDMaPxJT34G9/uTiUDC8X2KczW5C0SIMs4b7HQentvNXxYhrCpxRmZzX0WIe18ZWI39FFyY6+DvKkHL5pnV1tQQ7fQhOPCI/vxxF3aoRy9nsbvLadnMeTXg/43vn1k2BSeu2nZssvsi4MfOjdrMe3WHoG3bdH2baR6uk/COgpwL9d2OmxRk5RCYGm5h3DPvdcsxDXuLIh7LrS+PqoqXDVr1UNrGk3QgtmMvbL1UZ60OOelw3ky4g== X-Forefront-PRVS: 0142F22657 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(50944005)(189002)(92566002)(81156014)(81166006)(68736007)(38730400001)(39410400001)(50226002)(42882006)(39450400002)(8676002)(733004)(69596002)(6486002)(66066001)(6666003)(50986999)(47776003)(101416001)(106356001)(107886002)(33646002)(42186005)(2361001)(53416004)(2351001)(4326007)(36756003)(5003940100001)(189998001)(105586002)(4001430100002)(2906002)(5660300001)(6916009)(3846002)(6116002)(97736004)(305945005)(48376002)(7736002)(50466002)(110136003)(7846002)(7099028)(5005270100013); DIR:OUT; SFP:1102; SCL:1; SRVR:CO2PR04MB2184; H:ztester-Precision-T3600.hgst.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: wdc.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR04MB2184; 23:FcShyLV0psMJiSudBYrFeSPII2AzSjigVLL+2B2vO?= =?us-ascii?Q?Vcz6Uc0TNxSPMiz0DYjJ8UqJ9kexMqZSaTQhG9xBsBUdl2bM0wOiDFjOpBI/?= =?us-ascii?Q?F34n9wGXLQUxAwOnE9D2UMpQVMc+temMX7DJTetM+hdmzqkIlJ5n6NEHCxa6?= =?us-ascii?Q?7JA1JvkefbjK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aSbK7XRBCN55VkAQPlvasY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CO2PR04MB2184; 7:PRyGnGlTzpWW3Y/zcvVQV06rfT1fAzYZEl3EzXRweWrwZh7i392pYrKj2oldC8A+3hgqvBitSbdgpvfT5j9bB1fkzSeVY6p0TaEAeirMuwFQCkEv5R9YW80Hk1xuwoRC1VLf3nvU2TTSrd7F+0z9KdpCTQUqj9ciSzLwK+pT56Ma/s1W5S4dyPY8Nok3F35+Zy+ZHNBPzZQWX9QRqYq6JfSfNzFTeAf9m58z7lvyEADEbALUO9UgnNQvk+R9OFM3oUJCeekWFCLsTvykdO7YWAjMZBTKvPckds3nQfnBJxSg1I27w0QpRWuG7HIFT0oTpz0SzDw7t8j/qLRufwpgfpuBircJgSyGlYJZaslK0FMyWsVMUwHO3CE99jzdBw4UkWO3ErS/m2SCSWHGz2prH7+8TrfFu8i0Tu6X3ddSYBqFyiAxaLGdUUdmfbGjnH5OWe6UGCHJu8yzLWPmqis0xw==; 20:rk3heEgC0PdjuwWzvK0XfN7eMnu+1NEAIoCUbQWtX3zu3sMcsvnboc9HaaCzeei3PRkGz2GKX47M3VEeOM4B1/6f7O9p9TTZWVsWP+DFOQ0BzWqxv6tv0Tpop27YI5sbs7oxIoANR5/OOzBz0lHGRhpvcqn9vebVTUe5WSDqIPpT4zanjQLrxG2aTtO+GJzrqCjrkQIO/UB/V3KL+ZNpIxmj3EVGHrsZrdrYkkYh/P9duwG9d/GNrB/O+m2dPTOO X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2016 20:29:26.9041 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR04MB2184 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 Similar to __blkdev_issue_discard this variant allows submitting the final bio asynchronously and chaining multiple ranges into a single completion. Signed-off-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig --- block/blk-lib.c | 115 ++++++++++++++++++++++++++++++++++--------------- include/linux/blkdev.h | 3 ++ 2 files changed, 84 insertions(+), 34 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 18abda8..bfb28b0 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -137,24 +137,24 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, EXPORT_SYMBOL(blkdev_issue_discard); /** - * blkdev_issue_write_same - queue a write same operation + * __blkdev_issue_write_same - generate number of bios with same page * @bdev: target blockdev * @sector: start sector * @nr_sects: number of sectors to write * @gfp_mask: memory allocation flags (for bio_alloc) * @page: page containing data to write + * @biop: pointer to anchor bio * * Description: - * Issue a write same request for the sectors in question. + * Generate and issue number of bios(REQ_OP_WRITE_SAME) with same page. */ -int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, - sector_t nr_sects, gfp_t gfp_mask, - struct page *page) +static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, struct page *page, + struct bio **biop) { struct request_queue *q = bdev_get_queue(bdev); unsigned int max_write_same_sectors; - struct bio *bio = NULL; - int ret = 0; + struct bio *bio = *biop; sector_t bs_mask; if (!q) @@ -164,6 +164,9 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, if ((sector | nr_sects) & bs_mask) return -EINVAL; + if (!bdev_write_same(bdev)) + return -EOPNOTSUPP; + /* Ensure that max_write_same_sectors doesn't overflow bi_size */ max_write_same_sectors = UINT_MAX >> 9; @@ -185,32 +188,63 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, bio->bi_iter.bi_size = nr_sects << 9; nr_sects = 0; } + cond_resched(); } - if (bio) { + *biop = bio; + return 0; +} + +/** + * blkdev_issue_write_same - queue a write same operation + * @bdev: target blockdev + * @sector: start sector + * @nr_sects: number of sectors to write + * @gfp_mask: memory allocation flags (for bio_alloc) + * @page: page containing data + * + * Description: + * Issue a write same request for the sectors in question. + */ +int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, + struct page *page) +{ + struct bio *bio = NULL; + struct blk_plug plug; + int ret; + + blk_start_plug(&plug); + ret = __blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, page, + &bio); + if (ret == 0 && bio) { ret = submit_bio_wait(bio); bio_put(bio); } + blk_finish_plug(&plug); return ret; } EXPORT_SYMBOL(blkdev_issue_write_same); /** - * blkdev_issue_zeroout - generate number of zero filed write bios + * __blkdev_issue_zeroout - generate number of zero filed write bios * @bdev: blockdev to issue * @sector: start sector * @nr_sects: number of sectors to write * @gfp_mask: memory allocation flags (for bio_alloc) + * @biop: pointer to anchor bio + * @discard: discard flag * * Description: * Generate and issue number of bios with zerofiled pages. */ - -static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, - sector_t nr_sects, gfp_t gfp_mask) +int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, + bool discard) { int ret; - struct bio *bio = NULL; + int bi_size = 0; + struct bio *bio = *biop; unsigned int sz; sector_t bs_mask; @@ -218,6 +252,19 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, if ((sector | nr_sects) & bs_mask) return -EINVAL; + if (discard) { + ret = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, + BLKDEV_DISCARD_ZERO, biop); + if (ret == 0 || (ret && ret != -EOPNOTSUPP)) + goto out; + } + + ret = __blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, + ZERO_PAGE(0), biop); + if (ret == 0 || (ret && ret != -EOPNOTSUPP)) + goto out; + + ret = 0; while (nr_sects != 0) { bio = next_bio(bio, min(nr_sects, (sector_t)BIO_MAX_PAGES), gfp_mask); @@ -227,21 +274,20 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, while (nr_sects != 0) { sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects); - ret = bio_add_page(bio, ZERO_PAGE(0), sz << 9, 0); - nr_sects -= ret >> 9; - sector += ret >> 9; - if (ret < (sz << 9)) + bi_size = bio_add_page(bio, ZERO_PAGE(0), sz << 9, 0); + nr_sects -= bi_size >> 9; + sector += bi_size >> 9; + if (bi_size < (sz << 9)) break; } + cond_resched(); } - if (bio) { - ret = submit_bio_wait(bio); - bio_put(bio); - return ret; - } - return 0; + *biop = bio; +out: + return ret; } +EXPORT_SYMBOL(__blkdev_issue_zeroout); /** * blkdev_issue_zeroout - zero-fill a block range @@ -263,21 +309,22 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, * clearing the block range. Otherwise the zeroing will be performed * using regular WRITE calls. */ - int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, bool discard) { - if (discard) { - if (!blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, - BLKDEV_DISCARD_ZERO)) - return 0; - } + int ret; + struct bio *bio = NULL; + struct blk_plug plug; - if (bdev_write_same(bdev) && - blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, - ZERO_PAGE(0)) == 0) - return 0; + blk_start_plug(&plug); + ret = __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask, + &bio, discard); + if (ret == 0 && bio) { + ret = submit_bio_wait(bio); + bio_put(bio); + } + blk_finish_plug(&plug); - return __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask); + return ret; } EXPORT_SYMBOL(blkdev_issue_zeroout); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 541fdd8..7e9d8a0 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1269,6 +1269,9 @@ extern int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, struct bio **biop); extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct page *page); +extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, + bool discard); extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, bool discard); static inline int sb_issue_discard(struct super_block *sb, sector_t block,