Skip to contentSkip to conversation

f2fs: init discard policy after thread wakeup

PATCH In review Yangtao Li 2 participants 4 messages Nov 18, 2022 – Nov 24, 2022 F2FS file system

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 f2fs: init discard policy after thread wakeup

Under the current logic, after the discard thread wakes up, it will not run according to the expected policy, but will use the expected policy before sleep. Move the strategy selection to after the thread wakes up, so that the running state of the thread meets expectations.

---
 fs/f2fs/segment.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
fs/f2fs/segment.c +9 -11
index 8b0b76550578..609e90aa80c2 100644
@@ -1685,6 +1685,11 @@ static int issue_discard_thread(void *data)
 	set_freezable();
 
 	do {
+		wait_event_interruptible_timeout(*q,
+				kthread_should_stop() || freezing(current) ||
+				dcc->discard_wake,
+				msecs_to_jiffies(wait_ms));
+
 		if (sbi->gc_mode == GC_URGENT_HIGH ||
 			!f2fs_available_free_memory(sbi, DISCARD_CACHE))
 			__init_discard_policy(sbi, &dpolicy, DPOLICY_FORCE, 1);
@@ -1692,14 +1697,6 @@ static int issue_discard_thread(void *data)
 			__init_discard_policy(sbi, &dpolicy, DPOLICY_BG,
 						dcc->discard_granularity);
 
-		if (!atomic_read(&dcc->discard_cmd_cnt))
-		       wait_ms = dpolicy.max_interval;
-
-		wait_event_interruptible_timeout(*q,
-				kthread_should_stop() || freezing(current) ||
-				dcc->discard_wake,
-				msecs_to_jiffies(wait_ms));
-
 		if (dcc->discard_wake)
 			dcc->discard_wake = 0;
 
@@ -1713,12 +1710,11 @@ static int issue_discard_thread(void *data)
 			continue;
 		if (kthread_should_stop())
 			return 0;
-		if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) {
+		if (is_sbi_flag_set(sbi, SBI_NEED_FSCK) ||
+			!atomic_read(&dcc->discard_cmd_cnt)) {
 			wait_ms = dpolicy.max_interval;
 			continue;
 		}
-		if (!atomic_read(&dcc->discard_cmd_cnt))
-			continue;
 
 		sb_start_intwrite(sbi->sb);
 
@@ -1733,6 +1729,8 @@ static int issue_discard_thread(void *data)
 		} else {
 			wait_ms = dpolicy.max_interval;
 		}
+		if (!atomic_read(&dcc->discard_cmd_cnt))
+			wait_ms = dpolicy.max_interval;
 
 		sb_end_intwrite(sbi->sb);
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 15 lines · Yangtao Li

Under the current logic, after the discard thread wakes up, it will not run according to the expected policy, but will use the expected policy before sleep. Move the strategy selection to after the thread wakes up, so that the running state of the thread meets expectations.

---
  fs/f2fs/segment.c | 20 +++++++++-----------
  1 file changed, 9 insertions(+), 11 deletions(-)
fs/f2fs/segment.c +0 -0
index 8b0b76550578..609e90aa80c2 100644

fs/f2fs/segment.c static int issue_discard_thread(void *data) · line 1687

Quoted 3 lines
fs/f2fs/segment.c +0 -0
@@ -1685,6 +1685,11 @@ static int issue_discard_thread(void *data)
  	set_freezable();
 
  	do {
		if (!atomic_read(&dcc->discard_cmd_cnt))
		       wait_ms = dpolicy.max_interval;

Thanks,

Quoted 47 lines
fs/f2fs/segment.c +9 -11
+		wait_event_interruptible_timeout(*q,
+				kthread_should_stop() || freezing(current) ||
+				dcc->discard_wake,
+				msecs_to_jiffies(wait_ms));
+
  		if (sbi->gc_mode == GC_URGENT_HIGH ||
  			!f2fs_available_free_memory(sbi, DISCARD_CACHE))
  			__init_discard_policy(sbi, &dpolicy, DPOLICY_FORCE, 1);
@@ -1692,14 +1697,6 @@ static int issue_discard_thread(void *data)
  			__init_discard_policy(sbi, &dpolicy, DPOLICY_BG,
  						dcc->discard_granularity);
 
-		if (!atomic_read(&dcc->discard_cmd_cnt))
-		       wait_ms = dpolicy.max_interval;
-
-		wait_event_interruptible_timeout(*q,
-				kthread_should_stop() || freezing(current) ||
-				dcc->discard_wake,
-				msecs_to_jiffies(wait_ms));
-
  		if (dcc->discard_wake)
  			dcc->discard_wake = 0;
 
@@ -1713,12 +1710,11 @@ static int issue_discard_thread(void *data)
  			continue;
  		if (kthread_should_stop())
  			return 0;
-		if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) {
+		if (is_sbi_flag_set(sbi, SBI_NEED_FSCK) ||
+			!atomic_read(&dcc->discard_cmd_cnt)) {
  			wait_ms = dpolicy.max_interval;
  			continue;
  		}
-		if (!atomic_read(&dcc->discard_cmd_cnt))
-			continue;
 
  		sb_start_intwrite(sbi->sb);
 
@@ -1733,6 +1729,8 @@ static int issue_discard_thread(void *data)
  		} else {
  			wait_ms = dpolicy.max_interval;
  		}
+		if (!atomic_read(&dcc->discard_cmd_cnt))
+			wait_ms = dpolicy.max_interval;
 
  		sb_end_intwrite(sbi->sb);
 
author
#2 lore raw

HI Chao,

Quoted 6 lines
Quoted 3 lines
		set_freezable();
  
		do {
		if (!atomic_read(&dcc->discard_cmd_cnt))
		       wait_ms = dpolicy.max_interval;

dpolicy has not been initialized for the first time, and the value in the stack is unstable.

Thx,
Yangtao

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Yangtao Li
Quoted 6 lines · Yangtao Li

Under the current logic, after the discard thread wakes up, it will not run according to the expected policy, but will use the expected policy before sleep. Move the strategy selection to after the thread wakes up, so that the running state of the thread meets expectations.

Thanks,

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