All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] resize.f2fs: skip cursegs when finding next free block
@ 2018-06-04  8:14 Sheng Yong
  2018-06-04 10:06 ` Chao Yu
  2018-06-04 20:55 ` Jaegeuk Kim
  0 siblings, 2 replies; 5+ messages in thread
From: Sheng Yong @ 2018-06-04  8:14 UTC (permalink / raw)
  To: jaegeuk, yuchao0; +Cc: linux-f2fs-devel

resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
However, if a curseg is selected, and f2fs_defragment is broken by any
error, curseg->next_blkoff is left not updated.

To avoid this, we skip cursegs when finding next free block.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 fsck/f2fs.h  | 5 +----
 fsck/fsck.c  | 2 +-
 fsck/mount.c | 8 +++-----
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index d0e08aa..d216444 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -380,16 +380,13 @@ static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
 	return 1;
 }
 
-static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno, int type)
+static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno)
 {
 	int i;
 
 	for (i = 0; i < NO_CHECK_TYPE; i++) {
 		struct curseg_info *curseg = CURSEG_I(sbi, i);
 
-		if (type == i)
-			continue;
-
 		if (segno == curseg->segno)
 			return 1;
 	}
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 5b6dbc8..8145199 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1741,7 +1741,7 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
 		se = get_seg_entry(sbi, i);
 		if (se->valid_blocks != 0)
 			sit_valid_segs++;
-		else if (IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE)) {
+		else if (IS_CUR_SEGNO(sbi, i)) {
 			/* curseg has not been written back to device */
 			MSG(1, "\tInfo: curseg %u is counted in valid segs\n", i);
 			sit_valid_segs++;
diff --git a/fsck/mount.c b/fsck/mount.c
index 0a30adb..8d4704e 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -35,8 +35,7 @@ u32 get_free_segments(struct f2fs_sb_info *sbi)
 	for (i = 0; i < TOTAL_SEGS(sbi); i++) {
 		struct seg_entry *se = get_seg_entry(sbi, i);
 
-		if (se->valid_blocks == 0x0 &&
-				!IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE))
+		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, i))
 			free_segs++;
 	}
 	return free_segs;
@@ -1891,8 +1890,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
 							se->valid_blocks);
 		rewrite_current_sit_page(sbi, segno, sit_blk);
 
-		if (se->valid_blocks == 0x0 &&
-				!IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
+		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, segno))
 			free_segs++;
 	}
 
@@ -1922,7 +1920,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 		se = get_seg_entry(sbi, segno);
 
 		if (se->valid_blocks == sbi->blocks_per_seg ||
-				IS_CUR_SEGNO(sbi, segno, type)) {
+				IS_CUR_SEGNO(sbi, segno)) {
 			*to = left ? START_BLOCK(sbi, segno) - 1:
 						START_BLOCK(sbi, segno + 1);
 			continue;
-- 
2.17.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] resize.f2fs: skip cursegs when finding next free block
  2018-06-04  8:14 [PATCH] resize.f2fs: skip cursegs when finding next free block Sheng Yong
@ 2018-06-04 10:06 ` Chao Yu
  2018-06-04 20:55 ` Jaegeuk Kim
  1 sibling, 0 replies; 5+ messages in thread
From: Chao Yu @ 2018-06-04 10:06 UTC (permalink / raw)
  To: Sheng Yong, jaegeuk; +Cc: linux-f2fs-devel

On 2018/6/4 16:14, Sheng Yong wrote:
> resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
> However, if a curseg is selected, and f2fs_defragment is broken by any
> error, curseg->next_blkoff is left not updated.
> 
> To avoid this, we skip cursegs when finding next free block.
> 
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] resize.f2fs: skip cursegs when finding next free block
  2018-06-04  8:14 [PATCH] resize.f2fs: skip cursegs when finding next free block Sheng Yong
  2018-06-04 10:06 ` Chao Yu
@ 2018-06-04 20:55 ` Jaegeuk Kim
  2018-06-05  1:42   ` Sheng Yong
  2018-06-05  2:08   ` Junling Zheng
  1 sibling, 2 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2018-06-04 20:55 UTC (permalink / raw)
  To: Sheng Yong; +Cc: linux-f2fs-devel

On 06/04, Sheng Yong wrote:
> resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
> However, if a curseg is selected, and f2fs_defragment is broken by any
> error, curseg->next_blkoff is left not updated.
> 
> To avoid this, we skip cursegs when finding next free block.

Don't we update the curseg at the end of resize/defrag?

> 
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
> ---
>  fsck/f2fs.h  | 5 +----
>  fsck/fsck.c  | 2 +-
>  fsck/mount.c | 8 +++-----
>  3 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/fsck/f2fs.h b/fsck/f2fs.h
> index d0e08aa..d216444 100644
> --- a/fsck/f2fs.h
> +++ b/fsck/f2fs.h
> @@ -380,16 +380,13 @@ static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
>  	return 1;
>  }
>  
> -static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno, int type)
> +static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno)
>  {
>  	int i;
>  
>  	for (i = 0; i < NO_CHECK_TYPE; i++) {
>  		struct curseg_info *curseg = CURSEG_I(sbi, i);
>  
> -		if (type == i)
> -			continue;
> -
>  		if (segno == curseg->segno)
>  			return 1;
>  	}
> diff --git a/fsck/fsck.c b/fsck/fsck.c
> index 5b6dbc8..8145199 100644
> --- a/fsck/fsck.c
> +++ b/fsck/fsck.c
> @@ -1741,7 +1741,7 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
>  		se = get_seg_entry(sbi, i);
>  		if (se->valid_blocks != 0)
>  			sit_valid_segs++;
> -		else if (IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE)) {
> +		else if (IS_CUR_SEGNO(sbi, i)) {
>  			/* curseg has not been written back to device */
>  			MSG(1, "\tInfo: curseg %u is counted in valid segs\n", i);
>  			sit_valid_segs++;
> diff --git a/fsck/mount.c b/fsck/mount.c
> index 0a30adb..8d4704e 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -35,8 +35,7 @@ u32 get_free_segments(struct f2fs_sb_info *sbi)
>  	for (i = 0; i < TOTAL_SEGS(sbi); i++) {
>  		struct seg_entry *se = get_seg_entry(sbi, i);
>  
> -		if (se->valid_blocks == 0x0 &&
> -				!IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE))
> +		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, i))
>  			free_segs++;
>  	}
>  	return free_segs;
> @@ -1891,8 +1890,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
>  							se->valid_blocks);
>  		rewrite_current_sit_page(sbi, segno, sit_blk);
>  
> -		if (se->valid_blocks == 0x0 &&
> -				!IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
> +		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, segno))
>  			free_segs++;
>  	}
>  
> @@ -1922,7 +1920,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
>  		se = get_seg_entry(sbi, segno);
>  
>  		if (se->valid_blocks == sbi->blocks_per_seg ||
> -				IS_CUR_SEGNO(sbi, segno, type)) {
> +				IS_CUR_SEGNO(sbi, segno)) {
>  			*to = left ? START_BLOCK(sbi, segno) - 1:
>  						START_BLOCK(sbi, segno + 1);
>  			continue;
> -- 
> 2.17.0

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] resize.f2fs: skip cursegs when finding next free block
  2018-06-04 20:55 ` Jaegeuk Kim
@ 2018-06-05  1:42   ` Sheng Yong
  2018-06-05  2:08   ` Junling Zheng
  1 sibling, 0 replies; 5+ messages in thread
From: Sheng Yong @ 2018-06-05  1:42 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-f2fs-devel

Hi, Jaegeuk

On 2018/6/5 4:55, Jaegeuk Kim wrote:
> On 06/04, Sheng Yong wrote:
>> resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
>> However, if a curseg is selected, and f2fs_defragment is broken by any
>> error, curseg->next_blkoff is left not updated.
>>
>> To avoid this, we skip cursegs when finding next free block.
> 
> Don't we update the curseg at the end of resize/defrag?

Yes, we will if f2fs_defragment successfully moves all blocks. However,
if find_next_free_block fails because not enough space left (this happens
when sload fills too much data into the image), f2fs_defragment returns
without updating CP or cursegs.

thanks,
Sheng
> 
>>
>> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
>> ---
>>   fsck/f2fs.h  | 5 +----
>>   fsck/fsck.c  | 2 +-
>>   fsck/mount.c | 8 +++-----
>>   3 files changed, 5 insertions(+), 10 deletions(-)
>>
>> diff --git a/fsck/f2fs.h b/fsck/f2fs.h
>> index d0e08aa..d216444 100644
>> --- a/fsck/f2fs.h
>> +++ b/fsck/f2fs.h
>> @@ -380,16 +380,13 @@ static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
>>   	return 1;
>>   }
>>   
>> -static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno, int type)
>> +static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno)
>>   {
>>   	int i;
>>   
>>   	for (i = 0; i < NO_CHECK_TYPE; i++) {
>>   		struct curseg_info *curseg = CURSEG_I(sbi, i);
>>   
>> -		if (type == i)
>> -			continue;
>> -
>>   		if (segno == curseg->segno)
>>   			return 1;
>>   	}
>> diff --git a/fsck/fsck.c b/fsck/fsck.c
>> index 5b6dbc8..8145199 100644
>> --- a/fsck/fsck.c
>> +++ b/fsck/fsck.c
>> @@ -1741,7 +1741,7 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
>>   		se = get_seg_entry(sbi, i);
>>   		if (se->valid_blocks != 0)
>>   			sit_valid_segs++;
>> -		else if (IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE)) {
>> +		else if (IS_CUR_SEGNO(sbi, i)) {
>>   			/* curseg has not been written back to device */
>>   			MSG(1, "\tInfo: curseg %u is counted in valid segs\n", i);
>>   			sit_valid_segs++;
>> diff --git a/fsck/mount.c b/fsck/mount.c
>> index 0a30adb..8d4704e 100644
>> --- a/fsck/mount.c
>> +++ b/fsck/mount.c
>> @@ -35,8 +35,7 @@ u32 get_free_segments(struct f2fs_sb_info *sbi)
>>   	for (i = 0; i < TOTAL_SEGS(sbi); i++) {
>>   		struct seg_entry *se = get_seg_entry(sbi, i);
>>   
>> -		if (se->valid_blocks == 0x0 &&
>> -				!IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE))
>> +		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, i))
>>   			free_segs++;
>>   	}
>>   	return free_segs;
>> @@ -1891,8 +1890,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
>>   							se->valid_blocks);
>>   		rewrite_current_sit_page(sbi, segno, sit_blk);
>>   
>> -		if (se->valid_blocks == 0x0 &&
>> -				!IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
>> +		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, segno))
>>   			free_segs++;
>>   	}
>>   
>> @@ -1922,7 +1920,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
>>   		se = get_seg_entry(sbi, segno);
>>   
>>   		if (se->valid_blocks == sbi->blocks_per_seg ||
>> -				IS_CUR_SEGNO(sbi, segno, type)) {
>> +				IS_CUR_SEGNO(sbi, segno)) {
>>   			*to = left ? START_BLOCK(sbi, segno) - 1:
>>   						START_BLOCK(sbi, segno + 1);
>>   			continue;
>> -- 
>> 2.17.0
> 
> .
> 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] resize.f2fs: skip cursegs when finding next free block
  2018-06-04 20:55 ` Jaegeuk Kim
  2018-06-05  1:42   ` Sheng Yong
@ 2018-06-05  2:08   ` Junling Zheng
  1 sibling, 0 replies; 5+ messages in thread
From: Junling Zheng @ 2018-06-05  2:08 UTC (permalink / raw)
  To: Jaegeuk Kim, Sheng Yong; +Cc: linux-f2fs-devel

On 2018/6/5 4:55, Jaegeuk Kim wrote:
> On 06/04, Sheng Yong wrote:
>> resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
>> However, if a curseg is selected, and f2fs_defragment is broken by any
>> error, curseg->next_blkoff is left not updated.
>>
>> To avoid this, we skip cursegs when finding next free block.
> 
> Don't we update the curseg at the end of resize/defrag?
> 

Yeah, currently, at the beginning of resize, we finds the next free block
from the beginning of main instead of from cursegs. So, we needn't to update
the curseg if we skip cursegs while finding next free block.

Besides, the logic of IS_CUR_SEGNO is puzzling, does it mean to check the
type of curseg? If the type of curseg with specified segno is not that we
need, then returns nonzero?

>>
>> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
>> ---
>>  fsck/f2fs.h  | 5 +----
>>  fsck/fsck.c  | 2 +-
>>  fsck/mount.c | 8 +++-----
>>  3 files changed, 5 insertions(+), 10 deletions(-)
>>
>> diff --git a/fsck/f2fs.h b/fsck/f2fs.h
>> index d0e08aa..d216444 100644
>> --- a/fsck/f2fs.h
>> +++ b/fsck/f2fs.h
>> @@ -380,16 +380,13 @@ static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
>>  	return 1;
>>  }
>>  
>> -static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno, int type)
>> +static inline int IS_CUR_SEGNO(struct f2fs_sb_info *sbi, u32 segno)
>>  {
>>  	int i;
>>  
>>  	for (i = 0; i < NO_CHECK_TYPE; i++) {
>>  		struct curseg_info *curseg = CURSEG_I(sbi, i);
>>  
>> -		if (type == i)
>> -			continue;
>> -
>>  		if (segno == curseg->segno)
>>  			return 1;
>>  	}
>> diff --git a/fsck/fsck.c b/fsck/fsck.c
>> index 5b6dbc8..8145199 100644
>> --- a/fsck/fsck.c
>> +++ b/fsck/fsck.c
>> @@ -1741,7 +1741,7 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi)
>>  		se = get_seg_entry(sbi, i);
>>  		if (se->valid_blocks != 0)
>>  			sit_valid_segs++;
>> -		else if (IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE)) {
>> +		else if (IS_CUR_SEGNO(sbi, i)) {
>>  			/* curseg has not been written back to device */
>>  			MSG(1, "\tInfo: curseg %u is counted in valid segs\n", i);
>>  			sit_valid_segs++;
>> diff --git a/fsck/mount.c b/fsck/mount.c
>> index 0a30adb..8d4704e 100644
>> --- a/fsck/mount.c
>> +++ b/fsck/mount.c
>> @@ -35,8 +35,7 @@ u32 get_free_segments(struct f2fs_sb_info *sbi)
>>  	for (i = 0; i < TOTAL_SEGS(sbi); i++) {
>>  		struct seg_entry *se = get_seg_entry(sbi, i);
>>  
>> -		if (se->valid_blocks == 0x0 &&
>> -				!IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE))
>> +		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, i))
>>  			free_segs++;
>>  	}
>>  	return free_segs;
>> @@ -1891,8 +1890,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi)
>>  							se->valid_blocks);
>>  		rewrite_current_sit_page(sbi, segno, sit_blk);
>>  
>> -		if (se->valid_blocks == 0x0 &&
>> -				!IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
>> +		if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, segno))
>>  			free_segs++;
>>  	}
>>  
>> @@ -1922,7 +1920,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
>>  		se = get_seg_entry(sbi, segno);
>>  
>>  		if (se->valid_blocks == sbi->blocks_per_seg ||
>> -				IS_CUR_SEGNO(sbi, segno, type)) {
>> +				IS_CUR_SEGNO(sbi, segno)) {
>>  			*to = left ? START_BLOCK(sbi, segno) - 1:
>>  						START_BLOCK(sbi, segno + 1);
>>  			continue;
>> -- 
>> 2.17.0
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> 
> 



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

end of thread, other threads:[~2018-06-05  2:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04  8:14 [PATCH] resize.f2fs: skip cursegs when finding next free block Sheng Yong
2018-06-04 10:06 ` Chao Yu
2018-06-04 20:55 ` Jaegeuk Kim
2018-06-05  1:42   ` Sheng Yong
2018-06-05  2:08   ` Junling Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.