diff options
author | Chao Yu <yuchao0@huawei.com> | 2019-08-09 18:52:55 +0800 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-08-27 14:51:05 -0700 |
commit | bf99ab9e273b1f30f44a7dc3a0e079fd20d4d0c0 (patch) | |
tree | 7063f77ba76e24f12519bdafa1f3c6a754e6e866 | |
parent | 2183c65b7687a8de3328beaa9d5eb6dae70994dd (diff) | |
download | f2fs-tools-bf99ab9e273b1f30f44a7dc3a0e079fd20d4d0c0.tar.gz |
f2fs-tools: allocate memory in batch in build_sit_info()
Like we did in kernel, allocating memory in batch will be more
efficient.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | fsck/f2fs.h | 1 | ||||
-rw-r--r-- | fsck/mount.c | 28 |
2 files changed, 17 insertions, 12 deletions
diff --git a/fsck/f2fs.h b/fsck/f2fs.h index a52b5d4..6fc0bf3 100644 --- a/fsck/f2fs.h +++ b/fsck/f2fs.h @@ -82,6 +82,7 @@ struct sit_info { block_t sit_base_addr; /* start block address of SIT area */ block_t sit_blocks; /* # of blocks used by SIT area */ block_t written_valid_blocks; /* # of valid blocks in main area */ + unsigned char *bitmap; /* all bitmaps pointer */ char *sit_bitmap; /* SIT bitmap pointer */ unsigned int bitmap_size; /* SIT bitmap size */ diff --git a/fsck/mount.c b/fsck/mount.c index fe5cdc4..7693699 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -1407,6 +1407,7 @@ int build_sit_info(struct f2fs_sb_info *sbi) unsigned int sit_segs; int start; char *src_bitmap, *dst_bitmap; + unsigned char *bitmap; unsigned int bitmap_size; sit_i = malloc(sizeof(struct sit_info)); @@ -1423,13 +1424,19 @@ int build_sit_info(struct f2fs_sb_info *sbi) goto free_sit_info; } + bitmap_size = TOTAL_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE; + + sit_i->bitmap = calloc(bitmap_size, 1); + if (!sit_i->bitmap) { + MSG(1, "\tError: Calloc failed for build_sit_info!!\n"); + goto free_sentries; + } + + bitmap = sit_i->bitmap; + for (start = 0; start < TOTAL_SEGS(sbi); start++) { - sit_i->sentries[start].cur_valid_map - = calloc(SIT_VBLOCK_MAP_SIZE, 1); - if (!sit_i->sentries[start].cur_valid_map) { - MSG(1, "\tError: Calloc failed for build_sit_info!!\n"); - goto free_validity_maps; - } + sit_i->sentries[start].cur_valid_map = bitmap; + bitmap += SIT_VBLOCK_MAP_SIZE; } sit_segs = get_sb(segment_count_sit) >> 1; @@ -1455,10 +1462,9 @@ int build_sit_info(struct f2fs_sb_info *sbi) return 0; free_validity_maps: - for (--start ; start >= 0; --start) - free(sit_i->sentries[start].cur_valid_map); + free(sit_i->bitmap); +free_sentries: free(sit_i->sentries); - free_sit_info: free(sit_i); @@ -2906,9 +2912,7 @@ void f2fs_do_umount(struct f2fs_sb_info *sbi) free(sbi->nm_info); /* free sit_info */ - for (i = 0; i < TOTAL_SEGS(sbi); i++) - free(sit_i->sentries[i].cur_valid_map); - + free(sit_i->bitmap); free(sit_i->sit_bitmap); free(sit_i->sentries); free(sm_i->sit_info); |