From patchwork Mon Apr 30 15:32:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10371997 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 645A36038F for ; Mon, 30 Apr 2018 15:33:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5476D2766D for ; Mon, 30 Apr 2018 15:33:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 491B328113; Mon, 30 Apr 2018 15:33:02 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 ADE892766D for ; Mon, 30 Apr 2018 15:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754740AbeD3Pc7 (ORCPT ); Mon, 30 Apr 2018 11:32:59 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:41015 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754695AbeD3Pc5 (ORCPT ); Mon, 30 Apr 2018 11:32:57 -0400 Received: by mail-io0-f196.google.com with SMTP id e12-v6so10610028iob.8 for ; Mon, 30 Apr 2018 08:32:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/oFGsBiWDRG+eNwnBcSm03jWUiC2sSInLAiLSL4VKlQ=; b=0Pkcd0Ztw+mjUpD+CuROMWk56PT74nKrnIWPR309Oz8nmASbBm3KrvB9E3YclAi2ls hcxowGVtNE7dzZbDip5sX0iCF9pZwLeQ3cQsOL87SH3cJ3suKkAXmLOkhtHdsCssm9eD OmxXtAUmMzlKyfD4ZWdKXU7pOkCWWTQ5Qrgxpt9Jf8iBElP4gz9Pn4nf2lgJD4ERgX1Y nMQ7jK5sN2vwRh60x+5VM9etvvrAGephVcDA9S8zwwVYDXWWsSv2HTtuB4G0uT7sAGAN 3cb3tofAWdoGvodDAs8ObP+GxX4fdhuGuIJ0ErbkBq6jk4NAUqhZp0ww/eguAOwWsUyT NMhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/oFGsBiWDRG+eNwnBcSm03jWUiC2sSInLAiLSL4VKlQ=; b=GTJuZbZzoGFlDSugREBxaTGQXyEOAtkZQsDApXJLyKfj6Lp2FOUHpLT8MRVFAfmJhG GB4qeQTuQrmS8XKiExWCAPLbMQG5L311poghkwblWI7gd7AJAovVtIG3pQnCtOVlPUvn GjS5QVQrvqngGUE3HybFvWlDmUYWrakq7BjZOJXXo/tHs3NToUZBdS8Rvw+k938mTA1W uxdE1l0RpulDDpP9dRltKs6mSWELnYBnqC8/XchiOGVnUFIri0XbCmztcxzMieFO8wdI EjIww2Wr9rE92B1yiB0B57RehfWd+22TjpGtuK5SLDCDnAcIW7HsjJ3t3bf8Yq3X2bJT XeEA== X-Gm-Message-State: ALQs6tDCjc2AAFYobOpsnghX1HoawXDu3/tsqPWckMUddbVXc7T8Q2Oc QGn9d/UU6+wI9VZnUrCc19pajxfuE5Q= X-Google-Smtp-Source: AB8JxZqWBkSnkBR51ZGX6+JR2fM8a745667voSOk+LYo6sijE3DGN+2lzN2VvJKaLq6Inj1B5VD38Q== X-Received: by 2002:a6b:9587:: with SMTP id x129-v6mr13304118iod.13.1525102376676; Mon, 30 Apr 2018 08:32:56 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id z88-v6sm3850877ioi.25.2018.04.30.08.32.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Apr 2018 08:32:55 -0700 (PDT) From: Jens Axboe To: linux-xfs@vger.kernel.org, linux-block@vger.kernel.org Cc: hch@lst.de, Jens Axboe Subject: [PATCH 1/2] block: add BLKDEV_DISCARD_SYNC flag Date: Mon, 30 Apr 2018 09:32:51 -0600 Message-Id: <1525102372-8430-2-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525102372-8430-1-git-send-email-axboe@kernel.dk> References: <1525102372-8430-1-git-send-email-axboe@kernel.dk> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By default, blkdev_issue_discard() will build potentially big bio chains, even when the discard size has been limited by the user. Add a BLKDEV_DISCARD_SYNC flag, telling blkdev_issue_discard() to wait for completion of each discard. Signed-off-by: Jens Axboe --- block/blk-lib.c | 33 ++++++++++++++++++++++++--------- include/linux/blkdev.h | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index a676084d4740..1d0263c13c9c 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -11,13 +11,18 @@ #include "blk.h" static struct bio *next_bio(struct bio *bio, unsigned int nr_pages, - gfp_t gfp) + gfp_t gfp, bool do_sync) { struct bio *new = bio_alloc(gfp, nr_pages); if (bio) { - bio_chain(bio, new); - submit_bio(bio); + if (do_sync) { + submit_bio_wait(bio); + bio_put(bio); + } else { + bio_chain(bio, new); + submit_bio(bio); + } } return new; @@ -30,7 +35,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, struct request_queue *q = bdev_get_queue(bdev); struct bio *bio = *biop; unsigned int granularity; - unsigned int op; + unsigned int op, max_sectors; int alignment; sector_t bs_mask; @@ -58,12 +63,17 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, granularity = max(q->limits.discard_granularity >> 9, 1U); alignment = (bdev_discard_alignment(bdev) >> 9) % granularity; + if (flags & BLKDEV_DISCARD_SYNC) + max_sectors = q->limits.max_discard_sectors; + else + max_sectors = UINT_MAX >> 9; + while (nr_sects) { unsigned int req_sects; sector_t end_sect, tmp; /* Make sure bi_size doesn't overflow */ - req_sects = min_t(sector_t, nr_sects, UINT_MAX >> 9); + req_sects = min_t(sector_t, nr_sects, max_sectors); /** * If splitting a request, and the next starting sector would be @@ -79,7 +89,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 = next_bio(bio, 0, gfp_mask, flags & BLKDEV_DISCARD_SYNC); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio_set_op_attrs(bio, op, 0); @@ -97,6 +107,11 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, cond_resched(); } + if (bio && (flags & BLKDEV_DISCARD_SYNC)) { + submit_bio_wait(bio); + bio_put(bio); + bio = NULL; + } *biop = bio; return 0; } @@ -173,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 = next_bio(bio, 1, gfp_mask, false); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio->bi_vcnt = 1; @@ -249,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 = next_bio(bio, 0, gfp_mask, false); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio->bi_opf = REQ_OP_WRITE_ZEROES; @@ -301,7 +316,7 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, while (nr_sects != 0) { bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), - gfp_mask); + gfp_mask, false); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); bio_set_op_attrs(bio, REQ_OP_WRITE, 0); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 5c4eee043191..e90388004029 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1396,6 +1396,7 @@ extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct page *page); #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */ +#define BLKDEV_DISCARD_SYNC (1 << 1) extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);