From patchwork Sun Dec 17 12:07:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 10117695 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 809776019C for ; Sun, 17 Dec 2017 12:07:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E5DE28C7E for ; Sun, 17 Dec 2017 12:07:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F96A29379; Sun, 17 Dec 2017 12:07:43 +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 EF84528C7E for ; Sun, 17 Dec 2017 12:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757275AbdLQMHk convert rfc822-to-8bit (ORCPT ); Sun, 17 Dec 2017 07:07:40 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:14246 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757214AbdLQMHh (ORCPT ); Sun, 17 Dec 2017 07:07:37 -0500 Received: from 172.30.72.53 (EHLO dggemi405-hub.china.huawei.com) ([172.30.72.53]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id BBM52954; Sun, 17 Dec 2017 20:07:22 +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; Sun, 17 Dec 2017 20:07:16 +0800 From: "gaoxiang (P)" To: "jaegeuk@kernel.org" , "chao@kernel.org" CC: "linux-f2fs-devel@lists.sourceforge.net" , "linux-fsdevel@vger.kernel.org" , "Duwei (Device OS)" Subject: [f2fs-dev] [PATCH RFC] f2fs: clean up build_sit_entries Thread-Topic: [f2fs-dev] [PATCH RFC] f2fs: clean up build_sit_entries Thread-Index: AdN3L3QaJlAQDNzLRIqkCUeAnGfvfQ== Date: Sun, 17 Dec 2017 12:07:14 +0000 Message-ID: <9047C53C18267742AB12E43B65C7F9F70BCB4020@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: dggemi302-cas.china.huawei.com (14.03.0336.000) x-originating-ip: [10.151.23.176] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.5A365DFA.009F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=169.254.2.37, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: c630833b30219db35c119e1b229adeae 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 clean up some redundant repeat code in build_sit_entries and seperate some logic into new functions: - build_discard_entries - build_sec_entries Note that "if (f2fs_discard_en(sbi))" and "if (sbi->segs_per_sec > 1)" are all taken out of the loops they are unchangable. Signed-off-by: Gao Xiang --- fs/f2fs/segment.c | 80 +++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 40e1d20..bcd8a40 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3476,12 +3476,39 @@ static int build_curseg(struct f2fs_sb_info *sbi) return restore_curseg_summaries(sbi); } +static void build_discard_entries(struct f2fs_sb_info *sbi) +{ + unsigned segno; + + for (segno = 0; segno < MAIN_SEGS(sbi); ++segno) { + struct seg_entry *se = get_seg_entry(sbi, segno); + + if (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) + memset(se->discard_map, 0xff, SIT_VBLOCK_MAP_SIZE); + else { + memcpy(se->discard_map, se->cur_valid_map, + SIT_VBLOCK_MAP_SIZE); + + sbi->discard_blks += sbi->blocks_per_seg - + se->valid_blocks; + } + } +} + +static void build_sec_entries(struct f2fs_sb_info *sbi) +{ + unsigned segno; + + for (segno = 0; segno < MAIN_SEGS(sbi); ++segno) + get_sec_entry(sbi, segno)->valid_blocks += + get_seg_entry(sbi, segno)->valid_blocks; +} + static void build_sit_entries(struct f2fs_sb_info *sbi) { struct sit_info *sit_i = SIT_I(sbi); struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); struct f2fs_journal *journal = curseg->journal; - struct seg_entry *se; struct f2fs_sit_entry sit; int sit_blk_cnt = SIT_BLK_CNT(sbi); unsigned int i, start, end; @@ -3498,67 +3525,34 @@ static void build_sit_entries(struct f2fs_sb_info *sbi) struct f2fs_sit_block *sit_blk; struct page *page; - se = &sit_i->sentries[start]; page = get_current_sit_page(sbi, start); sit_blk = (struct f2fs_sit_block *)page_address(page); sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)]; f2fs_put_page(page, 1); check_block_count(sbi, start, &sit); - seg_info_from_raw_sit(se, &sit); - - /* build discard map only one time */ - if (f2fs_discard_en(sbi)) { - if (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) { - memset(se->discard_map, 0xff, - SIT_VBLOCK_MAP_SIZE); - } else { - memcpy(se->discard_map, - se->cur_valid_map, - SIT_VBLOCK_MAP_SIZE); - sbi->discard_blks += - sbi->blocks_per_seg - - se->valid_blocks; - } - } - if (sbi->segs_per_sec > 1) - get_sec_entry(sbi, start)->valid_blocks += - se->valid_blocks; + seg_info_from_raw_sit(&sit_i->sentries[start], &sit); } start_blk += readed; } while (start_blk < sit_blk_cnt); down_read(&curseg->journal_rwsem); for (i = 0; i < sits_in_cursum(journal); i++) { - unsigned int old_valid_blocks; - start = le32_to_cpu(segno_in_journal(journal, i)); - se = &sit_i->sentries[start]; sit = sit_in_journal(journal, i); - old_valid_blocks = se->valid_blocks; - check_block_count(sbi, start, &sit); - seg_info_from_raw_sit(se, &sit); - - if (f2fs_discard_en(sbi)) { - if (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) { - memset(se->discard_map, 0xff, - SIT_VBLOCK_MAP_SIZE); - } else { - memcpy(se->discard_map, se->cur_valid_map, - SIT_VBLOCK_MAP_SIZE); - sbi->discard_blks += old_valid_blocks - - se->valid_blocks; - } - } - - if (sbi->segs_per_sec > 1) - get_sec_entry(sbi, start)->valid_blocks += - se->valid_blocks - old_valid_blocks; + seg_info_from_raw_sit(&sit_i->sentries[start], &sit); } up_read(&curseg->journal_rwsem); + + /* build discard map only one time */ + if (f2fs_discard_en(sbi)) + build_discard_entries(sbi); + + if (sbi->segs_per_sec > 1) + build_sec_entries(sbi); } static void init_free_segmap(struct f2fs_sb_info *sbi)