Skip to contentSkip to conversation

f2fs:fix the race condition of resize flag between resizefs

PATCH New Zhang Qilong via Linux-f2fs-devel 1 participant 2 messages Sep 6, 2022 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs:fix the race condition of resize flag between resizefs

Because the set/clear SBI_IS_RESIZEFS flag not between any locks, there is a race:
thread1 thread2
ioctl(resizefs)
set RESIZEFS flag ioctl(resizefs)
... set RESIZEFS flag

                        ...

clear RESIZEFS flag # then no RESIZEFS flag on thread2.

Also before freeze_super, the resizefs not started, we should not set the SBI_IS_RESIZEFS flag.

So move the set/clear SBI_IS_RESIZEFS flag between the cp_mutex and gc_lock.

Fixes b4b10061ef98 ("f2fs: refactor resize_fs to avoid meta updates in progress")
---
 fs/f2fs/gc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/f2fs/gc.c +2 -3
index fd400d148afb..e13aa080ae00 100644
@@ -2121,8 +2121,6 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 	if (err)
 		return err;
 
-	set_sbi_flag(sbi, SBI_IS_RESIZEFS);
-
 	freeze_super(sbi->sb);
 	f2fs_down_write(&sbi->gc_lock);
 	f2fs_down_write(&sbi->cp_global_sem);
@@ -2138,6 +2136,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 	if (err)
 		goto out_err;
 
+	set_sbi_flag(sbi, SBI_IS_RESIZEFS);
 	err = free_segment_range(sbi, secs, false);
 	if (err)
 		goto recover_out;
@@ -2161,6 +2160,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 		f2fs_commit_super(sbi, false);
 	}
 recover_out:
+	clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
 	if (err) {
 		set_sbi_flag(sbi, SBI_NEED_FSCK);
 		f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
@@ -2173,6 +2173,5 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 	f2fs_up_write(&sbi->cp_global_sem);
 	f2fs_up_write(&sbi->gc_lock);
 	thaw_super(sbi->sb);
-	clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
 	return err;
 }
Signature · 8 lines
2.25.1



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

PATCH 1/1 f2fs:start freeing cluster pages from the unused number

We can start freeing cluster page(s) from which compression is not used. It will get better performance.

---
 fs/f2fs/compress.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/f2fs/compress.c +1 -3
index 6baaff4c52ba..a2d02a1848a2 100644
@@ -693,9 +693,7 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
 	vm_unmap_ram(cc->cbuf, cc->nr_cpages);
 	vm_unmap_ram(cc->rbuf, cc->cluster_size);
 
-	for (i = 0; i < cc->nr_cpages; i++) {
-		if (i < new_nr_cpages)
-			continue;
+	for (i = new_nr_cpages; i < cc->nr_cpages; i++) {
 		f2fs_compress_free_page(cc->cpages[i]);
 		cc->cpages[i] = NULL;
 	}
Signature · 8 lines
2.25.1



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