From patchwork Sat Oct 29 08:08:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9403441 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 07E3760587 for ; Sat, 29 Oct 2016 08:31:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E83472A692 for ; Sat, 29 Oct 2016 08:31:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC6A42A698; Sat, 29 Oct 2016 08:31:24 +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 94AE32A692 for ; Sat, 29 Oct 2016 08:31:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S942828AbcJ2Iay (ORCPT ); Sat, 29 Oct 2016 04:30:54 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34255 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933163AbcJ2IMq (ORCPT ); Sat, 29 Oct 2016 04:12:46 -0400 Received: by mail-pf0-f193.google.com with SMTP id u84so3375448pfj.1; Sat, 29 Oct 2016 01:12:45 -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=sSFoiJZjdtWqXakwLiCAMSt4K02QyVXeDKEPeCn57sk=; b=vpsU4KOgZN2NePpRUP53Pu3+OWpWnb3u9NhtekiX5k6vVa/8VGqT97sAE7BxAyqoEs xvtMR5i1FKxIaJBsAs6sQJ6Z0yJkgjwnqHz+t5VkGSdHdMy5kz1elloASWiN+B5nHKGw He67WGwMIB2XQiWigJcgEUoWBNiCmmKhys/lgkIOqhYTGwgJPznVaCJlyDdTVjZqHGP+ TUCy5hcrzsYQrDUcAm5L3GuWmUm7YFPLl1LKBuSPcJgIqsyVxM6OhgT/bEIb5ng3KYnX FcyGcbj2bzltuzXWwi+ZEXsiAPx4mxNr+wlcrSMXgjYD0IwEBo6klzfAlSrsFh02An+7 n4LQ== 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=sSFoiJZjdtWqXakwLiCAMSt4K02QyVXeDKEPeCn57sk=; b=BKYBc6/ZU0QmFT+8d11FoIC5IQ2nzckeiGyvQkFHzTAhqXwHmBN5vo5fFNHjJMtndq S8M07KbQx6s5lDiDu+Cz1tVuSXDkIO/jrPmzT6I+NY3WjiWeZ6xYx3Bjbsn/C68nROL4 pEnu9qpT3meZgKBUMBfOnfm6+ZFwF2yjRIEIT16l9FvJ+2+4ud2KMj+YDmbhZ2nmPxml 7rmZlIlZjBoHEbinP10cQHHk+RvQ4R8YMdCopAdBLQVOPf3YnOi9eQ9kBoD3up1++HlP eUICx1uBJoOU5w1FG1UXJ4bKIjb50LP/nHCe6jeaW1TQ7HY9fiqm/YwoXmoaqnpgZLLc /T+w== X-Gm-Message-State: ABUngvcU32uc2GHBLgylasBdXKNGeG6YGgygfhCTHkNy0M5DvzC6iT4TWzDQPbqXzOiUcg== X-Received: by 10.99.169.25 with SMTP id u25mr25977860pge.6.1477728765269; Sat, 29 Oct 2016 01:12:45 -0700 (PDT) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id f81sm23481038pfd.84.2016.10.29.01.12.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2016 01:12:44 -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 11/60] fs: logfs: use bio_add_page() in __bdev_writeseg() Date: Sat, 29 Oct 2016 16:08:10 +0800 Message-Id: <1477728600-12938-12-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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Also this patch simplify the code a bit. Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- 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 696dcdd65fdd..79be4cb0dfd8 100644 --- a/fs/logfs/dev_bdev.c +++ b/fs/logfs/dev_bdev.c @@ -72,56 +72,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; }