From patchwork Thu Dec 17 11:40:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 7872141 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1381CBEEE5 for ; Thu, 17 Dec 2015 11:40:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA0AB203F7 for ; Thu, 17 Dec 2015 11:40:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ABAD02041D for ; Thu, 17 Dec 2015 11:40:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966135AbbLQLk0 (ORCPT ); Thu, 17 Dec 2015 06:40:26 -0500 Received: from mail-bn1bon0081.outbound.protection.outlook.com ([157.56.111.81]:11168 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966134AbbLQLkW (ORCPT ); Thu, 17 Dec 2015 06:40:22 -0500 Received: from BN1PR02CA0043.namprd02.prod.outlook.com (10.141.56.43) by DM2PR0201MB0831.namprd02.prod.outlook.com (10.160.95.152) with Microsoft SMTP Server (TLS) id 15.1.355.16; Thu, 17 Dec 2015 11:40:19 +0000 Received: from BY2FFO11OLC007.protection.gbl (2a01:111:f400:7c0c::113) by BN1PR02CA0043.outlook.office365.com (2a01:111:e400:2a::43) with Microsoft SMTP Server (TLS) id 15.1.355.16 via Frontend Transport; Thu, 17 Dec 2015 11:40:19 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; lst.de; dkim=none (message not signed) header.d=none;lst.de; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.173) by BY2FFO11OLC007.mail.protection.outlook.com (10.1.14.254) with Microsoft SMTP Server id 15.1.355.15 via Frontend Transport; Thu, 17 Dec 2015 11:40:18 +0000 Received: from MILHUBIP04.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id 4C.69.32178.22F92765; Thu, 17 Dec 2015 03:40:18 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.248.2; Thu, 17 Dec 2015 03:40:18 -0800 X-AuditID: ac160a69-f79f76d000007db2-0e-56729f220465 Received: from [10.50.231.72] ( [10.177.8.100]) by milsmgip12.sandisk.com (Symantec Messaging Gateway) with SMTP id 46.E0.17166.02F92765; Thu, 17 Dec 2015 03:40:17 -0800 (PST) Subject: [PATCH 2/6] block: Introduce bio_add_zero_pages() To: Jens Axboe References: <56729ECF.50906@sandisk.com> CC: Jan Kara , Christoph Hellwig , Mike Snitzer , "Martin K. Petersen" , Dmitry Monakhov , "linux-block@vger.kernel.org" , device-mapper development From: Bart Van Assche Message-ID: <56729F1F.1020701@sandisk.com> Date: Thu, 17 Dec 2015 12:40:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <56729ECF.50906@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGIsWRmVeSWpSXmKPExsWyRoxnka7S/KIwgxOz+Cz+7znGZrH33WxW ixMzPS1Wrj7KZDF7ejOTxd5b2hbLj/9jsmjb+JXRgcNjYvM7do/dNxvYPCYd/szk8fHpLRaP 9/uusnmcWXCE3ePzJrk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EZhZQl/gz7xIzhC0vsf3tHOYJjPyzkLTMQlI2C0nZAkbmVYxiuZk5 xbnpmQWGRnrFiXkpmcXZesn5uZsYwUHOGbWD8fpE80OMTBycUg2MxrYSZ2ap//UXcHqvZLvF VcgsoXNVemCA8UI9hoId190+KElNWPmMf92p1TfZymc7WoovN570j9/r+Z7b2UkJX9Z3KzBe jOQ8l630YitP1IYsPuW7WWdUxeutPd5NmSkh+f7n7RyH55rCN3KElR7ut1HYKTIl8dHbmn/s q/yiTx90bQ6vuGOkxFKckWioxVxUnAgAVTOrfSICAAA= X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11OLC007; 1:n/pFRBBF4ESy5duWviPjNKWBaH7i6s1TM6PfQS3CcbSHdmec8HgDPll7cuDOkHPXVnyTfTInTCuwsD/JoeTXTcZQU3Cac3HGKeBEjaozam4LDV7Vz+Q4MWMr4IagOAqnVVK75VbVx7xP3xlmE1gJTM7LQm+M37dnIjWlL6pZbDqNnMRGwIF2pqyD4fL+DpU4qppS4y/ZWKZV39r8Webx3EJQZr1gv7aS05Ra9GWzoEfbYoWSbXvpKotmBxQIRfpHES0BQNPtjzMcG/ZiP3GWxz+CZhzKCJlO+P+48jyIS/JxmtkIywjiPNrnBrxfu9acByvvp9lTj9AM9g1DhS+hpeczfUDdC0um/Q9w5Oxx9i/HwUv2LHzZwXqZErhuvyNx X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(65816999)(1220700001)(87266999)(33656002)(50986999)(99136001)(54356999)(64126003)(230700001)(5008740100001)(76176999)(1096002)(19580395003)(36756003)(86362001)(81156007)(19580405001)(77096005)(189998001)(87936001)(4001350100001)(80316001)(106466001)(69596002)(50466002)(59896002)(586003)(5001960100002)(110136002)(83506001)(11100500001)(97736004)(92566002)(23676002)(65806001)(2950100001)(65956001)(229853001)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0201MB0831; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0201MB0831; 2:3cGmMctxszK0Z7iRwrLAzRNyrpcG9jn/zbTWgsIapLJ0avBmSdVQosyCln1BAoaXTQYlAX6FoDcDt1XTkhBrFZESPUmUfqR6c/CYsCT+S87tTbHLFfj0+QSl6qzpjlzQFOmelg5wzl/UB+Mn5f++oQ==; 3:8F1KJMAzKKYtMNlbmRr8fYapej52BM6YQROzDlsaobHNe6N64WbfDzYzDxH2G0793gv6BtSjWBPgiyu4A3VlnqLZQSeN7ww/2fNGSmfTYYG8Akw36IF04hukSUsvIjrYixDM4yraNCcE+2RbmCxDVyIRI9oWYahpOGJK7d3Los63dMLFJ/kHLED/q+7zeBcmmCHbV6VS2dJU+qWD3/f/HzniAKPLoCLlmJ2w4abM2le/IekH5pS+n+8pADLVpA8WpTz7WdquyuaL1b4M1/Y5iQ==; 25:eBJGFiqVf+/7E5M2HRIeIxLjrxBFP9VzJ1mk3b0G6ol3riZJSwOR6WgN29SE8SEr6gO40zwrMmtCWc8CoAXc8W/QiQ7DlPEX7K2umoAwMc6L8L80IRIN58r0UDBIfADm6643JEIY6MHiP1nV43L/oYnfbLb2jxmY6JxfwwQIvF+lkINMC4dFr25ckOec2U90YJCgDVZTwbaf8twkQaII1vFyY0IKgaqqEalzN5TCX/XIP+5A6dwPyioVCSjta3CFalqinnSxDzmjQHUU65T8Tw== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:DM2PR0201MB0831; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0201MB0831; 20:ggCV1YEE4l4HY9qIo4QcjsaOzsOXfMuEEQ24kQy6s269umsedVGdAg1EwIqonTNj8piG3jR3g4sJq+caot9YWM2NJ/UA1q5Eb/IDVmNNYq8+YYTDKFD4XbyZ5Tv/pSJmnVvH9nTzar2Wyqbnb2qNjEM0VBel3Lqoz1CwZ6ih8zA/AijYXqqZ+g/MoETNsmraZfwt/m20j+57lhokwFjQo+eFOyGJInl10TzZ+uDQDWtI9/vJn/KBo7Sy6cuKGqkJah4cdYkM5wv7DI0zaL0209m1kfYaZFOR4gtkrkh5TN01N6l77GpnO+UuxcVHnSRhJ+yvQcl4murhPfxdzFVKsAQ5C3mPy2J0e/ZWzGbN5OczqLFtcItlfMo1CZsKyHGHy2iE1qwKfKOLZXLaOgUeVzHQUGTAIihF8KX8G1/b+KVV0w+Zlz757z39QgZ2cojjXeHodEZoii/fsmNCssDsCx1pCvVYSDd/U3FhW44qDWKm4lUMl5yNXjZUUjXO1C3V X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(146099531331640)(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001); SRVR:DM2PR0201MB0831; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0201MB0831; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0201MB0831; 4:kcykvk18xifnWCRzDsomvOmuf7vJ9ybt3JKeCewVelqj8nUJOK1sF3FKdxGr4TK8ZF/97N9tDacXGrx5el94FIRIKWlrUmjIDw4+RclMWueey0kcHADqY1K16GEbKjAM1cVKwJi1Cx7vuviLr+r9wChhIoQTqJQEBq76HLRAwX1fVvesgJ1Tmly9VfMY+sECg5ADLWUAnRcHgoHEukWnJli8v+IyJ/vPKA1q+lMj/DZ8q9IwOjr532v6r4J5BoFIfwn/dNL2o2jo2GOUdZRRsp3qqgrJAHBEHfW0LAVSCCtyQAvCR9oZVo/R3P7UXS25HvOU+8EyEcNjKEvo/CY22P4CYVS/iZN+ObTVtX2fYIyUIb/dtUZF0ThhXr5/EKjLH27+EwZVWhdDqkr6otF9RYKOqoQRWBYvup7F5ktAi/CtvXGBNlhVOc+O2f15Peb3L31KcixA66XJy87WOh02RQ==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1BA==; 24:UmcG8tjaAKF4lKOQEjy3uCqxovcUfw4ysojm98QOHYHn9997gza459pWof6lbQgP+3Hdh8HbjhmZWJtSOOmcnKFqiUbBam/5Hqs7rCysBHU=; 20:a9oJWQj7XOSzoNkFYv4LoTM0U4vxDy4h9DtQgjlHrc9mEhvIReFvkt/LJsCBjSn6fIHM6Gn0rgKv8RYY+DXeZo03na0cRl+NnjsENwqtevaT/akBRYyArKbbXIQCd4GZKLab83IvvCibd/P2fcJardOciG0Y4s6Gy583qvYf5qr3HgoES4pZY3JMJYxWSUvkS8Pc/uxG3xptLhlkWZYoreikl++lRdaSDnUPHii/FQZq1S88qsVZhi0+svJ3xNgL SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2015 11:40:18.2798 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.173]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0201MB0831 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the code for adding one or more zero pages into a new function. Signed-off-by: Bart Van Assche Cc: Jan Kara Cc: Christoph Hellwig Cc: Mike Snitzer Cc: Martin K. Petersen Cc: Dmitry Monakhov Reviewed-by: Christoph Hellwig --- block/blk-lib.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 2f4c6b2..f44ec95 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -219,6 +219,22 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, } EXPORT_SYMBOL(blkdev_issue_write_same); +static void bio_add_zero_pages(struct bio *bio, sector_t nr_sects) +{ + unsigned sz; + int ret; + + /* Avoid that bi_size overflows */ + nr_sects = min_t(sector_t, nr_sects, UINT_MAX >> 9); + + for (; nr_sects != 0; nr_sects -= ret >> 9) { + sz = min_t(unsigned, PAGE_SIZE >> 9, nr_sects) << 9; + ret = bio_add_page(bio, ZERO_PAGE(0), sz, 0); + if (ret < sz) + break; + } +} + /** * blkdev_issue_zeroout - generate number of zero filed write bios * @bdev: blockdev to issue @@ -236,7 +252,6 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, int ret; struct bio *bio; struct bio_batch bb; - unsigned int sz; DECLARE_COMPLETION_ONSTACK(wait); atomic_set(&bb.done, 1); @@ -256,16 +271,9 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, bio->bi_bdev = bdev; bio->bi_end_io = bio_batch_end_io; bio->bi_private = &bb; - - 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)) - break; - } - ret = 0; + bio_add_zero_pages(bio, nr_sects); + nr_sects -= bio->bi_iter.bi_size >> 9; + sector += bio->bi_iter.bi_size >> 9; atomic_inc(&bb.done); submit_bio(WRITE, bio); }