Skip to contentSkip to conversation

resize.f2fs: skip cursegs when finding next free block

PATCH In review Sheng Yong 4 participants 5 messages Jun 4, 2018 – Jun 5, 2018

lore
Share & tools
lore

Sheng Yong

author
#0 lore raw

PATCH 1/1 resize.f2fs: skip cursegs when finding next free block

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.

---
 fsck/f2fs.h  | 5 +----
 fsck/fsck.c  | 2 +-
 fsck/mount.c | 8 +++-----
 3 files changed, 5 insertions(+), 10 deletions(-)
fsck/f2fs.h +1 -4
index d0e08aa..d216444 100644
@@ -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;
 	}
fsck/fsck.c +1 -1
index 5b6dbc8..8145199 100644
@@ -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++;
fsck/mount.c +3 -5
index 0a30adb..8d4704e 100644
@@ -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;
Signature · 6 lines
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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Sheng Yong

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.

Thanks,

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

#2 lore raw
In reply to Sheng Yong
Quoted 5 lines · Sheng Yong

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?

Quoted 78 lines
---
 fsck/f2fs.h  | 5 +----
 fsck/fsck.c  | 2 +-
 fsck/mount.c | 8 +++-----
 3 files changed, 5 insertions(+), 10 deletions(-)
fsck/f2fs.h +1 -4
index d0e08aa..d216444 100644
@@ -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;
 	}
fsck/fsck.c +1 -1
index 5b6dbc8..8145199 100644
@@ -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++;
fsck/mount.c +3 -5
index 0a30adb..8d4704e 100644
@@ -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;
Signature · 1 line
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

author
#3 lore raw

Hi, Jaegeuk

Quoted 8 lines · Jaegeuk Kim
Quoted 5 lines · Sheng Yong

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

Quoted 71 lines
Quoted 71 lines
---
  fsck/f2fs.h  | 5 +----
  fsck/fsck.c  | 2 +-
  fsck/mount.c | 8 +++-----
  3 files changed, 5 insertions(+), 10 deletions(-)
fsck/f2fs.h +1 -4
index d0e08aa..d216444 100644
@@ -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;
  	}
fsck/fsck.c +1 -1
index 5b6dbc8..8145199 100644
@@ -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++;
fsck/mount.c +2 -4
index 0a30adb..8d4704e 100644
@@ -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);
 
Quoted 11 lines
Quoted 8 lines
fsck/mount.c +1 -1
  		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;
Signature · 1 line
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

#4 lore raw
In reply to Jaegeuk Kim
Quoted 9 lines · Jaegeuk Kim
Quoted 5 lines · Sheng Yong

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?

Quoted 70 lines
Quoted 70 lines
---
 fsck/f2fs.h  | 5 +----
 fsck/fsck.c  | 2 +-
 fsck/mount.c | 8 +++-----
 3 files changed, 5 insertions(+), 10 deletions(-)
fsck/f2fs.h +1 -4
index d0e08aa..d216444 100644
@@ -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;
 	}
fsck/fsck.c +1 -1
index 5b6dbc8..8145199 100644
@@ -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++;
fsck/mount.c +2 -4
index 0a30adb..8d4704e 100644
@@ -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);
 
Quoted 18 lines
Quoted 8 lines
fsck/mount.c +1 -1
 		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;
Signature · 1 line
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 [email protected]
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