From patchwork Tue Apr 5 12:07:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8750911 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8D59C9F36E for ; Tue, 5 Apr 2016 12:11:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C30582012B for ; Tue, 5 Apr 2016 12:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9DDC20117 for ; Tue, 5 Apr 2016 12:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932735AbcDEMKE (ORCPT ); Tue, 5 Apr 2016 08:10:04 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33929 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932739AbcDEMKA (ORCPT ); Tue, 5 Apr 2016 08:10:00 -0400 Received: by mail-pf0-f194.google.com with SMTP id d184so1193907pfc.1; Tue, 05 Apr 2016 05:10:00 -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=kOjjy9vd15jfflHGoBdVCzZhgWwHLMeNSxMc9leeFaw=; b=MN44AMpKybXmRAqoIg2Nk31Gm/YneXtM9KnXjcPWzdHfT5ZMHoJ8tAveb8PGnx69LC gP4bPkkWFUKyEclVKXB74T3i+ufqh5mUjJ7kAB529DtpcxtQEw6I9J81NhKJA5NxVcwi 3tYXzT8uXaze9FjNYSdH9TLNdQESnWgoa2KGOzhMPi8XDY6Dn6ciMzRYthR64mITTOJ6 WacmcfctJsE6mHDRqx1ZfgwcLxuyYoS8PdK8CUV6MuIwdX6G449BX5HMJtZ8Oh6Qk0hO 481PTOwDYO6XCOm1+J0tUqqzk7EF3+ckpydRYsgBC8YUy8BbLQRRbF29QOCrwBs7fudW jk1w== 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=kOjjy9vd15jfflHGoBdVCzZhgWwHLMeNSxMc9leeFaw=; b=ML3x4oIxrI1aBKkTTb6XIUzoX/yr09sjj3e0tpCAqAeBg6+yIwBcl63BejSmTRkHGK XJmoVq3kZDJt2+8u2nf6MBGIwpooXaqMtOxNhj8CdmsENZeUelOnT5lNt92+izqEHckA dTIkSaIkQpkz0Rj2ba5jW5Oo7tzt70r6pTvGK2rlg7ujzl/lLQjPurKtkeBVnNMj7qPS +ab9VuE9cB88cCmCPIirCb0FwEofjLSbLzCFIzewZ+3KIezHq+ZvgVDhwOsq/EY4s9Qv d0cu4fR4XKOPxqH5ZqUJaFI7DEVmOsXK8XeWlTQSCx06cDSRHqxxZ2gU3Ehtai1QT2g0 dtqg== X-Gm-Message-State: AD7BkJK22xW/VgPszwRc4umLC5RZZc7mOVF845k9uYX27aUZxems5cJidt4jyOkCdW4D2w== X-Received: by 10.98.34.200 with SMTP id p69mr28739499pfj.114.1459858200059; Tue, 05 Apr 2016 05:10:00 -0700 (PDT) Received: from localhost (56.34.213.162.lcy-01.canonistack.canonical.com. [162.213.34.56]) by smtp.gmail.com with ESMTPSA id wh9sm7528291pab.8.2016.04.05.05.09.52 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 05 Apr 2016 05:09:59 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Boaz Harrosh , Ming Lei , Joern Engel , Prasad Joshi , logfs@logfs.org (open list:LogFS) Subject: [PATCH 24/27] fs: logfs: use bio_add_page() in do_erase() Date: Tue, 5 Apr 2016 20:07:39 +0800 Message-Id: <1459858062-21075-10-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459858062-21075-1-git-send-email-tom.leiming@gmail.com> References: <1459858062-21075-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 1df84e0..db04231 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; }