linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: allocate memory in batch in build_sit_info()
@ 2019-07-04  8:17 Chao Yu
  2019-07-08 23:46 ` Jaegeuk Kim
  0 siblings, 1 reply; 5+ messages in thread
From: Chao Yu @ 2019-07-04  8:17 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-kernel, linux-f2fs-devel

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>
---
 fs/f2fs/segment.c | 51 +++++++++++++++++++++--------------------------
 fs/f2fs/segment.h |  1 +
 2 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 402fbbbb2d7c..73c803af1f31 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3929,7 +3929,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
 	struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
 	struct sit_info *sit_i;
 	unsigned int sit_segs, start;
-	char *src_bitmap;
+	char *src_bitmap, *bitmap;
 	unsigned int bitmap_size;
 
 	/* allocate memory for SIT information */
@@ -3950,27 +3950,31 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
 	if (!sit_i->dirty_sentries_bitmap)
 		return -ENOMEM;
 
+#ifdef CONFIG_F2FS_CHECK_FS
+	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4;
+#else
+	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3;
+#endif
+	sit_i->bitmap = f2fs_kzalloc(sbi, bitmap_size, GFP_KERNEL);
+	if (!sit_i->bitmap)
+		return -ENOMEM;
+
+	bitmap = sit_i->bitmap;
+
 	for (start = 0; start < MAIN_SEGS(sbi); start++) {
-		sit_i->sentries[start].cur_valid_map
-			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
-		sit_i->sentries[start].ckpt_valid_map
-			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
-		if (!sit_i->sentries[start].cur_valid_map ||
-				!sit_i->sentries[start].ckpt_valid_map)
-			return -ENOMEM;
+		sit_i->sentries[start].cur_valid_map = bitmap;
+		bitmap += SIT_VBLOCK_MAP_SIZE;
+
+		sit_i->sentries[start].ckpt_valid_map = bitmap;
+		bitmap += SIT_VBLOCK_MAP_SIZE;
 
 #ifdef CONFIG_F2FS_CHECK_FS
-		sit_i->sentries[start].cur_valid_map_mir
-			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
-		if (!sit_i->sentries[start].cur_valid_map_mir)
-			return -ENOMEM;
+		sit_i->sentries[start].cur_valid_map_mir = bitmap;
+		bitmap += SIT_VBLOCK_MAP_SIZE;
 #endif
 
-		sit_i->sentries[start].discard_map
-			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
-							GFP_KERNEL);
-		if (!sit_i->sentries[start].discard_map)
-			return -ENOMEM;
+		sit_i->sentries[start].discard_map = bitmap;
+		bitmap += SIT_VBLOCK_MAP_SIZE;
 	}
 
 	sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
@@ -4440,21 +4444,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi)
 static void destroy_sit_info(struct f2fs_sb_info *sbi)
 {
 	struct sit_info *sit_i = SIT_I(sbi);
-	unsigned int start;
 
 	if (!sit_i)
 		return;
 
-	if (sit_i->sentries) {
-		for (start = 0; start < MAIN_SEGS(sbi); start++) {
-			kvfree(sit_i->sentries[start].cur_valid_map);
-#ifdef CONFIG_F2FS_CHECK_FS
-			kvfree(sit_i->sentries[start].cur_valid_map_mir);
-#endif
-			kvfree(sit_i->sentries[start].ckpt_valid_map);
-			kvfree(sit_i->sentries[start].discard_map);
-		}
-	}
+	if (sit_i->sentries)
+		kvfree(sit_i->bitmap);
 	kvfree(sit_i->tmp_map);
 
 	kvfree(sit_i->sentries);
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 2fd53462fa27..4d171b489130 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -226,6 +226,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 */
+	char *bitmap;			/* all bitmaps pointer */
 	char *sit_bitmap;		/* SIT bitmap pointer */
 #ifdef CONFIG_F2FS_CHECK_FS
 	char *sit_bitmap_mir;		/* SIT bitmap mirror */
-- 
2.18.0.rc1



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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: allocate memory in batch in build_sit_info()
  2019-07-04  8:17 [f2fs-dev] [PATCH] f2fs: allocate memory in batch in build_sit_info() Chao Yu
@ 2019-07-08 23:46 ` Jaegeuk Kim
  2019-07-09  5:06   ` Chao Yu
  0 siblings, 1 reply; 5+ messages in thread
From: Jaegeuk Kim @ 2019-07-08 23:46 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

On 07/04, Chao Yu wrote:
> 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

It may give more failure rate?

> 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>
> ---
>  fs/f2fs/segment.c | 51 +++++++++++++++++++++--------------------------
>  fs/f2fs/segment.h |  1 +
>  2 files changed, 24 insertions(+), 28 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 402fbbbb2d7c..73c803af1f31 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -3929,7 +3929,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>  	struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
>  	struct sit_info *sit_i;
>  	unsigned int sit_segs, start;
> -	char *src_bitmap;
> +	char *src_bitmap, *bitmap;
>  	unsigned int bitmap_size;
>  
>  	/* allocate memory for SIT information */
> @@ -3950,27 +3950,31 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>  	if (!sit_i->dirty_sentries_bitmap)
>  		return -ENOMEM;
>  
> +#ifdef CONFIG_F2FS_CHECK_FS
> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4;
> +#else
> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3;
> +#endif
> +	sit_i->bitmap = f2fs_kzalloc(sbi, bitmap_size, GFP_KERNEL);
> +	if (!sit_i->bitmap)
> +		return -ENOMEM;
> +
> +	bitmap = sit_i->bitmap;
> +
>  	for (start = 0; start < MAIN_SEGS(sbi); start++) {
> -		sit_i->sentries[start].cur_valid_map
> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> -		sit_i->sentries[start].ckpt_valid_map
> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> -		if (!sit_i->sentries[start].cur_valid_map ||
> -				!sit_i->sentries[start].ckpt_valid_map)
> -			return -ENOMEM;
> +		sit_i->sentries[start].cur_valid_map = bitmap;
> +		bitmap += SIT_VBLOCK_MAP_SIZE;
> +
> +		sit_i->sentries[start].ckpt_valid_map = bitmap;
> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>  
>  #ifdef CONFIG_F2FS_CHECK_FS
> -		sit_i->sentries[start].cur_valid_map_mir
> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> -		if (!sit_i->sentries[start].cur_valid_map_mir)
> -			return -ENOMEM;
> +		sit_i->sentries[start].cur_valid_map_mir = bitmap;
> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>  #endif
>  
> -		sit_i->sentries[start].discard_map
> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
> -							GFP_KERNEL);
> -		if (!sit_i->sentries[start].discard_map)
> -			return -ENOMEM;
> +		sit_i->sentries[start].discard_map = bitmap;
> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>  	}
>  
>  	sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> @@ -4440,21 +4444,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi)
>  static void destroy_sit_info(struct f2fs_sb_info *sbi)
>  {
>  	struct sit_info *sit_i = SIT_I(sbi);
> -	unsigned int start;
>  
>  	if (!sit_i)
>  		return;
>  
> -	if (sit_i->sentries) {
> -		for (start = 0; start < MAIN_SEGS(sbi); start++) {
> -			kvfree(sit_i->sentries[start].cur_valid_map);
> -#ifdef CONFIG_F2FS_CHECK_FS
> -			kvfree(sit_i->sentries[start].cur_valid_map_mir);
> -#endif
> -			kvfree(sit_i->sentries[start].ckpt_valid_map);
> -			kvfree(sit_i->sentries[start].discard_map);
> -		}
> -	}
> +	if (sit_i->sentries)
> +		kvfree(sit_i->bitmap);
>  	kvfree(sit_i->tmp_map);
>  
>  	kvfree(sit_i->sentries);
> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> index 2fd53462fa27..4d171b489130 100644
> --- a/fs/f2fs/segment.h
> +++ b/fs/f2fs/segment.h
> @@ -226,6 +226,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 */
> +	char *bitmap;			/* all bitmaps pointer */
>  	char *sit_bitmap;		/* SIT bitmap pointer */
>  #ifdef CONFIG_F2FS_CHECK_FS
>  	char *sit_bitmap_mir;		/* SIT bitmap mirror */
> -- 
> 2.18.0.rc1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: allocate memory in batch in build_sit_info()
  2019-07-08 23:46 ` Jaegeuk Kim
@ 2019-07-09  5:06   ` Chao Yu
  2019-07-09 17:23     ` Jaegeuk Kim
  0 siblings, 1 reply; 5+ messages in thread
From: Chao Yu @ 2019-07-09  5:06 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

On 2019-7-9 7:46, Jaegeuk Kim wrote:
> On 07/04, Chao Yu wrote:
>> 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
> 
> It may give more failure rate?

For android, I think there should be no problem, since while startup, memory
should be sufficient for f2fs mount.
For server or desktop, if there is any failure on memory allocation,
f2fs_kzalloc will fallback to vmalloc, so that would not be worse than before,
right?

Or if you worry about this really, could we add a fast path:

build_sit_info()
 - try allocate sit_i->bitmap
  - success: divide memory
 - fail: fallback to old method

Thanks,

> 
>> 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>
>> ---
>>  fs/f2fs/segment.c | 51 +++++++++++++++++++++--------------------------
>>  fs/f2fs/segment.h |  1 +
>>  2 files changed, 24 insertions(+), 28 deletions(-)
>>
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index 402fbbbb2d7c..73c803af1f31 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -3929,7 +3929,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>>  	struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
>>  	struct sit_info *sit_i;
>>  	unsigned int sit_segs, start;
>> -	char *src_bitmap;
>> +	char *src_bitmap, *bitmap;
>>  	unsigned int bitmap_size;
>>  
>>  	/* allocate memory for SIT information */
>> @@ -3950,27 +3950,31 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>>  	if (!sit_i->dirty_sentries_bitmap)
>>  		return -ENOMEM;
>>  
>> +#ifdef CONFIG_F2FS_CHECK_FS
>> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4;
>> +#else
>> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3;
>> +#endif
>> +	sit_i->bitmap = f2fs_kzalloc(sbi, bitmap_size, GFP_KERNEL);
>> +	if (!sit_i->bitmap)
>> +		return -ENOMEM;
>> +
>> +	bitmap = sit_i->bitmap;
>> +
>>  	for (start = 0; start < MAIN_SEGS(sbi); start++) {
>> -		sit_i->sentries[start].cur_valid_map
>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>> -		sit_i->sentries[start].ckpt_valid_map
>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>> -		if (!sit_i->sentries[start].cur_valid_map ||
>> -				!sit_i->sentries[start].ckpt_valid_map)
>> -			return -ENOMEM;
>> +		sit_i->sentries[start].cur_valid_map = bitmap;
>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>> +
>> +		sit_i->sentries[start].ckpt_valid_map = bitmap;
>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>>  
>>  #ifdef CONFIG_F2FS_CHECK_FS
>> -		sit_i->sentries[start].cur_valid_map_mir
>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>> -		if (!sit_i->sentries[start].cur_valid_map_mir)
>> -			return -ENOMEM;
>> +		sit_i->sentries[start].cur_valid_map_mir = bitmap;
>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>>  #endif
>>  
>> -		sit_i->sentries[start].discard_map
>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
>> -							GFP_KERNEL);
>> -		if (!sit_i->sentries[start].discard_map)
>> -			return -ENOMEM;
>> +		sit_i->sentries[start].discard_map = bitmap;
>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>>  	}
>>  
>>  	sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>> @@ -4440,21 +4444,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi)
>>  static void destroy_sit_info(struct f2fs_sb_info *sbi)
>>  {
>>  	struct sit_info *sit_i = SIT_I(sbi);
>> -	unsigned int start;
>>  
>>  	if (!sit_i)
>>  		return;
>>  
>> -	if (sit_i->sentries) {
>> -		for (start = 0; start < MAIN_SEGS(sbi); start++) {
>> -			kvfree(sit_i->sentries[start].cur_valid_map);
>> -#ifdef CONFIG_F2FS_CHECK_FS
>> -			kvfree(sit_i->sentries[start].cur_valid_map_mir);
>> -#endif
>> -			kvfree(sit_i->sentries[start].ckpt_valid_map);
>> -			kvfree(sit_i->sentries[start].discard_map);
>> -		}
>> -	}
>> +	if (sit_i->sentries)
>> +		kvfree(sit_i->bitmap);
>>  	kvfree(sit_i->tmp_map);
>>  
>>  	kvfree(sit_i->sentries);
>> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
>> index 2fd53462fa27..4d171b489130 100644
>> --- a/fs/f2fs/segment.h
>> +++ b/fs/f2fs/segment.h
>> @@ -226,6 +226,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 */
>> +	char *bitmap;			/* all bitmaps pointer */
>>  	char *sit_bitmap;		/* SIT bitmap pointer */
>>  #ifdef CONFIG_F2FS_CHECK_FS
>>  	char *sit_bitmap_mir;		/* SIT bitmap mirror */
>> -- 
>> 2.18.0.rc1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: allocate memory in batch in build_sit_info()
  2019-07-09  5:06   ` Chao Yu
@ 2019-07-09 17:23     ` Jaegeuk Kim
  2019-07-10  1:25       ` Chao Yu
  0 siblings, 1 reply; 5+ messages in thread
From: Jaegeuk Kim @ 2019-07-09 17:23 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

On 07/09, Chao Yu wrote:
> On 2019-7-9 7:46, Jaegeuk Kim wrote:
> > On 07/04, Chao Yu wrote:
> >> 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
> > 
> > It may give more failure rate?
> 
> For android, I think there should be no problem, since while startup, memory
> should be sufficient for f2fs mount.
> For server or desktop, if there is any failure on memory allocation,
> f2fs_kzalloc will fallback to vmalloc, so that would not be worse than before,
> right?
> 
> Or if you worry about this really, could we add a fast path:

How much time can we really get with this big alloc?

> 
> build_sit_info()
>  - try allocate sit_i->bitmap
>   - success: divide memory
>  - fail: fallback to old method
> 
> Thanks,
> 
> > 
> >> 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>
> >> ---
> >>  fs/f2fs/segment.c | 51 +++++++++++++++++++++--------------------------
> >>  fs/f2fs/segment.h |  1 +
> >>  2 files changed, 24 insertions(+), 28 deletions(-)
> >>
> >> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> >> index 402fbbbb2d7c..73c803af1f31 100644
> >> --- a/fs/f2fs/segment.c
> >> +++ b/fs/f2fs/segment.c
> >> @@ -3929,7 +3929,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
> >>  	struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
> >>  	struct sit_info *sit_i;
> >>  	unsigned int sit_segs, start;
> >> -	char *src_bitmap;
> >> +	char *src_bitmap, *bitmap;
> >>  	unsigned int bitmap_size;
> >>  
> >>  	/* allocate memory for SIT information */
> >> @@ -3950,27 +3950,31 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
> >>  	if (!sit_i->dirty_sentries_bitmap)
> >>  		return -ENOMEM;
> >>  
> >> +#ifdef CONFIG_F2FS_CHECK_FS
> >> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4;
> >> +#else
> >> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3;
> >> +#endif
> >> +	sit_i->bitmap = f2fs_kzalloc(sbi, bitmap_size, GFP_KERNEL);
> >> +	if (!sit_i->bitmap)
> >> +		return -ENOMEM;
> >> +
> >> +	bitmap = sit_i->bitmap;
> >> +
> >>  	for (start = 0; start < MAIN_SEGS(sbi); start++) {
> >> -		sit_i->sentries[start].cur_valid_map
> >> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> >> -		sit_i->sentries[start].ckpt_valid_map
> >> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> >> -		if (!sit_i->sentries[start].cur_valid_map ||
> >> -				!sit_i->sentries[start].ckpt_valid_map)
> >> -			return -ENOMEM;
> >> +		sit_i->sentries[start].cur_valid_map = bitmap;
> >> +		bitmap += SIT_VBLOCK_MAP_SIZE;
> >> +
> >> +		sit_i->sentries[start].ckpt_valid_map = bitmap;
> >> +		bitmap += SIT_VBLOCK_MAP_SIZE;
> >>  
> >>  #ifdef CONFIG_F2FS_CHECK_FS
> >> -		sit_i->sentries[start].cur_valid_map_mir
> >> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> >> -		if (!sit_i->sentries[start].cur_valid_map_mir)
> >> -			return -ENOMEM;
> >> +		sit_i->sentries[start].cur_valid_map_mir = bitmap;
> >> +		bitmap += SIT_VBLOCK_MAP_SIZE;
> >>  #endif
> >>  
> >> -		sit_i->sentries[start].discard_map
> >> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
> >> -							GFP_KERNEL);
> >> -		if (!sit_i->sentries[start].discard_map)
> >> -			return -ENOMEM;
> >> +		sit_i->sentries[start].discard_map = bitmap;
> >> +		bitmap += SIT_VBLOCK_MAP_SIZE;
> >>  	}
> >>  
> >>  	sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> >> @@ -4440,21 +4444,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi)
> >>  static void destroy_sit_info(struct f2fs_sb_info *sbi)
> >>  {
> >>  	struct sit_info *sit_i = SIT_I(sbi);
> >> -	unsigned int start;
> >>  
> >>  	if (!sit_i)
> >>  		return;
> >>  
> >> -	if (sit_i->sentries) {
> >> -		for (start = 0; start < MAIN_SEGS(sbi); start++) {
> >> -			kvfree(sit_i->sentries[start].cur_valid_map);
> >> -#ifdef CONFIG_F2FS_CHECK_FS
> >> -			kvfree(sit_i->sentries[start].cur_valid_map_mir);
> >> -#endif
> >> -			kvfree(sit_i->sentries[start].ckpt_valid_map);
> >> -			kvfree(sit_i->sentries[start].discard_map);
> >> -		}
> >> -	}
> >> +	if (sit_i->sentries)
> >> +		kvfree(sit_i->bitmap);
> >>  	kvfree(sit_i->tmp_map);
> >>  
> >>  	kvfree(sit_i->sentries);
> >> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> >> index 2fd53462fa27..4d171b489130 100644
> >> --- a/fs/f2fs/segment.h
> >> +++ b/fs/f2fs/segment.h
> >> @@ -226,6 +226,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 */
> >> +	char *bitmap;			/* all bitmaps pointer */
> >>  	char *sit_bitmap;		/* SIT bitmap pointer */
> >>  #ifdef CONFIG_F2FS_CHECK_FS
> >>  	char *sit_bitmap_mir;		/* SIT bitmap mirror */
> >> -- 
> >> 2.18.0.rc1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: allocate memory in batch in build_sit_info()
  2019-07-09 17:23     ` Jaegeuk Kim
@ 2019-07-10  1:25       ` Chao Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2019-07-10  1:25 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

On 2019/7/10 1:23, Jaegeuk Kim wrote:
> On 07/09, Chao Yu wrote:
>> On 2019-7-9 7:46, Jaegeuk Kim wrote:
>>> On 07/04, Chao Yu wrote:
>>>> 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
>>>
>>> It may give more failure rate?
>>
>> For android, I think there should be no problem, since while startup, memory
>> should be sufficient for f2fs mount.
>> For server or desktop, if there is any failure on memory allocation,
>> f2fs_kzalloc will fallback to vmalloc, so that would not be worse than before,
>> right?
>>
>> Or if you worry about this really, could we add a fast path:
> 
> How much time can we really get with this big alloc?

Total build_sit_info()'s elapsed time reduces from 20ms to 10ms on 128gb device.

Thanks,

> 
>>
>> build_sit_info()
>>  - try allocate sit_i->bitmap
>>   - success: divide memory
>>  - fail: fallback to old method
>>
>> Thanks,
>>
>>>
>>>> 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>
>>>> ---
>>>>  fs/f2fs/segment.c | 51 +++++++++++++++++++++--------------------------
>>>>  fs/f2fs/segment.h |  1 +
>>>>  2 files changed, 24 insertions(+), 28 deletions(-)
>>>>
>>>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>>>> index 402fbbbb2d7c..73c803af1f31 100644
>>>> --- a/fs/f2fs/segment.c
>>>> +++ b/fs/f2fs/segment.c
>>>> @@ -3929,7 +3929,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>>>>  	struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
>>>>  	struct sit_info *sit_i;
>>>>  	unsigned int sit_segs, start;
>>>> -	char *src_bitmap;
>>>> +	char *src_bitmap, *bitmap;
>>>>  	unsigned int bitmap_size;
>>>>  
>>>>  	/* allocate memory for SIT information */
>>>> @@ -3950,27 +3950,31 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
>>>>  	if (!sit_i->dirty_sentries_bitmap)
>>>>  		return -ENOMEM;
>>>>  
>>>> +#ifdef CONFIG_F2FS_CHECK_FS
>>>> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4;
>>>> +#else
>>>> +	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3;
>>>> +#endif
>>>> +	sit_i->bitmap = f2fs_kzalloc(sbi, bitmap_size, GFP_KERNEL);
>>>> +	if (!sit_i->bitmap)
>>>> +		return -ENOMEM;
>>>> +
>>>> +	bitmap = sit_i->bitmap;
>>>> +
>>>>  	for (start = 0; start < MAIN_SEGS(sbi); start++) {
>>>> -		sit_i->sentries[start].cur_valid_map
>>>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>>>> -		sit_i->sentries[start].ckpt_valid_map
>>>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>>>> -		if (!sit_i->sentries[start].cur_valid_map ||
>>>> -				!sit_i->sentries[start].ckpt_valid_map)
>>>> -			return -ENOMEM;
>>>> +		sit_i->sentries[start].cur_valid_map = bitmap;
>>>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>>>> +
>>>> +		sit_i->sentries[start].ckpt_valid_map = bitmap;
>>>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>>>>  
>>>>  #ifdef CONFIG_F2FS_CHECK_FS
>>>> -		sit_i->sentries[start].cur_valid_map_mir
>>>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>>>> -		if (!sit_i->sentries[start].cur_valid_map_mir)
>>>> -			return -ENOMEM;
>>>> +		sit_i->sentries[start].cur_valid_map_mir = bitmap;
>>>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>>>>  #endif
>>>>  
>>>> -		sit_i->sentries[start].discard_map
>>>> -			= f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
>>>> -							GFP_KERNEL);
>>>> -		if (!sit_i->sentries[start].discard_map)
>>>> -			return -ENOMEM;
>>>> +		sit_i->sentries[start].discard_map = bitmap;
>>>> +		bitmap += SIT_VBLOCK_MAP_SIZE;
>>>>  	}
>>>>  
>>>>  	sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
>>>> @@ -4440,21 +4444,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi)
>>>>  static void destroy_sit_info(struct f2fs_sb_info *sbi)
>>>>  {
>>>>  	struct sit_info *sit_i = SIT_I(sbi);
>>>> -	unsigned int start;
>>>>  
>>>>  	if (!sit_i)
>>>>  		return;
>>>>  
>>>> -	if (sit_i->sentries) {
>>>> -		for (start = 0; start < MAIN_SEGS(sbi); start++) {
>>>> -			kvfree(sit_i->sentries[start].cur_valid_map);
>>>> -#ifdef CONFIG_F2FS_CHECK_FS
>>>> -			kvfree(sit_i->sentries[start].cur_valid_map_mir);
>>>> -#endif
>>>> -			kvfree(sit_i->sentries[start].ckpt_valid_map);
>>>> -			kvfree(sit_i->sentries[start].discard_map);
>>>> -		}
>>>> -	}
>>>> +	if (sit_i->sentries)
>>>> +		kvfree(sit_i->bitmap);
>>>>  	kvfree(sit_i->tmp_map);
>>>>  
>>>>  	kvfree(sit_i->sentries);
>>>> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
>>>> index 2fd53462fa27..4d171b489130 100644
>>>> --- a/fs/f2fs/segment.h
>>>> +++ b/fs/f2fs/segment.h
>>>> @@ -226,6 +226,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 */
>>>> +	char *bitmap;			/* all bitmaps pointer */
>>>>  	char *sit_bitmap;		/* SIT bitmap pointer */
>>>>  #ifdef CONFIG_F2FS_CHECK_FS
>>>>  	char *sit_bitmap_mir;		/* SIT bitmap mirror */
>>>> -- 
>>>> 2.18.0.rc1
> .
> 


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-10  1:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04  8:17 [f2fs-dev] [PATCH] f2fs: allocate memory in batch in build_sit_info() Chao Yu
2019-07-08 23:46 ` Jaegeuk Kim
2019-07-09  5:06   ` Chao Yu
2019-07-09 17:23     ` Jaegeuk Kim
2019-07-10  1:25       ` Chao Yu

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).