From patchwork Fri Nov 11 12:05:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9422881 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 2889160233 for ; Fri, 11 Nov 2016 12:07:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B1B7299EE for ; Fri, 11 Nov 2016 12:07:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10282299F2; Fri, 11 Nov 2016 12:07:57 +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 BA2E529A81 for ; Fri, 11 Nov 2016 12:07:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933664AbcKKMHK (ORCPT ); Fri, 11 Nov 2016 07:07:10 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33345 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933649AbcKKMHI (ORCPT ); Fri, 11 Nov 2016 07:07:08 -0500 Received: by mail-pf0-f195.google.com with SMTP id 144so2419100pfv.0; Fri, 11 Nov 2016 04:07:07 -0800 (PST) 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=WYX+dtqeeRZ9FM3dN8gWwJ13NzE0rerwLMFny7jC1cQ=; b=HZTRkZqR3NgQnXCtXEenpnFCFl5HwZmg+j9g28Is01I7tZ5njyMFnamTOiQFcAfpLQ tFjx7BAmO+aidYm575f5SFVYp1jpxs2FeYugsmR5DjVMx+TxC7d8GGLNH1mQSt4mFg85 99qtPvg32igJfjAQLpVVrMLgr5jTbkOdYHGSr2XpH5ANWgZQRRBD0zKOQVsgjBTy4qUz iEj3I6OgGlISQFe7i2lgyGcIUGkSnBhheAtv3wa/HIva0JMfY6YgpS2jneVJ9/jJfb4Y mlAIWqziKRxxXV7FNiZgqJKyvHfmcwQzL857Gotfmv/0Sx5TcabZKNsp9kR3X+Fw5v3h 5Nqg== 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=WYX+dtqeeRZ9FM3dN8gWwJ13NzE0rerwLMFny7jC1cQ=; b=iP3osIoBvh+rjbjtCDtfNgHHQieEfFuSVBg+8UwMbZbffrI6r0u7N/MkfRiLSSGBs8 k0rMybtfftMAbYyJ+9JR7o743WI0XOzgQu1oU1q1opz/S4ZmXSBzNPrI8sxI+Td8pQwY ArfaUnm1UgVpIQE7XKE4PGe4VectFv+Hi/i2KMT9G9Zkt3JLKgEUeC8+AQ7TZKsbdb4W biPG49zXFnTkgo/sIexV0/iOubf4lEDjKCbX+NNuCtJ4/iDysWOA8JwvCaxV1uEdzsK1 JJJ+G4GVef774JT/0Fubdw8uwIrxrWSdG/Ndcz/l5O4AYLObzS7mI5qhHDe8XaDcdtVS cE4A== X-Gm-Message-State: ABUngvdrOUgUgnbxeisM+7Zm6vqE/7hF7FeeawinjcgPNRRl33tMj5uP2XFSocVwG6KjdQ== X-Received: by 10.99.55.79 with SMTP id g15mr5418626pgn.65.1478866027255; Fri, 11 Nov 2016 04:07:07 -0800 (PST) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id t5sm14723400pfb.58.2016.11.11.04.07.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 04:07:06 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , Ming Lei , Joern Engel , Prasad Joshi , logfs@logfs.org (open list:LogFS) Subject: [PATCH 10/12] fs: logfs: use bio_add_page() in __bdev_writeseg() Date: Fri, 11 Nov 2016 20:05:38 +0800 Message-Id: <1478865957-25252-11-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478865957-25252-1-git-send-email-tom.leiming@gmail.com> References: <1478865957-25252-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 this patch simplify the code a bit. Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lei --- fs/logfs/dev_bdev.c | 51 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c index e01075790600..a2e8511b89d6 100644 --- a/fs/logfs/dev_bdev.c +++ b/fs/logfs/dev_bdev.c @@ -71,56 +71,45 @@ static int __bdev_writeseg(struct super_block *sb, u64 ofs, pgoff_t index, { struct logfs_super *super = logfs_super(sb); struct address_space *mapping = super->s_mapping_inode->i_mapping; - struct bio *bio; + struct bio *bio = NULL; struct page *page; 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 = writeseg_end_io; bio_set_op_attrs(bio, REQ_OP_WRITE, 0); - 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); } page = find_lock_page(mapping, index + i); BUG_ON(!page); - bio->bi_io_vec[i].bv_page = page; - bio->bi_io_vec[i].bv_len = PAGE_SIZE; - bio->bi_io_vec[i].bv_offset = 0; + ret = bio_add_page(bio, page, PAGE_SIZE, 0); BUG_ON(PageWriteback(page)); set_page_writeback(page); unlock_page(page); + + if (!ret) { + /* Block layer cannot split bios :( */ + ofs += bio->bi_iter.bi_size; + atomic_inc(&super->s_pending_writes); + submit_bio(bio); + bio = NULL; + } + } + + if (bio) { + atomic_inc(&super->s_pending_writes); + submit_bio(bio); } - 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 = writeseg_end_io; - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); - atomic_inc(&super->s_pending_writes); - submit_bio(bio); return 0; }