From patchwork Thu Apr 14 12:02:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8834961 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 C1938C0554 for ; Thu, 14 Apr 2016 12:04:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEBF42020F for ; Thu, 14 Apr 2016 12:04:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02FC320166 for ; Thu, 14 Apr 2016 12:04:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755122AbcDNMDx (ORCPT ); Thu, 14 Apr 2016 08:03:53 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:35797 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755081AbcDNMDv (ORCPT ); Thu, 14 Apr 2016 08:03:51 -0400 Received: by mail-oi0-f65.google.com with SMTP id w18so9555831oie.2; Thu, 14 Apr 2016 05:03: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=8qnpcb4k9bLPd3V6fseogX5WO0ZP7IPPkv2QSFsVzwo=; b=TgIiDEltne/hpll03gWKktaqjEe4UgJE0RsK/Vj+eJ0+lVAJiPYAr37pm9sv+1lmpl StnmRzUkZlPvK7k1Uq5ece3fAId5CEq1Q5s7kYsqGJMWVvnxUdUS/H6H+hYx1SH+Z32P 8IQ+kphwWsb8wr0TTY6LV8xfRCiHOjxE3b0SPxmB8WWN/e6zbmUwqNEoP2FAujjnBuLS 05w+73GD/fZn9oGVWfP6KSu36k3sYBWQldnoAqoG3v4PFgNmG0sD8VvkN9aA+MKVGyP9 lvVJjZy2QPswBP1p/N2v8u2qOdKXvRvHyl/wDbIBVIM+vCwo9k8HNBTEScZOi0MYW5Vq O/Gw== 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=8qnpcb4k9bLPd3V6fseogX5WO0ZP7IPPkv2QSFsVzwo=; b=GYMeaa+ltvYnl+G06nCzAe40HSlgQlCU5fII86gDEjbUJzbRfAwK3+bpEwlvj8lO0Z rcV0FwnZrkzOS3DhbXfIDbkM6fmHCWBWOV/BGV5gBrGD/iBKeuZT1RqfyYhAl60lC/cQ RRJHTl93E8AKT9NrzJ11bY77kQ7IcvwtAAqWP9k8aCg9zDnJ1KXDSsx7YH3QTDbpp1C4 you07eBJdbdNY4VHbRWmfMghSwgiXLFr+oqZNUBmFvWkTVbOCpAsWmFkqXrRjMIptXA/ hHkUuGa2ILW8mxsucRyc1V73jxFrBm6i++GJ4GadBle6DBISSsnZh/HWi6w0b9EQAdKy rFhA== X-Gm-Message-State: AOPr4FVZ+SygzYr9ptZoTMDSulDIsRKtm/0CWnnrpFC6+ENp6AX8H04lwuzP2UuURdRwwQ== X-Received: by 10.157.50.197 with SMTP id u63mr3091611otb.124.1460635425407; Thu, 14 Apr 2016 05:03:45 -0700 (PDT) Received: from localhost ([12.228.154.70]) by smtp.gmail.com with ESMTPSA id ku6sm13338916obb.25.2016.04.14.05.03.44 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 14 Apr 2016 05:03:44 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Joern Engel , Prasad Joshi , logfs@logfs.org (open list:LogFS) Subject: [PATCH v1 24/27] fs: logfs: use bio_add_page() in do_erase() Date: Thu, 14 Apr 2016 20:02:42 +0800 Message-Id: <1460635375-28282-25-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460635375-28282-1-git-send-email-tom.leiming@gmail.com> References: <1460635375-28282-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-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 Also code gets simplified a bit. Signed-off-by: Ming Lei --- fs/logfs/dev_bdev.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c index e2c38f9..a3a446c 100644 --- a/fs/logfs/dev_bdev.c +++ b/fs/logfs/dev_bdev.c @@ -154,47 +154,38 @@ 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; + } + + 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(WRITE, bio); - ofs += i * PAGE_SIZE; - index += i; - nr_pages -= i; - i = 0; - - bio = bio_alloc(GFP_NOFS, max_pages); - BUG_ON(!bio); + bio = NULL; } - 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; - atomic_inc(&super->s_pending_writes); - submit_bio(WRITE, bio); + + if (bio) { + atomic_inc(&super->s_pending_writes); + submit_bio(WRITE, bio); + } return 0; }