From patchwork Sat Oct 29 08:08:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9403433 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 A816F60587 for ; Sat, 29 Oct 2016 08:30:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 957192A68A for ; Sat, 29 Oct 2016 08:30:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A4BC2A692; Sat, 29 Oct 2016 08:30:41 +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_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,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 440AB2A68A for ; Sat, 29 Oct 2016 08:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933491AbcJ2IMy (ORCPT ); Sat, 29 Oct 2016 04:12:54 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34274 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933122AbcJ2IMu (ORCPT ); Sat, 29 Oct 2016 04:12:50 -0400 Received: by mail-pf0-f195.google.com with SMTP id u84so3375635pfj.1; Sat, 29 Oct 2016 01:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J2UGk2D3Dcoza3WitvdmgmqIwXvc/Nj3G19PGiKvmPc=; b=csOppMyr1Fui9dgy4mcbvY9Rt+Df+HKt1pQZPUZis/B/XUQ7n1NAY5XRMwasArz5kB YKZzdfc90qcWUt0r2bkbpDWv4lgYntqkFE8ifdNbHewqtAk7/7MIg//3FCvqzljM4L7m 0bqXJ28gW3x1Rx/Kpz8qIXxRbLUI0HJzGaG6LM9lbuDV68tY9BLvciumeqqJJNfkRWBZ w/EjkFatNw3Rono4TdBE4iYGqvUz0ggIk0iUOLZsWyYsi+MSGwUU8RcCtZ6YQjrqkuow iHV+lPlGTAsx2NeFA06AK/tX9lyG24XsYzpu1FAW3+LJGMqNDefY0WhuaeEuPAvp1L/r xW0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J2UGk2D3Dcoza3WitvdmgmqIwXvc/Nj3G19PGiKvmPc=; b=XANfnx7kuYByLhjbFhSBl7E0qjiRUd46PCnD4DG+mgYFxWJ2OdTa3iVmvl0xeZY02F uowUYc3OyrNxpV/cWrXektJXhnpO/EH821esEnaOpTAIbThCcnmJDhHfhJDXKAME6xVc N2I3KowRDsE9WCG4IBnf1jVDTHEm2lwBOqvZ2VdgWRzUMGP4kYb9YI6RG4YUe+VFBO8L LZLGsFVN1PJjl4KxhIGsFV9ktkdKzqA0LUamfwuK6L1HUOyGq5cAcAiART8L1+TUY+01 3vuSZ5gqKSQGjnN2HechNJM2D1ds83v/EqGB6mKL0RCFCBm79PKW+HXqAz1meFnaW30J BWuw== X-Gm-Message-State: ABUngvccxIBhgnqII6+mqI73wQgL41ajuybVKvV2rZlW0VCPuPG5pNHt6EiObCMQcKH1Zw== X-Received: by 10.99.229.17 with SMTP id r17mr25907533pgh.97.1477728769738; Sat, 29 Oct 2016 01:12:49 -0700 (PDT) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id w15sm23543224paj.33.2016.10.29.01.12.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2016 01:12:48 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , "Kirill A . Shutemov" , Ming Lei , Joern Engel , Prasad Joshi , logfs@logfs.org (open list:LogFS) Subject: [PATCH 12/60] fs: logfs: use bio_add_page() in do_erase() Date: Sat, 29 Oct 2016 16:08:11 +0800 Message-Id: <1477728600-12938-13-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477728600-12938-1-git-send-email-tom.leiming@gmail.com> References: <1477728600-12938-1-git-send-email-tom.leiming@gmail.com> 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 Also code gets simplified a bit. Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- fs/logfs/dev_bdev.c | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c index 79be4cb0dfd8..ff5e3e31bca3 100644 --- a/fs/logfs/dev_bdev.c +++ b/fs/logfs/dev_bdev.c @@ -154,49 +154,35 @@ static int do_erase(struct super_block *sb, u64 ofs, pgoff_t index, size_t nr_pages) { struct logfs_super *super = logfs_super(sb); - struct bio *bio; + struct bio *bio = NULL; unsigned int max_pages; - int i; + int i, ret; max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES); - bio = bio_alloc(GFP_NOFS, max_pages); - BUG_ON(!bio); - for (i = 0; i < nr_pages; i++) { - if (i >= max_pages) { - /* Block layer cannot split bios :( */ - bio->bi_vcnt = i; - bio->bi_iter.bi_size = i * PAGE_SIZE; + if (!bio) { + bio = bio_alloc(GFP_NOFS, max_pages); + BUG_ON(!bio); + bio->bi_bdev = super->s_bdev; bio->bi_iter.bi_sector = ofs >> 9; bio->bi_private = sb; bio->bi_end_io = erase_end_io; bio_set_op_attrs(bio, REQ_OP_WRITE, 0); + } + ret = bio_add_page(bio, super->s_erase_page, PAGE_SIZE, 0); + if (!ret) { + /* Block layer cannot split bios :( */ + ofs += bio->bi_iter.bi_size; atomic_inc(&super->s_pending_writes); submit_bio(bio); - - ofs += i * PAGE_SIZE; - index += i; - nr_pages -= i; - i = 0; - - bio = bio_alloc(GFP_NOFS, max_pages); - BUG_ON(!bio); } - bio->bi_io_vec[i].bv_page = super->s_erase_page; - bio->bi_io_vec[i].bv_len = PAGE_SIZE; - bio->bi_io_vec[i].bv_offset = 0; } - bio->bi_vcnt = nr_pages; - bio->bi_iter.bi_size = nr_pages * PAGE_SIZE; - bio->bi_bdev = super->s_bdev; - bio->bi_iter.bi_sector = ofs >> 9; - bio->bi_private = sb; - bio->bi_end_io = erase_end_io; - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); - atomic_inc(&super->s_pending_writes); - submit_bio(bio); + if (bio) { + atomic_inc(&super->s_pending_writes); + submit_bio(bio); + } return 0; }