From patchwork Thu Jan 25 09:52:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 10183807 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 47FBE60233 for ; Thu, 25 Jan 2018 09:52:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3906728A6A for ; Thu, 25 Jan 2018 09:52:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D8DC28A6F; Thu, 25 Jan 2018 09:52: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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 93EA728A6A for ; Thu, 25 Jan 2018 09:52:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751345AbeAYJwV convert rfc822-to-8bit (ORCPT ); Thu, 25 Jan 2018 04:52:21 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:2521 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751191AbeAYJwU (ORCPT ); Thu, 25 Jan 2018 04:52:20 -0500 Received: from dggemi405-hub.china.huawei.com (unknown [172.30.72.53]) by Forcepoint Email with ESMTP id 1FF59D5756F14; Thu, 25 Jan 2018 17:52:16 +0800 (CST) Received: from DGGEMI505-MBS.china.huawei.com ([169.254.2.37]) by dggemi405-hub.china.huawei.com ([10.3.17.143]) with mapi id 14.03.0361.001; Thu, 25 Jan 2018 17:52:09 +0800 From: "Gaoxiang (OS)" To: Jaegeuk Kim , Chao Yu , "Yuchao (T)" CC: "linux-f2fs-devel@lists.sourceforge.net" , "linux-fsdevel@vger.kernel.org" , heyunlei , hutj , "Duwei (Device OS)" Subject: [f2fs-dev] [PATCH v3] f2fs: flush cp pack except cp pack 2 page at first Thread-Topic: [f2fs-dev] [PATCH v3] f2fs: flush cp pack except cp pack 2 page at first Thread-Index: AdOVwbs7EfX+x3SWQiKFmxl4cI7qUw== Date: Thu, 25 Jan 2018 09:52:09 +0000 Message-ID: <9047C53C18267742AB12E43B65C7F9F70BCD2F67@dggemi505-mbs.china.huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-imapappendstamp: dggemi304-cas.china.huawei.com (14.03.0336.000) x-originating-ip: [10.151.23.176] MIME-Version: 1.0 X-CFilter-Loop: Reflected 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 Previously, we attempt to flush the whole cp pack in a single bio, however, when suddenly powering off at this time, we could get into an extreme scenario that cp pack 1 page and cp pack 2 page are updated and latest, but payload or current summaries are still partially outdated. (see reliable write in the UFS specification) This patch submits the whole cp pack except cp pack 2 page at first, and then writes the cp pack 2 page with an extra independent bio with pre-io barrier. Signed-off-by: Gao Xiang Reviewed-by: Chao Yu --- Change log from v2: - Apply the review comments from Chao Change log from v1: - Apply the review comments from Chao - time data from "finish block_ops" to " finish checkpoint" (tested on ARM64 with TOSHIBA 128GB UFS): Before patch: 0.002273 0.001973 0.002789 0.005159 0.002050 After patch: 0.002502 0.001624 0.002487 0.003049 0.002696 fs/f2fs/checkpoint.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 14d2fed..c1f4b10 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -300,6 +300,33 @@ static int f2fs_write_meta_pages(struct address_space *mapping, return 0; } +static void commit_checkpoint(struct f2fs_sb_info *sbi, + void *src, block_t blk_addr) +{ + struct writeback_control wbc = { + .for_reclaim = 0, + }; + struct page *page = grab_meta_page(sbi, blk_addr); + int err; + + memcpy(page_address(page), src, PAGE_SIZE); + set_page_dirty(page); + + f2fs_wait_on_page_writeback(page, META, true); + f2fs_bug_on(sbi, PageWriteback(page)); + if (unlikely(!clear_page_dirty_for_io(page))) + f2fs_bug_on(sbi, 1); + + /* writeout cp pack 2 page */ + err = __f2fs_write_meta_page(page, &wbc, FS_CP_META_IO); + f2fs_bug_on(sbi, err); + + f2fs_put_page(page, 0); + + /* submit checkpoint with barrier */ + f2fs_submit_merged_write(sbi, META_FLUSH); +} + long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, long nr_to_write, enum iostat_type io_type) { @@ -1297,9 +1324,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) start_blk += NR_CURSEG_NODE_TYPE; } - /* writeout checkpoint block */ - update_meta_page(sbi, ckpt, start_blk); - /* wait for previous submitted node/meta pages writeback */ wait_on_all_pages_writeback(sbi); @@ -1313,10 +1337,15 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) sbi->last_valid_block_count = sbi->total_valid_block_count; percpu_counter_set(&sbi->alloc_valid_block_count, 0); - /* Here, we only have one bio having CP pack */ - sync_meta_pages(sbi, META_FLUSH, LONG_MAX, FS_CP_META_IO); + /* Here, we have one bio having CP pack except cp pack 2 page */ + sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); /* wait for previous submitted meta pages writeback */ + if (!test_opt(sbi, NOBARRIER)) + wait_on_all_pages_writeback(sbi); + + /* barrier and flush checkpoint cp pack 2 page */ + commit_checkpoint(sbi, ckpt, start_blk); wait_on_all_pages_writeback(sbi); release_ino_entry(sbi, false);