From patchwork Tue Jul 4 08:27:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9824313 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 8EEEF602F0 for ; Tue, 4 Jul 2017 08:28:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FCDC27FB7 for ; Tue, 4 Jul 2017 08:28:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74AF12811A; Tue, 4 Jul 2017 08:28:30 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 0C04427FB7 for ; Tue, 4 Jul 2017 08:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751986AbdGDI23 (ORCPT ); Tue, 4 Jul 2017 04:28:29 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:27813 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751979AbdGDI23 (ORCPT ); Tue, 4 Jul 2017 04:28:29 -0400 X-IronPort-AV: E=Sophos;i="5.40,307,1496073600"; d="scan'208";a="133271649" Received: from sjappemgw12.hgst.com (HELO sjappemgw11.hgst.com) ([199.255.44.66]) by ob1.hgst.iphmx.com with ESMTP; 04 Jul 2017 16:28:28 +0800 Received: from washi.fujisawa.hgst.com ([10.80.170.19]) by sjappemgw11.hgst.com with ESMTP; 04 Jul 2017 01:27:03 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: Christoph Hellwig Subject: [PATCH v2] block: Fix __blkdev_issue_zeroout loop Date: Tue, 4 Jul 2017 17:27:02 +0900 Message-Id: <20170704082702.15727-1-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.9.4 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 The BIO issuing loop in __blkdev_issue_zeroout() is allocating BIOs with a maximum number of bvec (pages) equal to min(nr_sects, (sector_t)BIO_MAX_PAGES) This works since the BIO will always be limited to the absolute maximum number of pages but this is ineficient as too many bvec entries may be requested since different units (number of sectors vs number of pages) are used in the min() operation. Fix this by correctly using the same unit (number of pages), making sure that this number is at least 1 for cases where the number of sectors is less that the number of sectors in a page. Also remove a trailing space after the bit shift in the internal loop min() call. Signed-off-by: Damien Le Moal --- block/blk-lib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index e8caecd..a19e6cd 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -307,14 +307,15 @@ int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, ret = 0; while (nr_sects != 0) { - bio = next_bio(bio, min(nr_sects, (sector_t)BIO_MAX_PAGES), - gfp_mask); + sz = min((nr_sects << 9) >> PAGE_SHIFT, + (sector_t)BIO_MAX_PAGES); + bio = next_bio(bio, max(1U, sz), gfp_mask); bio->bi_iter.bi_sector = sector; bio->bi_bdev = bdev; bio_set_op_attrs(bio, REQ_OP_WRITE, 0); while (nr_sects != 0) { - sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects); + sz = min((sector_t) PAGE_SIZE >> 9, nr_sects); bi_size = bio_add_page(bio, ZERO_PAGE(0), sz << 9, 0); nr_sects -= bi_size >> 9; sector += bi_size >> 9;