Skip to contentSkip to conversation

f2fs: don't call f2fs_issue_discard_timeout() when discard_cmd_cnt is 0 in f2fs_put_super()

PATCH In review Yangtao Li 3 participants 9 messages Dec 2, 2022 – Dec 13, 2022 F2FS file system

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH v2 1/1 f2fs: don't call f2fs_issue_discard_timeout() when discard_cmd_cnt is 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.

---
 fs/f2fs/segment.c | 6 ++++--
 fs/f2fs/super.c   | 8 ++------
 2 files changed, 6 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +4 -2
index 9486ca49ecb1..d5f150a08285 100644
@@ -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;
fs/f2fs/super.c +2 -6
index 79bf1faf4161..aa1cadfd34a5 100644
@@ -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,
 		};
@@ -2225,7 +2224,6 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	bool no_discard = !test_opt(sbi, DISCARD);
 	bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE);
 	bool block_unit_discard = f2fs_block_unit_discard(sbi);
-	struct discard_cmd_control *dcc;
 #ifdef CONFIG_QUOTA
 	int i, j;
 #endif
@@ -2406,10 +2404,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 				goto restore_flush;
 			need_stop_discard = true;
 		} 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;
 		}
 	}
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer
#1 lore raw
Quoted 44 lines · Yangtao Li

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.

---
  fs/f2fs/segment.c | 6 ++++--
  fs/f2fs/super.c   | 8 ++------
  2 files changed, 6 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +4 -2
index 9486ca49ecb1..d5f150a08285 100644
@@ -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;
fs/f2fs/super.c +0 -0
index 79bf1faf4161..aa1cadfd34a5 100644

fs/f2fs/super.c static void f2fs_put_super(struct super_block *sb) · line 1579

Quoted 6 lines
fs/f2fs/super.c +1 -2
@@ -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) {

static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi)

{
	return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) ||
					f2fs_hw_should_discard(sbi);
}

It looks the logic is changed?

Thanks,

Quoted 23 lines
fs/f2fs/super.c +1 -4
  		struct cp_control cpc = {
  			.reason = CP_UMOUNT | CP_TRIMMED,
  		};
@@ -2225,7 +2224,6 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  	bool no_discard = !test_opt(sbi, DISCARD);
  	bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE);
  	bool block_unit_discard = f2fs_block_unit_discard(sbi);
-	struct discard_cmd_control *dcc;
  #ifdef CONFIG_QUOTA
  	int i, j;
  #endif
@@ -2406,10 +2404,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
  				goto restore_flush;
  			need_stop_discard = true;
  		} 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;
  		}
  	}
author
#2 lore raw

Hi,

Quoted 6 lines
static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) {
	return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) ||
					f2fs_hw_should_discard(sbi);
}

It looks the logic is changed?

For a storage device that does not support discard, and we have not actually issued any discard command. I don't think it is necessary and f2fs should not be equipped with trim markers.

Thx,
Yangtao

maintainer
#3 lore raw
Quoted 7 lines · Yangtao Li

Hi,

Quoted 4 lines
static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) {
	return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) ||
					f2fs_hw_should_discard(sbi);
}
Quoted 5 lines
Quoted 1 line

It looks the logic is changed?

For a storage device that does not support discard, and we have not actually issued any discard command. I don't think it is necessary and f2fs should not be equipped with trim markers.

The difference here is, if we use f2fs_realtime_discard_enable() in f2fs_put_super(), we will only write checkpoint w/ CP_TRIMMED flag when discard option is enable and device supports discard.

But actually, if discard option is disabled, we still needs to give put_super() a chance to write checkpoint w/ CP_TRIMMED flag.

Thanks,

Quoted 3 lines

Thx,
Yangtao

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

author
#4 lore raw

Hi Chao,

Quoted 6 lines

The difference here is, if we use f2fs_realtime_discard_enable() in f2fs_put_super(), we will only write checkpoint w/ CP_TRIMMED flag when discard option is enable and device supports discard.

But actually, if discard option is disabled, we still needs to give put_super() a chance to write checkpoint w/ CP_TRIMMED flag.

Why do we still have to set the CP_TRIMMED flag when the discard opt is not set. Did I miss something?

Thx,
Yangtao

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

maintainer
#5 lore raw
Quoted 11 lines · Yangtao Li

Hi Chao,

Quoted 6 lines

The difference here is, if we use f2fs_realtime_discard_enable() in f2fs_put_super(), we will only write checkpoint w/ CP_TRIMMED flag when discard option is enable and device supports discard.

But actually, if discard option is disabled, we still needs to give put_super() a chance to write checkpoint w/ CP_TRIMMED flag.

Why do we still have to set the CP_TRIMMED flag when the discard opt is not set. Did I miss something?

Hi Yangtao,

I guess it's up to scenario. e.g.

mount w/ nodiscard and use FITRIM to trigger in-batch discard, if we set CP_TRIMMED flag during umount, next time, after mount w/ discard, it doesn't to issue redundant discard.

Thanks,

Quoted 3 lines

Thx,
Yangtao

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

maintainer
#6 lore raw
Quoted 13 lines · Chao Yu
Quoted 11 lines · Yangtao Li

Hi Chao,

Quoted 6 lines

The difference here is, if we use f2fs_realtime_discard_enable() in f2fs_put_super(), we will only write checkpoint w/ CP_TRIMMED flag when discard option is enable and device supports discard.

But actually, if discard option is disabled, we still needs to give put_super() a chance to write checkpoint w/ CP_TRIMMED flag.

Why do we still have to set the CP_TRIMMED flag when the discard opt is not set. Did I miss something?

Quoted 7 lines

Hi Yangtao,

I guess it's up to scenario. e.g.

mount w/ nodiscard and use FITRIM to trigger in-batch discard, if we set CP_TRIMMED flag during umount, next time, after mount w/ discard, it doesn't to issue redundant discard.

If fitrim was called with a range, we can get a wrong FI_TRIMMED flag. Isn't it better to get a full discard range after remount even though some are redundant?

Quoted 6 lines

Thanks,

Quoted 3 lines

Thx,
Yangtao

maintainer
#7 lore raw
Quoted 16 lines · Jaegeuk Kim
Quoted 15 lines · Chao Yu
Quoted 11 lines · Yangtao Li

Hi Chao,

Quoted 6 lines

The difference here is, if we use f2fs_realtime_discard_enable() in f2fs_put_super(), we will only write checkpoint w/ CP_TRIMMED flag when discard option is enable and device supports discard.

But actually, if discard option is disabled, we still needs to give put_super() a chance to write checkpoint w/ CP_TRIMMED flag.

Why do we still have to set the CP_TRIMMED flag when the discard opt is not set. Did I miss something?

Hi Yangtao,

Quoted 7 lines
Quoted 5 lines

I guess it's up to scenario. e.g.

mount w/ nodiscard and use FITRIM to trigger in-batch discard, if we set CP_TRIMMED flag during umount, next time, after mount w/ discard, it doesn't to issue redundant discard.

If fitrim was called with a range, we can get a wrong FI_TRIMMED flag. Isn't it

We can set CP_TRIMMED flag only if fitrim was called on full range w/ 4k granularity, due to it will check sbi->discard_blks variable to make sure there is no range we haven't trimmed.

Quoted 1 line

better to get a full discard range after remount even though some are redundant?

If nodiscard is set, and sbi->discard_blks becomes zero, it says a full range fitrim was been triggered.

So, previous check condition has no problem, right?

	if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) &&
					!sbi->discard_blks && !dropped) {

Thanks,

Quoted 7 lines
Quoted 7 lines

Thanks,

Quoted 3 lines

Thx,
Yangtao

maintainer
#8 lore raw
Quoted 25 lines · Chao Yu
Quoted 16 lines · Jaegeuk Kim
Quoted 15 lines · Chao Yu
Quoted 11 lines · Yangtao Li

Hi Chao,

Quoted 6 lines

The difference here is, if we use f2fs_realtime_discard_enable() in f2fs_put_super(), we will only write checkpoint w/ CP_TRIMMED flag when discard option is enable and device supports discard.

But actually, if discard option is disabled, we still needs to give put_super() a chance to write checkpoint w/ CP_TRIMMED flag.

Why do we still have to set the CP_TRIMMED flag when the discard opt is not set. Did I miss something?

Hi Yangtao,

Quoted 7 lines
Quoted 5 lines

I guess it's up to scenario. e.g.

mount w/ nodiscard and use FITRIM to trigger in-batch discard, if we set CP_TRIMMED flag during umount, next time, after mount w/ discard, it doesn't to issue redundant discard.

If fitrim was called with a range, we can get a wrong FI_TRIMMED flag. Isn't it

Quoted 8 lines

We can set CP_TRIMMED flag only if fitrim was called on full range w/ 4k granularity, due to it will check sbi->discard_blks variable to make sure there is no range we haven't trimmed.

Quoted 1 line

better to get a full discard range after remount even though some are redundant?

If nodiscard is set, and sbi->discard_blks becomes zero, it says a full range fitrim was been triggered.

That gives another assumption, and I prefer to make it simple.

Quoted 15 lines

So, previous check condition has no problem, right?

	if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) &&
					!sbi->discard_blks && !dropped) {

Thanks,

Quoted 7 lines
Quoted 7 lines

Thanks,

Quoted 3 lines

Thx,
Yangtao

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