Skip to contentSkip to conversation

f2fs: fix to cover allocate_segment() with lock

PATCH In review Chao Yu 2 participants 4 messages Apr 14, 2021 – Apr 20, 2021 F2FS file system

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: fix to cover allocate_segment() with lock

As we did for other cases, in fix_curseg_write_pointer(), let's change as below:
- use callback function s_ops->allocate_segment() instead of raw function allocate_segment_by_default();
- cover allocate_segment() with curseg_lock and sentry_lock.

---
 fs/f2fs/segment.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +6 -1
index b2ee6b7791b0..daf9531ec58f 100644
@@ -4848,7 +4848,12 @@ static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type)
 
 	f2fs_notice(sbi, "Assign new section to curseg[%d]: "
 		    "curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
-	allocate_segment_by_default(sbi, type, true);
+
+	down_read(&SM_I(sbi)->curseg_lock);
+	down_write(&SIT_I(sbi)->sentry_lock);
+	SIT_I(sbi)->s_ops->allocate_segment(sbi, type, true);
+	up_write(&SIT_I(sbi)->sentry_lock);
+	up_read(&SM_I(sbi)->curseg_lock);
 
 	/* check consistency of the zone curseg pointed to */
 	if (check_zone_write_pointer(sbi, zbd, &zone))
Signature · 1 line
2.29.2
maintainer
#1 lore raw
Quoted 16 lines · Chao Yu

As we did for other cases, in fix_curseg_write_pointer(), let's change as below:
- use callback function s_ops->allocate_segment() instead of raw function allocate_segment_by_default();
- cover allocate_segment() with curseg_lock and sentry_lock.

---
 fs/f2fs/segment.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +0 -0
index b2ee6b7791b0..daf9531ec58f 100644

fs/f2fs/segment.c static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type) · line 4856

Quoted 10 lines
fs/f2fs/segment.c +6 -1
@@ -4848,7 +4848,12 @@ static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type)
 
 	f2fs_notice(sbi, "Assign new section to curseg[%d]: "
 		    "curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
-	allocate_segment_by_default(sbi, type, true);
+
+	down_read(&SM_I(sbi)->curseg_lock);
+	down_write(&SIT_I(sbi)->sentry_lock);
+	SIT_I(sbi)->s_ops->allocate_segment(sbi, type, true);
+	up_write(&SIT_I(sbi)->sentry_lock);
+	up_read(&SM_I(sbi)->curseg_lock);

Seems f2fs_allocate_new_section()?

Quoted 5 lines
fs/f2fs/segment.c +0 -0
 	/* check consistency of the zone curseg pointed to */
 	if (check_zone_write_pointer(sbi, zbd, &zone))
Signature · 1 line
2.29.2
author
#2 lore raw
Quoted 18 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu

As we did for other cases, in fix_curseg_write_pointer(), let's change as below:
- use callback function s_ops->allocate_segment() instead of raw function allocate_segment_by_default();
- cover allocate_segment() with curseg_lock and sentry_lock.

---
  fs/f2fs/segment.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +0 -0
index b2ee6b7791b0..daf9531ec58f 100644
@@ -4848,7 +4848,12 @@ static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type)
 
Quoted 11 lines

fs/f2fs/segment.c static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type) · line 4856

Quoted 9 lines
fs/f2fs/segment.c +6 -1
  	f2fs_notice(sbi, "Assign new section to curseg[%d]: "
  		    "curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
-	allocate_segment_by_default(sbi, type, true);
+
+	down_read(&SM_I(sbi)->curseg_lock);
+	down_write(&SIT_I(sbi)->sentry_lock);
+	SIT_I(sbi)->s_ops->allocate_segment(sbi, type, true);
+	up_write(&SIT_I(sbi)->sentry_lock);
+	up_read(&SM_I(sbi)->curseg_lock);

Seems f2fs_allocate_new_section()?

f2fs_allocate_new_section() will allocate new section only when current section has been initialized and has valid block/ckpt_block.

It looks fix_curseg_write_pointer() wants to force migrating current segment to new section whenever write pointer and curseg->next_blkoff is inconsistent.

So how about adding a parameter to force f2fs_allocate_new_section() to allocate new section?

Thanks,

Quoted 8 lines
Quoted 6 lines
fs/f2fs/segment.c +0 -0
  	/* check consistency of the zone curseg pointed to */
  	if (check_zone_write_pointer(sbi, zbd, &zone))
Signature · 1 line
2.29.2

.

maintainer
#3 lore raw
Quoted 30 lines · Chao Yu
Quoted 12 lines · Jaegeuk Kim
Quoted 11 lines · Chao Yu

As we did for other cases, in fix_curseg_write_pointer(), let's change as below:
- use callback function s_ops->allocate_segment() instead of raw function allocate_segment_by_default();
- cover allocate_segment() with curseg_lock and sentry_lock.

---
  fs/f2fs/segment.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
fs/f2fs/segment.c +0 -0
index b2ee6b7791b0..daf9531ec58f 100644

fs/f2fs/segment.c static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type) · line 4855

Quoted 9 lines
fs/f2fs/segment.c +6 -1
@@ -4848,7 +4848,12 @@ static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type)
  	f2fs_notice(sbi, "Assign new section to curseg[%d]: "
  		    "curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
-	allocate_segment_by_default(sbi, type, true);
+
+	down_read(&SM_I(sbi)->curseg_lock);
+	down_write(&SIT_I(sbi)->sentry_lock);
+	SIT_I(sbi)->s_ops->allocate_segment(sbi, type, true);
+	up_write(&SIT_I(sbi)->sentry_lock);
+	up_read(&SM_I(sbi)->curseg_lock);

Seems f2fs_allocate_new_section()?

Quoted 8 lines

f2fs_allocate_new_section() will allocate new section only when current section has been initialized and has valid block/ckpt_block.

It looks fix_curseg_write_pointer() wants to force migrating current segment to new section whenever write pointer and curseg->next_blkoff is inconsistent.

So how about adding a parameter to force f2fs_allocate_new_section() to allocate new section?

I think that can be doable. Hope to avoid native calls as much as possible.

Quoted 10 lines

Thanks,

Quoted 7 lines
Quoted 5 lines
fs/f2fs/segment.c +0 -0
  	/* check consistency of the zone curseg pointed to */
  	if (check_zone_write_pointer(sbi, zbd, &zone))
Signature · 1 line
2.29.2

.