2022-11-29 14:02:00

by 李扬韬

[permalink] [raw]
Subject: [PATCH] f2fs: issue discard when discard_cmd_cnt is not 0 in f2fs_put_super()

No need to call f2fs_issue_discard_timeout() in f2fs_put_super,
when no discard command requires issue. Since the caller of
f2fs_issue_discard_timeout() usually judges the number of discard
commands before using it. Let's move this logic to
f2fs_issue_discard_timeout().

By the way, use f2fs_realtime_discard_enable to simplify the code.

Signed-off-by: Yangtao Li <[email protected]>
---
fs/f2fs/segment.c | 6 ++++--
fs/f2fs/super.c | 6 ++----
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 9486ca49ecb1..d5f150a08285 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1655,6 +1655,9 @@ bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi)
struct discard_policy dpolicy;
bool dropped;

+ if (!atomic_read(&dcc->discard_cmd_cnt))
+ return false;
+
__init_discard_policy(sbi, &dpolicy, DPOLICY_UMOUNT,
dcc->discard_granularity);
__issue_discard_cmd(sbi, &dpolicy);
@@ -2110,8 +2113,7 @@ static void destroy_discard_cmd_control(struct f2fs_sb_info *sbi)
* Recovery can cache discard commands, so in error path of
* fill_super(), it needs to give a chance to handle them.
*/
- if (unlikely(atomic_read(&dcc->discard_cmd_cnt)))
- f2fs_issue_discard_timeout(sbi);
+ f2fs_issue_discard_timeout(sbi);

kfree(dcc);
SM_I(sbi)->dcc_info = NULL;
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 79bf1faf4161..71e6b2bea1f4 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1576,8 +1576,7 @@ static void f2fs_put_super(struct super_block *sb)
/* be sure to wait for any on-going discard commands */
dropped = f2fs_issue_discard_timeout(sbi);

- if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) &&
- !sbi->discard_blks && !dropped) {
+ if (f2fs_realtime_discard_enable(sbi) && !sbi->discard_blks && !dropped) {
struct cp_control cpc = {
.reason = CP_UMOUNT | CP_TRIMMED,
};
@@ -2408,8 +2407,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
} else {
dcc = SM_I(sbi)->dcc_info;
f2fs_stop_discard_thread(sbi);
- if (atomic_read(&dcc->discard_cmd_cnt))
- f2fs_issue_discard_timeout(sbi);
+ f2fs_issue_discard_timeout(sbi);
need_restart_discard = true;
}
}
--
2.25.1


2022-11-30 17:42:22

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] f2fs: issue discard when discard_cmd_cnt is not 0 in f2fs_put_super()

Hi Yangtao,

I love your patch! Perhaps something to improve:

[auto build test WARNING on jaegeuk-f2fs/dev-test]
[also build test WARNING on jaegeuk-f2fs/dev linus/master v6.1-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Yangtao-Li/f2fs-issue-discard-when-discard_cmd_cnt-is-not-0-in-f2fs_put_super/20221130-110654
base: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test
patch link: https://lore.kernel.org/r/20221129134018.34120-1-frank.li%40vivo.com
patch subject: [PATCH] f2fs: issue discard when discard_cmd_cnt is not 0 in f2fs_put_super()
config: x86_64-randconfig-a011
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/ecfaeeb102cb22ad0b39670f674763735763db2f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yangtao-Li/f2fs-issue-discard-when-discard_cmd_cnt-is-not-0-in-f2fs_put_super/20221130-110654
git checkout ecfaeeb102cb22ad0b39670f674763735763db2f
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

fs/f2fs/super.c: In function 'f2fs_remount':
>> fs/f2fs/super.c:2227:37: warning: variable 'dcc' set but not used [-Wunused-but-set-variable]
2227 | struct discard_cmd_control *dcc;
| ^~~


vim +/dcc +2227 fs/f2fs/super.c

4354994f097d06 Daniel Rosenberg 2018-08-20 2209
696c018c7718f5 Namjae Jeon 2013-06-16 2210 static int f2fs_remount(struct super_block *sb, int *flags, char *data)
696c018c7718f5 Namjae Jeon 2013-06-16 2211 {
696c018c7718f5 Namjae Jeon 2013-06-16 2212 struct f2fs_sb_info *sbi = F2FS_SB(sb);
696c018c7718f5 Namjae Jeon 2013-06-16 2213 struct f2fs_mount_info org_mount_opt;
0abd675e97e60d Chao Yu 2017-07-09 2214 unsigned long old_sb_flags;
63189b785960c3 Chao Yu 2018-03-08 2215 int err;
3fd9735908287c Chao Yu 2021-03-17 2216 bool need_restart_gc = false, need_stop_gc = false;
3fd9735908287c Chao Yu 2021-03-17 2217 bool need_restart_ckpt = false, need_stop_ckpt = false;
3fd9735908287c Chao Yu 2021-03-17 2218 bool need_restart_flush = false, need_stop_flush = false;
4d67490498acb4 Fengnan Chang 2021-08-19 2219 bool need_restart_discard = false, need_stop_discard = false;
9cd81ce3c2f01f Chao Yu 2015-09-18 2220 bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
277afbde6ca2b3 Chao Yu 2021-07-29 2221 bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT);
1f78adfab379e5 Chao Yu 2019-07-12 2222 bool no_io_align = !F2FS_IO_ALIGNED(sbi);
093749e296e29a Chao Yu 2020-08-04 2223 bool no_atgc = !test_opt(sbi, ATGC);
4d67490498acb4 Fengnan Chang 2021-08-19 2224 bool no_discard = !test_opt(sbi, DISCARD);
6ce19aff0b8cd3 Chao Yu 2021-05-20 2225 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE);
4f993264fe2965 Chao Yu 2021-08-03 2226 bool block_unit_discard = f2fs_block_unit_discard(sbi);
4d67490498acb4 Fengnan Chang 2021-08-19 @2227 struct discard_cmd_control *dcc;
4b2414d04e9912 Chao Yu 2017-08-08 2228 #ifdef CONFIG_QUOTA
4b2414d04e9912 Chao Yu 2017-08-08 2229 int i, j;
4b2414d04e9912 Chao Yu 2017-08-08 2230 #endif
696c018c7718f5 Namjae Jeon 2013-06-16 2231
696c018c7718f5 Namjae Jeon 2013-06-16 2232 /*
696c018c7718f5 Namjae Jeon 2013-06-16 2233 * Save the old mount options in case we
696c018c7718f5 Namjae Jeon 2013-06-16 2234 * need to restore them.
696c018c7718f5 Namjae Jeon 2013-06-16 2235 */
696c018c7718f5 Namjae Jeon 2013-06-16 2236 org_mount_opt = sbi->mount_opt;
0abd675e97e60d Chao Yu 2017-07-09 2237 old_sb_flags = sb->s_flags;
696c018c7718f5 Namjae Jeon 2013-06-16 2238

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (4.37 kB)
config (161.01 kB)
Download all attachments