Skip to content

Commit 2fde3dd

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: allocate memory in batch in build_sit_info()
build_sit_info() allocate all bitmaps for each segment one by one, it's quite low efficiency, this pach changes to allocate large continuous memory at a time, and divide it and assign for each bitmaps of segment. For large size image, it can expect improving its mount speed. Signed-off-by: Chen Gong <gongchen4@huawei.com> Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 4507847 commit 2fde3dd

2 files changed

Lines changed: 24 additions & 28 deletions

File tree

‎fs/f2fs/segment.c‎

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,7 +3945,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
39453945
struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
39463946
struct sit_info *sit_i;
39473947
unsigned int sit_segs, start;
3948-
char *src_bitmap;
3948+
char *src_bitmap, *bitmap;
39493949
unsigned int bitmap_size;
39503950

39513951
/* allocate memory for SIT information */
@@ -3968,27 +3968,31 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
39683968
if (!sit_i->dirty_sentries_bitmap)
39693969
return -ENOMEM;
39703970

3971+
#ifdef CONFIG_F2FS_CHECK_FS
3972+
bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4;
3973+
#else
3974+
bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3;
3975+
#endif
3976+
sit_i->bitmap = f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL);
3977+
if (!sit_i->bitmap)
3978+
return -ENOMEM;
3979+
3980+
bitmap = sit_i->bitmap;
3981+
39713982
for (start = 0; start < MAIN_SEGS(sbi); start++) {
3972-
sit_i->sentries[start].cur_valid_map
3973-
= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
3974-
sit_i->sentries[start].ckpt_valid_map
3975-
= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
3976-
if (!sit_i->sentries[start].cur_valid_map ||
3977-
!sit_i->sentries[start].ckpt_valid_map)
3978-
return -ENOMEM;
3983+
sit_i->sentries[start].cur_valid_map = bitmap;
3984+
bitmap += SIT_VBLOCK_MAP_SIZE;
3985+
3986+
sit_i->sentries[start].ckpt_valid_map = bitmap;
3987+
bitmap += SIT_VBLOCK_MAP_SIZE;
39793988

39803989
#ifdef CONFIG_F2FS_CHECK_FS
3981-
sit_i->sentries[start].cur_valid_map_mir
3982-
= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
3983-
if (!sit_i->sentries[start].cur_valid_map_mir)
3984-
return -ENOMEM;
3990+
sit_i->sentries[start].cur_valid_map_mir = bitmap;
3991+
bitmap += SIT_VBLOCK_MAP_SIZE;
39853992
#endif
39863993

3987-
sit_i->sentries[start].discard_map
3988-
= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
3989-
GFP_KERNEL);
3990-
if (!sit_i->sentries[start].discard_map)
3991-
return -ENOMEM;
3994+
sit_i->sentries[start].discard_map = bitmap;
3995+
bitmap += SIT_VBLOCK_MAP_SIZE;
39923996
}
39933997

39943998
sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
@@ -4494,21 +4498,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi)
44944498
static void destroy_sit_info(struct f2fs_sb_info *sbi)
44954499
{
44964500
struct sit_info *sit_i = SIT_I(sbi);
4497-
unsigned int start;
44984501

44994502
if (!sit_i)
45004503
return;
45014504

4502-
if (sit_i->sentries) {
4503-
for (start = 0; start < MAIN_SEGS(sbi); start++) {
4504-
kvfree(sit_i->sentries[start].cur_valid_map);
4505-
#ifdef CONFIG_F2FS_CHECK_FS
4506-
kvfree(sit_i->sentries[start].cur_valid_map_mir);
4507-
#endif
4508-
kvfree(sit_i->sentries[start].ckpt_valid_map);
4509-
kvfree(sit_i->sentries[start].discard_map);
4510-
}
4511-
}
4505+
if (sit_i->sentries)
4506+
kvfree(sit_i->bitmap);
45124507
kvfree(sit_i->tmp_map);
45134508

45144509
kvfree(sit_i->sentries);

‎fs/f2fs/segment.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ struct sit_info {
226226
block_t sit_base_addr; /* start block address of SIT area */
227227
block_t sit_blocks; /* # of blocks used by SIT area */
228228
block_t written_valid_blocks; /* # of valid blocks in main area */
229+
char *bitmap; /* all bitmaps pointer */
229230
char *sit_bitmap; /* SIT bitmap pointer */
230231
#ifdef CONFIG_F2FS_CHECK_FS
231232
char *sit_bitmap_mir; /* SIT bitmap mirror */

0 commit comments

Comments
 (0)