* [PATCH] f2fs: init discard policy after thread wakeup
@ 2022-11-18 3:46 Yangtao Li
2022-11-23 15:36 ` Chao Yu
2022-11-24 14:20 ` Chao Yu
0 siblings, 2 replies; 4+ messages in thread
From: Yangtao Li @ 2022-11-18 3:46 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, 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.
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
fs/f2fs/segment.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 8b0b76550578..609e90aa80c2 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -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);
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] f2fs: init discard policy after thread wakeup
2022-11-18 3:46 [PATCH] f2fs: init discard policy after thread wakeup Yangtao Li
@ 2022-11-23 15:36 ` Chao Yu
2022-11-23 16:06 ` Yangtao Li
2022-11-24 14:20 ` Chao Yu
1 sibling, 1 reply; 4+ messages in thread
From: Chao Yu @ 2022-11-23 15:36 UTC (permalink / raw)
To: Yangtao Li, jaegeuk; +Cc: linux-f2fs-devel, linux-kernel
On 2022/11/18 11:46, Yangtao Li wrote:
> 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.
>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> fs/f2fs/segment.c | 20 +++++++++-----------
> 1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 8b0b76550578..609e90aa80c2 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -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,
> + 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);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] f2fs: init discard policy after thread wakeup
2022-11-23 15:36 ` Chao Yu
@ 2022-11-23 16:06 ` Yangtao Li
0 siblings, 0 replies; 4+ messages in thread
From: Yangtao Li @ 2022-11-23 16:06 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel
HI Chao,
>> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] f2fs: init discard policy after thread wakeup
2022-11-18 3:46 [PATCH] f2fs: init discard policy after thread wakeup Yangtao Li
2022-11-23 15:36 ` Chao Yu
@ 2022-11-24 14:20 ` Chao Yu
1 sibling, 0 replies; 4+ messages in thread
From: Chao Yu @ 2022-11-24 14:20 UTC (permalink / raw)
To: Yangtao Li, jaegeuk; +Cc: linux-f2fs-devel, linux-kernel
On 2022/11/18 11:46, Yangtao Li wrote:
> 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.
>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-24 14:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 3:46 [PATCH] f2fs: init discard policy after thread wakeup Yangtao Li
2022-11-23 15:36 ` Chao Yu
2022-11-23 16:06 ` Yangtao Li
2022-11-24 14:20 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®