Skip to contentSkip to conversation

f2fs: fix to add missing sb_{start,end}_intwrite() for ckpt thread

PATCH In review Chao Yu 2 participants 6 messages Jun 6, 2024 – Jun 24, 2024 F2FS file system

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH 1/2 f2fs: fix to add missing sb_{start,end}_intwrite() for ckpt thread

After commit 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option"), checkpoint can be triggered in background thread, it missed to cover f2fs inner checkpoint operation w/ sb_{start,end}_intwrite(), fix it.

Fixes 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option")
Cc Daeho Jeong <[email protected]>
---
 fs/f2fs/checkpoint.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +4 -1
index 55d444bec5c0..66eaad591b60 100644
@@ -1828,8 +1828,11 @@ static int issue_checkpoint_thread(void *data)
 	if (kthread_should_stop())
 		return 0;
 
-	if (!llist_empty(&cprc->issue_list))
+	if (!llist_empty(&cprc->issue_list)) {
+		sb_start_intwrite(sbi->sb);
 		__checkpoint_and_complete_reqs(sbi);
+		sb_end_intwrite(sbi->sb);
+	}
 
 	wait_event_interruptible(*q,
 		kthread_should_stop() || !llist_empty(&cprc->issue_list));
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH 2/2 f2fs: fix to use sb_{start,end}_intwrite{_trylock,}() in gc_thread_func()

Since background GC is f2fs inner operation, so, let's use sb_{start,end}_intwrite{_trylock,}() instead of sb_{start,end}_write{_trylock,}() in gc_thread_func().

---
 fs/f2fs/gc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +2 -2
index ef667fec9a12..004587ac5530 100644
@@ -76,7 +76,7 @@ static int gc_thread_func(void *data)
 			f2fs_stop_checkpoint(sbi, false,
 					STOP_CP_REASON_FAULT_INJECT);
 
-		if (!sb_start_write_trylock(sbi->sb)) {
+		if (!sb_start_intwrite_trylock(sbi->sb)) {
 			stat_other_skip_bggc_count(sbi);
 			continue;
 		}
@@ -163,7 +163,7 @@ static int gc_thread_func(void *data)
 			}
 			spin_unlock(&sbi->gc_remaining_trials_lock);
 		}
-		sb_end_write(sbi->sb);
+		sb_end_intwrite(sbi->sb);
 
 	} while (!kthread_should_stop());
 	return 0;
Signature · 1 line
2.40.1
author maintainer
#2 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: fix to use sb_{start, end}_intwrite{_trylock, }() in gc_thread_func()

Quoted 3 lines · Chao Yu

Since background GC is f2fs inner operation, so, let's use sb_{start,end}_intwrite{_trylock,}() instead of sb_{start,end}_write{_trylock,}() in gc_thread_func().

It may cause racing in between gc_thread and freeze_super(), result in writeback of dirty page after ->freeze, so please ignore this patch.

- sb_wait_write(sb, SB_FREEZE_WRITE)
- sync_filesystem(sb)
- sb_start_intwrite_trylock
- f2fs_gc
: dirty pages
- sb_wait_write(sb, SB_FREEZE_FS)

Thanks,

Quoted 28 lines
---
  fs/f2fs/gc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +2 -2
index ef667fec9a12..004587ac5530 100644
@@ -76,7 +76,7 @@ static int gc_thread_func(void *data)
  			f2fs_stop_checkpoint(sbi, false,
  					STOP_CP_REASON_FAULT_INJECT);
 
-		if (!sb_start_write_trylock(sbi->sb)) {
+		if (!sb_start_intwrite_trylock(sbi->sb)) {
  			stat_other_skip_bggc_count(sbi);
  			continue;
  		}
@@ -163,7 +163,7 @@ static int gc_thread_func(void *data)
  			}
  			spin_unlock(&sbi->gc_remaining_trials_lock);
  		}
-		sb_end_write(sbi->sb);
+		sb_end_intwrite(sbi->sb);
 
  	} while (!kthread_should_stop());
  	return 0;
author maintainer
#3 lore raw
In reply to Chao Yu
Quoted 4 lines · Chao Yu

After commit 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option"), checkpoint can be triggered in background thread, it missed to cover f2fs inner checkpoint operation w/ sb_{start,end}_intwrite(), fix it.

It needs to use sb_start_intwrite_trylock(), otherwise, it will cause deadlock as below:

- freeze_super
- sb_wait_write(SB_FREEZE_WRITE)
- sb_wait_write(SB_FREEZE_PAGEFAULT)
- sb_wait_write(SB_FREEZE_FS)
- sync
- iterate_supers
- super_lock_shared
- down_read(&sb->s_umount)
- sync_fs_one_sb
- f2fs_sync_fs
- f2fs_issue_checkpoint
- wait_for_completion
- issue_checkpoint_thread
- sb_start_intwrite(sbi->sb);

- thaw_super
- super_lock_excl
- down_write(&sb->s_umount)

Thanks,

Quoted 25 lines
Fixes 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option")
Cc Daeho Jeong <[email protected]>
---
  fs/f2fs/checkpoint.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +4 -1
index 55d444bec5c0..66eaad591b60 100644
@@ -1828,8 +1828,11 @@ static int issue_checkpoint_thread(void *data)
  	if (kthread_should_stop())
  		return 0;
 
-	if (!llist_empty(&cprc->issue_list))
+	if (!llist_empty(&cprc->issue_list)) {
+		sb_start_intwrite(sbi->sb);
  		__checkpoint_and_complete_reqs(sbi);
+		sb_end_intwrite(sbi->sb);
+	}
 
  	wait_event_interruptible(*q,
  		kthread_should_stop() || !llist_empty(&cprc->issue_list));
Reviewed-by
#4 lore raw

Re: [f2fs-dev] [PATCH 1/2] f2fs: fix to add missing sb_{start, end}_intwrite() for ckpt thread

Quoted 54 lines · Chao Yu
Quoted 4 lines · Chao Yu

After commit 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option"), checkpoint can be triggered in background thread, it missed to cover f2fs inner checkpoint operation w/ sb_{start,end}_intwrite(), fix it.

It needs to use sb_start_intwrite_trylock(), otherwise, it will cause deadlock as below:

- freeze_super
- sb_wait_write(SB_FREEZE_WRITE)
- sb_wait_write(SB_FREEZE_PAGEFAULT)
- sb_wait_write(SB_FREEZE_FS)
- sync
- iterate_supers
- super_lock_shared
- down_read(&sb->s_umount)
- sync_fs_one_sb
- f2fs_sync_fs
- f2fs_issue_checkpoint
- wait_for_completion
- issue_checkpoint_thread
- sb_start_intwrite(sbi->sb);

- thaw_super
- super_lock_excl
- down_write(&sb->s_umount)

Thanks,

Quoted 23 lines
Fixes 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option")
Cc Daeho Jeong <[email protected]>
---
  fs/f2fs/checkpoint.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +4 -1
index 55d444bec5c0..66eaad591b60 100644
@@ -1828,8 +1828,11 @@ static int issue_checkpoint_thread(void *data)
      if (kthread_should_stop())
              return 0;
 
-     if (!llist_empty(&cprc->issue_list))
+     if (!llist_empty(&cprc->issue_list)) {
+             sb_start_intwrite(sbi->sb);
              __checkpoint_and_complete_reqs(sbi);
+             sb_end_intwrite(sbi->sb);
+     }
 
Quoted 4 lines

fs/f2fs/checkpoint.c static int issue_checkpoint_thread(void *data) · line 1838

Quoted 2 lines
fs/f2fs/checkpoint.c +0 -0
      wait_event_interruptible(*q,
              kthread_should_stop() || !llist_empty(&cprc->issue_list));

Thanks.

Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#5 lore raw

Re: [f2fs-dev] [PATCH 1/2] f2fs: fix to add missing sb_{start, end}_intwrite() for ckpt thread

Hi all,

Please ignore this patch, because during freeze_super(), it will call sync_fs() to clear all dirty data, there should be no race case after that.

Thanks,

Quoted 70 lines · Daeho Jeong
Quoted 54 lines · Chao Yu
Quoted 4 lines · Chao Yu

After commit 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option"), checkpoint can be triggered in background thread, it missed to cover f2fs inner checkpoint operation w/ sb_{start,end}_intwrite(), fix it.

It needs to use sb_start_intwrite_trylock(), otherwise, it will cause deadlock as below:

- freeze_super
- sb_wait_write(SB_FREEZE_WRITE)
- sb_wait_write(SB_FREEZE_PAGEFAULT)
- sb_wait_write(SB_FREEZE_FS)
- sync
- iterate_supers
- super_lock_shared
- down_read(&sb->s_umount)
- sync_fs_one_sb
- f2fs_sync_fs
- f2fs_issue_checkpoint
- wait_for_completion
- issue_checkpoint_thread
- sb_start_intwrite(sbi->sb);

- thaw_super
- super_lock_excl
- down_write(&sb->s_umount)

Thanks,

Quoted 23 lines
Fixes 261eeb9c1585 ("f2fs: introduce checkpoint_merge mount option")
Cc Daeho Jeong <[email protected]>
---
   fs/f2fs/checkpoint.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +4 -1
index 55d444bec5c0..66eaad591b60 100644
@@ -1828,8 +1828,11 @@ static int issue_checkpoint_thread(void *data)
       if (kthread_should_stop())
               return 0;
 
-     if (!llist_empty(&cprc->issue_list))
+     if (!llist_empty(&cprc->issue_list)) {
+             sb_start_intwrite(sbi->sb);
               __checkpoint_and_complete_reqs(sbi);
+             sb_end_intwrite(sbi->sb);
+     }
 
Quoted 4 lines

fs/f2fs/checkpoint.c static int issue_checkpoint_thread(void *data) · line 1838

Quoted 2 lines
fs/f2fs/checkpoint.c +0 -0
       wait_event_interruptible(*q,
               kthread_should_stop() || !llist_empty(&cprc->issue_list));

Thanks.

Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel