linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <yuchao0@huawei.com>
To: <jaegeuk@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 03/10] f2fs-tools: allocate memory in batch in build_sit_info()
Date: Fri, 9 Aug 2019 18:52:55 +0800	[thread overview]
Message-ID: <20190809105302.79876-3-yuchao0@huawei.com> (raw)
In-Reply-To: <20190809105302.79876-1-yuchao0@huawei.com>

Like we did in kernel, allocating memory in batch will be more
efficient.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/f2fs.h  |  1 +
 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 af7149e..bed22d5 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1404,6 +1404,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));
@@ -1420,13 +1421,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;
@@ -1452,10 +1459,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);
 
@@ -2913,9 +2919,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);
-- 
2.18.0.rc1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  parent reply	other threads:[~2019-08-09 10:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 02/10] f2fs-tools: fix to avoid memory leak of sit_i->sentries Chao Yu
2019-08-09 10:52 ` Chao Yu [this message]
2019-08-09 10:52 ` [f2fs-dev] [PATCH 04/10] fsck.f2fs: introduce current_sit_addr() for cleanup Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 05/10] f2fs-tools: introduce f2fs_ra_meta_pages() Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 06/10] dump.f2fs: introduce start_bidx_of_node() for cleanup Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 07/10] fsck.f2fs: fix to set large section type during allocation Chao Yu
2019-08-09 10:53 ` [f2fs-dev] [PATCH 08/10] f2fs-tools: advise to mount unclean image to replay journal Chao Yu
2019-08-09 10:53 ` [f2fs-dev] [PATCH 09/10] fsck.f2fs: fix to propagate error of write_dquots() Chao Yu
2019-08-09 10:53 ` [f2fs-dev] [PATCH 10/10] f2fs-tools: add missing newline symbol in log Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190809105302.79876-3-yuchao0@huawei.com \
    --to=yuchao0@huawei.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).