From: Chao Yu Subject: Re: [PATCH v2] fsck.f2fs: reduce mem alloc during read sit block Date: Mon, 29 Jan 2018 15:56:54 +0800 Message-ID: <981167a2-1aab-ce8e-8a19-93817d8f594f@huawei.com> References: <1517196482-444-1-git-send-email-heyunlei@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from sfi-mx-1.v28.ch3.sourceforge.com ([172.29.28.191] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eg4Jg-0007pR-86 for linux-f2fs-devel@lists.sourceforge.net; Mon, 29 Jan 2018 07:57:24 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190] helo=huawei.com) by sfi-mx-1.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) id 1eg4Je-0003t6-0l for linux-f2fs-devel@lists.sourceforge.net; Mon, 29 Jan 2018 07:57:24 +0000 In-Reply-To: <1517196482-444-1-git-send-email-heyunlei@huawei.com> Content-Language: en-US List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: Yunlei He , jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: ning.jia@huawei.com On 2018/1/29 11:28, Yunlei He wrote: > This patch reduce mem alloc during read sit block > > Signed-off-by: Yunlei He > --- > fsck/fsck.c | 9 ++++++--- > fsck/fsck.h | 4 ++-- > fsck/mount.c | 42 +++++++++++++++++++++++------------------- > 3 files changed, 31 insertions(+), 24 deletions(-) > > diff --git a/fsck/fsck.c b/fsck/fsck.c > index 6c1b9a7..d5c18d3 100644 > --- a/fsck/fsck.c > +++ b/fsck/fsck.c > @@ -1895,25 +1895,28 @@ static void fix_nat_entries(struct f2fs_sb_info *sbi) > static void flush_curseg_sit_entries(struct f2fs_sb_info *sbi) > { > struct sit_info *sit_i = SIT_I(sbi); > + struct f2fs_sit_block *sit_blk; > int i; > > + sit_blk = calloc(BLOCK_SZ, 1); > + ASSERT(sit_blk); Minor thing, one more blank line would be better here to keep good coding style. > /* update curseg sit entries, since we may change > * a segment type in move_curseg_info > */ > for (i = 0; i < NO_CHECK_TYPE; i++) { > struct curseg_info *curseg = CURSEG_I(sbi, i); > - struct f2fs_sit_block *sit_blk; > struct f2fs_sit_entry *sit; > struct seg_entry *se; > > se = get_seg_entry(sbi, curseg->segno); > - sit_blk = get_current_sit_page(sbi, curseg->segno); > + get_current_sit_page(sbi, curseg->segno, sit_blk); > sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, curseg->segno)]; > sit->vblocks = cpu_to_le16((se->type << SIT_VBLOCKS_SHIFT) | > se->valid_blocks); > rewrite_current_sit_page(sbi, curseg->segno, sit_blk); > - free(sit_blk); > } > + > + free(sit_blk); > } > > static void fix_checkpoint(struct f2fs_sb_info *sbi) > diff --git a/fsck/fsck.h b/fsck/fsck.h > index d635c5a..648c2db 100644 > --- a/fsck/fsck.h > +++ b/fsck/fsck.h > @@ -182,8 +182,8 @@ extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t); > extern void print_raw_sb_info(struct f2fs_super_block *); > > extern u32 get_free_segments(struct f2fs_sb_info *); > -extern struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *, > - unsigned int); > +extern void get_current_sit_page(struct f2fs_sb_info *, > + unsigned int, struct f2fs_sit_block *); > extern void rewrite_current_sit_page(struct f2fs_sb_info *, unsigned int, > struct f2fs_sit_block *); > > diff --git a/fsck/mount.c b/fsck/mount.c > index fe0d510..dd62861 100644 > --- a/fsck/mount.c > +++ b/fsck/mount.c > @@ -1324,17 +1324,14 @@ static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) > ASSERT(segno <= end_segno); > } > > -struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi, > - unsigned int segno) > +void get_current_sit_page(struct f2fs_sb_info *sbi, > + unsigned int segno, struct f2fs_sit_block *sit_blk) > { > struct sit_info *sit_i = SIT_I(sbi); > unsigned int offset = SIT_BLOCK_OFFSET(sit_i, segno); > block_t blk_addr = sit_i->sit_base_addr + offset; > - struct f2fs_sit_block *sit_blk; > int ret; > > - sit_blk = calloc(BLOCK_SZ, 1); > - ASSERT(sit_blk); > check_seg_range(sbi, segno); > > /* calculate sit block address */ > @@ -1343,8 +1340,6 @@ struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi, > > ret = dev_read_block(sit_blk, blk_addr); > ASSERT(ret >= 0); > - > - return sit_blk; > } > > void rewrite_current_sit_page(struct f2fs_sb_info *sbi, > @@ -1607,22 +1602,24 @@ 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->sum_blk->journal; > + struct f2fs_sit_block *sit_blk; > struct seg_entry *se; > struct f2fs_sit_entry sit; > unsigned int i, segno; > > + sit_blk = calloc(BLOCK_SZ, 1); > + ASSERT(sit_blk); Ditto, > for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) { > se = &sit_i->sentries[segno]; > - struct f2fs_sit_block *sit_blk; > > - sit_blk = get_current_sit_page(sbi, segno); > + get_current_sit_page(sbi, segno, sit_blk); > sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)]; > - free(sit_blk); > > check_block_count(sbi, segno, &sit); > seg_info_from_raw_sit(se, &sit); > } > > + free(sit_blk); Ditto, > for (i = 0; i < sits_in_cursum(journal); i++) { > segno = le32_to_cpu(segno_in_journal(journal, i)); > se = &sit_i->sentries[segno]; > @@ -1714,24 +1711,26 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi) > struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); > struct sit_info *sit_i = SIT_I(sbi); > + struct f2fs_sit_block *sit_blk; > unsigned int segno = 0; > struct f2fs_summary_block *sum = curseg->sum_blk; > char *ptr = NULL; > > + sit_blk = calloc(BLOCK_SZ, 1); > + ASSERT(sit_blk); Ditto, > /* remove sit journal */ > sum->journal.n_sits = 0; > > ptr = fsck->main_area_bitmap; > > for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) { > - struct f2fs_sit_block *sit_blk; > struct f2fs_sit_entry *sit; > struct seg_entry *se; > u16 valid_blocks = 0; > u16 type; > int i; > > - sit_blk = get_current_sit_page(sbi, segno); > + get_current_sit_page(sbi, segno, sit_blk); > sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)]; > memcpy(sit->valid_map, ptr, SIT_VBLOCK_MAP_SIZE); > > @@ -1751,10 +1750,11 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi) > sit->vblocks = cpu_to_le16((type << SIT_VBLOCKS_SHIFT) | > valid_blocks); > rewrite_current_sit_page(sbi, segno, sit_blk); > - free(sit_blk); > > ptr += SIT_VBLOCK_MAP_SIZE; > } > + > + free(sit_blk); > } > > static int flush_sit_journal_entries(struct f2fs_sb_info *sbi) > @@ -1762,18 +1762,20 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi) > struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); > struct f2fs_journal *journal = &curseg->sum_blk->journal; > struct sit_info *sit_i = SIT_I(sbi); > + struct f2fs_sit_block *sit_blk; > unsigned int segno; > int i; > > + sit_blk = calloc(BLOCK_SZ, 1); > + ASSERT(sit_blk); Ditto, > for (i = 0; i < sits_in_cursum(journal); i++) { > - struct f2fs_sit_block *sit_blk; > struct f2fs_sit_entry *sit; > struct seg_entry *se; > > segno = segno_in_journal(journal, i); > se = get_seg_entry(sbi, segno); > > - sit_blk = get_current_sit_page(sbi, segno); > + get_current_sit_page(sbi, segno, sit_blk); > sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)]; > > memcpy(sit->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE); > @@ -1782,9 +1784,9 @@ static int flush_sit_journal_entries(struct f2fs_sb_info *sbi) > sit->mtime = cpu_to_le64(se->mtime); > > rewrite_current_sit_page(sbi, segno, sit_blk); > - free(sit_blk); > } > > + free(sit_blk); > journal->n_sits = 0; > return i; > } > @@ -1839,12 +1841,14 @@ void flush_sit_entries(struct f2fs_sb_info *sbi) > { > struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); > struct sit_info *sit_i = SIT_I(sbi); > + struct f2fs_sit_block *sit_blk; > unsigned int segno = 0; > u32 free_segs = 0; > > + sit_blk = calloc(BLOCK_SZ, 1); > + ASSERT(sit_blk); Ditto, Otherwise, please add: Reviewed-by: Chao Yu Thanks, > /* update free segments */ > for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) { > - struct f2fs_sit_block *sit_blk; > struct f2fs_sit_entry *sit; > struct seg_entry *se; > > @@ -1853,19 +1857,19 @@ void flush_sit_entries(struct f2fs_sb_info *sbi) > if (!se->dirty) > continue; > > - sit_blk = get_current_sit_page(sbi, segno); > + get_current_sit_page(sbi, segno, sit_blk); > sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)]; > memcpy(sit->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE); > sit->vblocks = cpu_to_le16((se->type << SIT_VBLOCKS_SHIFT) | > se->valid_blocks); > rewrite_current_sit_page(sbi, segno, sit_blk); > - free(sit_blk); > > if (se->valid_blocks == 0x0 && > !IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE)) > free_segs++; > } > > + free(sit_blk); > set_cp(free_segment_count, free_segs); > } > > ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot