f2fs: fix the discard thread sleep timeout under high utilization
PATCH 1/1 f2fs: fix the discard thread sleep timeout under high utilization
When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued. This results into unnecessary frequent and periodic wake ups of the discard thread. This patch adds check for pending discard commands in addition to heavy utilization condition to prevent those wake ups.
--- fs/f2fs/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +4 -1
@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;
@@ -1129,7 +1131,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->io_aware = true; dpolicy->sync = false; dpolicy->ordered = true; -if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { +if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL && +atomic_read (&dcc->discard_cmd_cnt)) { dpolicy->granularity =1 ; dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; }
Signature · 9 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project. _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Sahitya,
Quoted 7 lines · Sahitya Tummala
When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (
DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued. This results into unnecessary frequent and periodic wake ups of the discard thread. This patch adds check for pending discard commands in addition to heavy utilization condition to prevent those wake ups.
Could this commit fix your issue?
Thanks,
Quoted 21 lines
Signed-off-by Sahitya Tummala <[email protected]>--- fs/f2fs/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/segment.c +2
-0@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;
fs/f2fs/segment.c static void __init_discard_policy(struct f2fs_sb_info *sbi, · line 1138
Quoted 9 lines
fs/f2fs/segment.c +2
-1@@ -1129,7 +1131,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->io_aware = true; dpolicy->sync = false; dpolicy->ordered = true; -if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { +if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL && +atomic_read (&dcc->discard_cmd_cnt)) { dpolicy->granularity =1 ; dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; }
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Chao,
Quoted 11 lines · Chao Yu
Sahitya,
Quoted 7 lines · Sahitya Tummala
When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (
DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued. This results into unnecessary frequent and periodic wake ups of the discard thread. This patch adds check for pending discard commands in addition to heavy utilization condition to prevent those wake ups.
Quoted 4 lines
Could this commit fix your issue?
I don't think it will help because we are changing the max timeout of the dpolicy itself in __init_discard_policy() when util > 80% as below -
dpolicy->max_interval = DEF_MIN_DISCARD_ISSUE_TIME;
And issue_discard_thread() uses this value as wait_ms, when there are no more pending discard commands to be issued. <snip>
} else {
wait_ms = dpolicy.max_interval;
}<snip>
The new patch posted above is not changing anything related to the max_interval. Hence, I think it won't help the uncessary wakeup problem I am trying to solve for this condition - util > 80% and when there are no pending discards.
Please let me know if i am missing something.
Thanks,
Sahitya.
Quoted 32 lines
Thanks,
Quoted 30 lines
Signed-off-by Sahitya Tummala <[email protected]>--- fs/f2fs/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/segment.c +4
-1@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;@@ -1129,7 +1131,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->io_aware = true; dpolicy->sync = false; dpolicy->ordered = true; -if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { +if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL && +atomic_read (&dcc->discard_cmd_cnt)) { dpolicy->granularity =1 ; dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; }
Signature · 9 lines
-- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum. _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Sahitya,
Quoted 29 lines · Sahitya Tummala
Hi Chao,
Quoted 11 lines · Chao Yu
Sahitya,
Quoted 7 lines · Sahitya Tummala
When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (
DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued. This results into unnecessary frequent and periodic wake ups of the discard thread. This patch adds check for pending discard commands in addition to heavy utilization condition to prevent those wake ups.Quoted 4 lines
Could this commit fix your issue?
I don't think it will help because we are changing the max timeout of the dpolicy itself in
__init_discard_policy()when util > 80% as below -
dpolicy->max_interval=DEF_MIN_DISCARD_ISSUE_TIME;And
issue_discard_thread()uses this value aswait_ms, when there are no more pending discard commands to be issued. <snip>} else { wait_ms = dpolicy.max_interval; }
Quoted 7 lines
<snip>
The new patch posted above is not changing anything related to the
max_interval. Hence, I think it won't help the uncessary wakeup problem I am trying to solve for this condition - util > 80% and when there are no pending discards.Please let me know if i am missing something.
Copied, thanks for the explanation.
But there is another case which can cause this issue in the case of disk util < 80%.
wait_ms = DEF_MIN_DISCARD_ISSUE_TIME;
do {
wait_event_interruptible_timeout(, wait_ms);
...
if (!atomic_read(&dcc->discard_cmd_cnt))
[1] new statement
continue;} while();
Then the loop will wakeup whenever 50ms timeout.
So, to avoid this case, shouldn't we reset wait_ms to dpolicy.max_interval at [1]?
Meanwhile, how about relocating discard_cmd_cnt check after __init_discard_policy(DPOLICY_FORCE)? and olny set .max_interval to DEF_MAX_DISCARD_ISSUE_TIME if there is no discard command, and keep .granularity to 1?
Thanks,
Quoted 28 lines
Thanks,
Sahitya.Quoted 24 lines
Thanks,
Quoted 22 lines
Signed-off-by Sahitya Tummala <[email protected]>--- fs/f2fs/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/segment.c +2
-0@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;@@ -1129,7 +1131,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->io_aware = true; dpolicy->sync = false;
Quoted 9 lines
Quoted 8 lines
fs/f2fs/segment.c static void __init_discard_policy(struct f2fs_sb_info *sbi, · line 1138
Quoted 8 lines
fs/f2fs/segment.c +2
-1dpolicy->ordered = true; -if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { +if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL && +atomic_read (&dcc->discard_cmd_cnt)) { dpolicy->granularity =1 ; dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; }
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Chao,
Quoted 56 lines · Chao Yu
Hi Sahitya,
Quoted 29 lines · Sahitya Tummala
Hi Chao,
Quoted 11 lines · Chao Yu
Sahitya,
Quoted 7 lines · Sahitya Tummala
When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (
DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued. This results into unnecessary frequent and periodic wake ups of the discard thread. This patch adds check for pending discard commands in addition to heavy utilization condition to prevent those wake ups.Quoted 4 lines
Could this commit fix your issue?
I don't think it will help because we are changing the max timeout of the dpolicy itself in
__init_discard_policy()when util > 80% as below -
dpolicy->max_interval=DEF_MIN_DISCARD_ISSUE_TIME;And
issue_discard_thread()uses this value aswait_ms, when there are no more pending discard commands to be issued. <snip>} else { wait_ms = dpolicy.max_interval; }Quoted 7 lines
<snip>
The new patch posted above is not changing anything related to the
max_interval. Hence, I think it won't help the uncessary wakeup problem I am trying to solve for this condition - util > 80% and when there are no pending discards.Please let me know if i am missing something.
Copied, thanks for the explanation.
But there is another case which can cause this issue in the case of disk util < 80%.
wait_ms=DEF_MIN_DISCARD_ISSUE_TIME;do { wait_event_interruptible_timeout(, wait_ms); ... if (!atomic_read(&dcc->discard_cmd_cnt)) [1] new statement continue;
Quoted 4 lines
}
while();Then the loop will wakeup whenever 50ms timeout.
Yes, only for a short period of time i.e., until the first discard command is issued. Once a discard is issued, it will usewait_ms = dpolicy.max_interval;
Quoted 3 lines
So, to avoid this case, shouldn't we reset
wait_msto dpolicy.max_interval at [1]?
Yes, we can add that to cover the above case.
Quoted 5 lines
Meanwhile, how about relocating
discard_cmd_cntcheck after__init_discard_policy(DPOLICY_FORCE)? and olny set .max_interval toDEF_MAX_DISCARD_ISSUE_TIMEif there is no discard command, and keep .granularity to 1?
There is not need to change .granularity, right? It will be controlled as per utilization as it is done today. Only max_interval and wait_ms needs to be updated. Does this look good?
fs/f2fs/segment.c +6 -3
@@ -1772,13 +1772,16 @@ static int issue_discard_thread(void *data) wait_ms = dpolicy.max_interval;continue ; } -if (!atomic_read (&dcc->discard_cmd_cnt)) -continue ; -if (sbi->gc_mode ==GC_URGENT_HIGH || !f2fs_available_free_memory (sbi,DISCARD_CACHE ))__init_discard_policy (sbi, &dpolicy,DPOLICY_FORCE ,1 ); +if (!atomic_read (&dcc->discard_cmd_cnt)) { + dpolicy.max_interval =DEF_MAX_DISCARD_ISSUE_TIME ; + wait_ms = dpolicy.max_interval; +continue ; + } +sb_start_intwrite (sbi->sb); issued =__issue_discard_cmd (sbi, &dpolicy);
thanks,
Sahitya.
Quoted 39 lines
Thanks,
Quoted 37 lines
Thanks,
Sahitya.Quoted 32 lines
Thanks,
Quoted 30 lines
Signed-off-by Sahitya Tummala <[email protected]>--- fs/f2fs/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/segment.c +4
-1@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;@@ -1129,7 +1131,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->io_aware = true; dpolicy->sync = false; dpolicy->ordered = true; -if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { +if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL && +atomic_read (&dcc->discard_cmd_cnt)) { dpolicy->granularity =1 ; dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; }
Signature · 9 lines
-- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum. _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Sahitya,
Quoted 72 lines · Sahitya Tummala
Hi Chao,
Quoted 56 lines · Chao Yu
Hi Sahitya,
Quoted 29 lines · Sahitya Tummala
Hi Chao,
Quoted 11 lines · Chao Yu
Sahitya,
Quoted 7 lines · Sahitya Tummala
When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (
DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued. This results into unnecessary frequent and periodic wake ups of the discard thread. This patch adds check for pending discard commands in addition to heavy utilization condition to prevent those wake ups.Quoted 4 lines
Could this commit fix your issue?
I don't think it will help because we are changing the max timeout of the dpolicy itself in
__init_discard_policy()when util > 80% as below -
dpolicy->max_interval=DEF_MIN_DISCARD_ISSUE_TIME;And
issue_discard_thread()uses this value aswait_ms, when there are no more pending discard commands to be issued. <snip>} else { wait_ms = dpolicy.max_interval; }Quoted 7 lines
<snip>
The new patch posted above is not changing anything related to the
max_interval. Hence, I think it won't help the uncessary wakeup problem I am trying to solve for this condition - util > 80% and when there are no pending discards.Please let me know if i am missing something.
Copied, thanks for the explanation.
But there is another case which can cause this issue in the case of disk util < 80%.
wait_ms=DEF_MIN_DISCARD_ISSUE_TIME;do { wait_event_interruptible_timeout(, wait_ms); ... if (!atomic_read(&dcc->discard_cmd_cnt)) [1] new statement continue;Quoted 4 lines
}
while();Then the loop will wakeup whenever 50ms timeout.
Yes, only for a short period of time i.e., until the first discard command is issued. Once a discard is issued, it will use
wait_ms= dpolicy.max_interval;Quoted 3 lines
So, to avoid this case, shouldn't we reset
wait_msto dpolicy.max_interval at [1]?Yes, we can add that to cover the above case.
Quoted 7 lines
Quoted 5 lines
Meanwhile, how about relocating
discard_cmd_cntcheck after__init_discard_policy(DPOLICY_FORCE)? and olny set .max_interval toDEF_MAX_DISCARD_ISSUE_TIMEif there is no discard command, and keep .granularity to 1?There is not need to change .granularity, right? It will be controlled
I think so.
Quoted 13 lines
as per utilization as it is done today. Only
max_intervalandwait_msneeds to be updated. Does this look good?fs/f2fs/segment.c +0
-2@@ -1772,13 +1772,16 @@ static int issue_discard_thread(void *data) wait_ms = dpolicy.max_interval;continue ; } -if (!atomic_read (&dcc->discard_cmd_cnt)) -continue ;
fs/f2fs/segment.c static int issue_discard_thread(void *data) · line 1783
Quoted 10 lines
fs/f2fs/segment.c +5
-1-if (sbi->gc_mode ==GC_URGENT_HIGH || !f2fs_available_free_memory (sbi,DISCARD_CACHE ))__init_discard_policy (sbi, &dpolicy,DPOLICY_FORCE ,1 ); +if (!atomic_read (&dcc->discard_cmd_cnt)) { + dpolicy.max_interval =DEF_MAX_DISCARD_ISSUE_TIME ; + wait_ms = dpolicy.max_interval; +continue ; + }
Hmm.. how about cleaning up to configure discard policy in __init_discard_policy()?
Something like:
--- fs/f2fs/segment.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
fs/f2fs/segment.c +12 -7
@@ -1118,7 +1118,9 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->ordered = true;if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { dpolicy->granularity =1 ; - dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; +if (atomic_read (&SM_I (sbi)->dcc_info->discard_cmd_cnt)) + dpolicy->max_interval = +DEF_MIN_DISCARD_ISSUE_TIME ; } }else if (discard_type ==DPOLICY_FORCE ) { dpolicy->min_interval =DEF_MIN_DISCARD_ISSUE_TIME ;
@@ -1734,8 +1736,15 @@ static int issue_discard_thread(void *data)set_freezable (); do { - __init_discard_policy(sbi, &dpolicy, DPOLICY_BG, - dcc->discard_granularity); + if (sbi->gc_mode == GC_URGENT_HIGH || + !f2fs_available_free_memory(sbi, DISCARD_CACHE)) + __init_discard_policy(sbi, &dpolicy, DPOLICY_FORCE, 1); + else + __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) ||
@@ -1762,10 +1771,6 @@ static int issue_discard_thread(void *data)if (!atomic_read (&dcc->discard_cmd_cnt))continue ; -if (sbi->gc_mode ==GC_URGENT_HIGH || - !f2fs_available_free_memory (sbi,DISCARD_CACHE )) -__init_discard_policy (sbi, &dpolicy,DPOLICY_FORCE ,1 ); -sb_start_intwrite (sbi->sb); issued =__issue_discard_cmd (sbi, &dpolicy);
Signature · 5 lines
2.29.2 Thoughts? Thanks,
Quoted 5 lines
fs/f2fs/segment.c +1
-0+sb_start_intwrite (sbi->sb); issued =__issue_discard_cmd (sbi, &dpolicy);
Quoted 43 lines
thanks,
Sahitya.Quoted 39 lines
Thanks,
Quoted 37 lines
Thanks,
Sahitya.Quoted 32 lines
Thanks,
Quoted 30 lines
Signed-off-by Sahitya Tummala <[email protected]>--- fs/f2fs/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/segment.c +4
-1@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;@@ -1129,7 +1131,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->io_aware = true; dpolicy->sync = false; dpolicy->ordered = true; -if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { +if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL && +atomic_read (&dcc->discard_cmd_cnt)) { dpolicy->granularity =1 ; dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; }
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Chao,
Thanks for the review and suggestions.
I think the below code should work and cover all the cases we discussed. Let me test it and then put up a new patchset for review.
Thanks,
Sahitya.
Quoted 217 lines · Chao Yu
Hi Sahitya,
Quoted 72 lines · Sahitya Tummala
Hi Chao,
Quoted 56 lines · Chao Yu
Hi Sahitya,
Quoted 29 lines · Sahitya Tummala
Hi Chao,
Quoted 11 lines · Chao Yu
Sahitya,
Quoted 7 lines · Sahitya Tummala
When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (
DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued. This results into unnecessary frequent and periodic wake ups of the discard thread. This patch adds check for pending discard commands in addition to heavy utilization condition to prevent those wake ups.Quoted 4 lines
Could this commit fix your issue?
I don't think it will help because we are changing the max timeout of the dpolicy itself in
__init_discard_policy()when util > 80% as below -
dpolicy->max_interval=DEF_MIN_DISCARD_ISSUE_TIME;And
issue_discard_thread()uses this value aswait_ms, when there are no more pending discard commands to be issued. <snip>} else { wait_ms = dpolicy.max_interval; }Quoted 7 lines
<snip>
The new patch posted above is not changing anything related to the
max_interval. Hence, I think it won't help the uncessary wakeup problem I am trying to solve for this condition - util > 80% and when there are no pending discards.Please let me know if i am missing something.
Copied, thanks for the explanation.
But there is another case which can cause this issue in the case of disk util < 80%.
wait_ms=DEF_MIN_DISCARD_ISSUE_TIME;do { wait_event_interruptible_timeout(, wait_ms); ... if (!atomic_read(&dcc->discard_cmd_cnt)) [1] new statement continue;Quoted 4 lines
}
while();Then the loop will wakeup whenever 50ms timeout.
Yes, only for a short period of time i.e., until the first discard command is issued. Once a discard is issued, it will use
wait_ms= dpolicy.max_interval;Quoted 3 lines
So, to avoid this case, shouldn't we reset
wait_msto dpolicy.max_interval at [1]?Yes, we can add that to cover the above case.
Quoted 7 lines
Quoted 5 lines
Meanwhile, how about relocating
discard_cmd_cntcheck after__init_discard_policy(DPOLICY_FORCE)? and olny set .max_interval toDEF_MAX_DISCARD_ISSUE_TIMEif there is no discard command, and keep .granularity to 1?There is not need to change .granularity, right? It will be controlled
I think so.
Quoted 13 lines
as per utilization as it is done today. Only
max_intervalandwait_msneeds to be updated. Does this look good?fs/f2fs/segment.c +0
-2@@ -1772,13 +1772,16 @@ static int issue_discard_thread(void *data) wait_ms = dpolicy.max_interval;continue ; } -if (!atomic_read (&dcc->discard_cmd_cnt)) -continue ;fs/f2fs/segment.c static int issue_discard_thread(void *data) · line 1783
Quoted 10 lines
fs/f2fs/segment.c +5
-1-if (sbi->gc_mode ==GC_URGENT_HIGH || !f2fs_available_free_memory (sbi,DISCARD_CACHE ))__init_discard_policy (sbi, &dpolicy,DPOLICY_FORCE ,1 ); +if (!atomic_read (&dcc->discard_cmd_cnt)) { + dpolicy.max_interval =DEF_MAX_DISCARD_ISSUE_TIME ; + wait_ms = dpolicy.max_interval; +continue ; + }Hmm.. how about cleaning up to configure discard policy in
__init_discard_policy()?Something like:
--- fs/f2fs/segment.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)fs/f2fs/segment.c +12
-7@@ -1118,7 +1118,9 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->ordered = true;if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { dpolicy->granularity =1 ; - dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; +if (atomic_read (&SM_I (sbi)->dcc_info->discard_cmd_cnt)) + dpolicy->max_interval = +DEF_MIN_DISCARD_ISSUE_TIME ; } }else if (discard_type ==DPOLICY_FORCE ) { dpolicy->min_interval =DEF_MIN_DISCARD_ISSUE_TIME ;@@ -1734,8 +1736,15 @@ static int issue_discard_thread(void *data)set_freezable (); do { - __init_discard_policy(sbi, &dpolicy, DPOLICY_BG, - dcc->discard_granularity); + if (sbi->gc_mode == GC_URGENT_HIGH || + !f2fs_available_free_memory(sbi, DISCARD_CACHE)) + __init_discard_policy(sbi, &dpolicy, DPOLICY_FORCE, 1); + else + __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) ||@@ -1762,10 +1771,6 @@ static int issue_discard_thread(void *data)if (!atomic_read (&dcc->discard_cmd_cnt))continue ; -if (sbi->gc_mode ==GC_URGENT_HIGH || - !f2fs_available_free_memory (sbi,DISCARD_CACHE )) -__init_discard_policy (sbi, &dpolicy,DPOLICY_FORCE ,1 ); -sb_start_intwrite (sbi->sb); issued =__issue_discard_cmd (sbi, &dpolicy);Signature · 5 lines
2.29.2 Thoughts? Thanks,Quoted 48 lines
fs/f2fs/segment.c +1
-0+sb_start_intwrite (sbi->sb); issued =__issue_discard_cmd (sbi, &dpolicy);thanks,
Sahitya.Quoted 39 lines
Thanks,
Quoted 37 lines
Thanks,
Sahitya.Quoted 32 lines
Thanks,
Quoted 30 lines
Signed-off-by Sahitya Tummala <[email protected]>--- fs/f2fs/segment.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/f2fs/segment.c +4
-1@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;@@ -1129,7 +1131,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->io_aware = true; dpolicy->sync = false; dpolicy->ordered = true; -if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { +if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL && +atomic_read (&dcc->discard_cmd_cnt)) { dpolicy->granularity =1 ; dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; }
Signature · 9 lines
-- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum. _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v2 1/1 f2fs: fix the periodic wakeups of discard thread
Fix the unnecessary periodic wakeups of discard thread that happens under below two conditions -
1. When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued.
2. In the issue_discard_thread() path when there are no pending discard commands, it fails to reset the wait_ms to max timeout value.
---
v2:
- Fix the second scenario mentioned above in commit text
fs/f2fs/segment.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
fs/f2fs/segment.c +14 -7
@@ -1112,6 +1112,8 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,struct discard_policy *dpolicy, int discard_type, unsigned int granularity) { + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; +/* common policy */ dpolicy->type = discard_type; dpolicy->sync = true;
@@ -1131,7 +1133,9 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, dpolicy->ordered = true;if (utilization (sbi) >DEF_DISCARD_URGENT_UTIL ) { dpolicy->granularity =1 ; - dpolicy->max_interval =DEF_MIN_DISCARD_ISSUE_TIME ; +if (atomic_read (&dcc->discard_cmd_cnt)) + dpolicy->max_interval = +DEF_MIN_DISCARD_ISSUE_TIME ; } }else if (discard_type ==DPOLICY_FORCE ) { dpolicy->min_interval =DEF_MIN_DISCARD_ISSUE_TIME ;
@@ -1747,8 +1751,15 @@ static int issue_discard_thread(void *data)set_freezable (); do { - __init_discard_policy(sbi, &dpolicy, DPOLICY_BG, - dcc->discard_granularity); + if (sbi->gc_mode == GC_URGENT_HIGH || + !f2fs_available_free_memory(sbi, DISCARD_CACHE)) + __init_discard_policy(sbi, &dpolicy, DPOLICY_FORCE, 1); + else + __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) ||
@@ -1775,10 +1786,6 @@ static int issue_discard_thread(void *data)if (!atomic_read (&dcc->discard_cmd_cnt))continue ; -if (sbi->gc_mode ==GC_URGENT_HIGH || - !f2fs_available_free_memory (sbi,DISCARD_CACHE )) -__init_discard_policy (sbi, &dpolicy,DPOLICY_FORCE ,1 ); -sb_start_intwrite (sbi->sb); issued =__issue_discard_cmd (sbi, &dpolicy);
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v2] f2fs: fix the periodic wakeups of discard thread
Quoted 8 lines · Sahitya Tummala
Fix the unnecessary periodic wakeups of discard thread that happens under below two conditions -
1. When f2fs is heavily utilized over 80%, the current discard policy sets the max sleep timeout of discard thread as 50ms (
DEF_MIN_DISCARD_ISSUE_TIME). But this is set even when there are no pending discard commands to be issued.
Quoted 4 lines
2. In the
issue_discard_thread()path when there are no pending discard commands, it fails to reset thewait_msto max timeout value.Signed-off-by Sahitya Tummala <[email protected]>
Thanks,