Skip to contentSkip to conversation

f2fs: avoid unnecessary fg_gc

PATCH In review Hou Pengyang 4 participants 15 messages Feb 24, 2017 – Feb 28, 2017 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: avoid unnecessary fg_gc

Under scenerio with large number of dirty nodes, and these nodes are flushed in SSR mode during cp. enough free segemts now, no need to do fggc.

---
 fs/f2fs/gc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +1 -1
index 6c996e3..41bdfb7 100644
@@ -959,7 +959,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
 		 * garbage collections.
 		 */
 		ret = write_checkpoint(sbi, &cpc);
-		if (ret)
+		if (ret || !has_not_enough_free_secs(sbi, sec_freed, 0))
 			goto stop;
 	} else if (gc_type == BG_GC && !background) {
 		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
#1 lore raw
Quoted 2 lines · Hou Pengyang

Under scenerio with large number of dirty nodes, and these nodes are flushed in SSR mode during cp. enough free segemts now, no need to do fggc.

We'd better break out of GC flow once we encounter cp error, so additional condition judgment is not needed.

Thanks,

Quoted 12 lines
---
 fs/f2fs/gc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +0 -0
index 6c996e3..41bdfb7 100644

fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) · line 965

Quoted 8 lines
fs/f2fs/gc.c +1 -1
@@ -959,7 +959,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
 		 * garbage collections.
 		 */
 		ret = write_checkpoint(sbi, &cpc);
-		if (ret)
+		if (ret || !has_not_enough_free_secs(sbi, sec_freed, 0))
 			goto stop;
 	} else if (gc_type == BG_GC && !background) {
 		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#2 lore raw
Quoted 7 lines · Chao Yu
Quoted 2 lines · Hou Pengyang

Under scenerio with large number of dirty nodes, and these nodes are flushed in SSR mode during cp. enough free segemts now, no need to do fggc.

We'd better break out of GC flow once we encounter cp error, so additional condition judgment is not needed.

In (ret || !has_not_enough_free_secs(sbi, sec_freed, 0)), if cp return error(NOT zero), flow will goto stop directly without has_not_enough_free_secs checking;
if cp return ok(zero), has_not_enough_free_secs would be checked.

Thanks,

Quoted 17 lines

Thanks,

Quoted 15 lines
---
  fs/f2fs/gc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +0 -1
index 6c996e3..41bdfb7 100644
@@ -959,7 +959,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
  		 * garbage collections.
  		 */
  		ret = write_checkpoint(sbi, &cpc);
-		if (ret)
Quoted 9 lines

fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) · line 965

Quoted 5 lines
fs/f2fs/gc.c +1 -0
+		if (ret || !has_not_enough_free_secs(sbi, sec_freed, 0))
  			goto stop;
  	} else if (gc_type == BG_GC && !background) {
  		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#3 lore raw
Quoted 5 lines · Hou Pengyang
Quoted 4 lines · Chao Yu
Quoted 2 lines · Hou Pengyang

Under scenerio with large number of dirty nodes, and these nodes are flushed in SSR mode during cp. enough free segemts now, no need to do fggc.

Quoted 8 lines
Quoted 3 lines

We'd better break out of GC flow once we encounter cp error, so additional condition judgment is not needed.

In (ret || !has_not_enough_free_secs(sbi, sec_freed, 0)), if cp return error(NOT zero), flow will goto stop directly without has_not_enough_free_secs checking;
if cp return ok(zero), has_not_enough_free_secs would be checked.

Oh, sorry, I misunderstood your patch, can you add some comments in the code too?

Thanks,

Quoted 32 lines

Thanks,

Quoted 17 lines

Thanks,

Quoted 15 lines
---
  fs/f2fs/gc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +0 -1
index 6c996e3..41bdfb7 100644
@@ -959,7 +959,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
  		 * garbage collections.
  		 */
  		ret = write_checkpoint(sbi, &cpc);
-		if (ret)
Quoted 9 lines

fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) · line 965

Quoted 5 lines
fs/f2fs/gc.c +1 -0
+		if (ret || !has_not_enough_free_secs(sbi, sec_freed, 0))
  			goto stop;
  	} else if (gc_type == BG_GC && !background) {
  		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */

.

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

maintainer
#4 lore raw
In reply to Hou Pengyang
Quoted 5 lines · Hou Pengyang
Quoted 4 lines · Chao Yu
Quoted 2 lines · Hou Pengyang

Under scenerio with large number of dirty nodes, and these nodes are flushed in SSR mode during cp. enough free segemts now, no need to do fggc.

Quoted 8 lines
Quoted 3 lines

We'd better break out of GC flow once we encounter cp error, so additional condition judgment is not needed.

In (ret || !has_not_enough_free_secs(sbi, sec_freed, 0)), if cp return error(NOT zero), flow will goto stop directly without has_not_enough_free_secs checking;
if cp return ok(zero), has_not_enough_free_secs would be checked.

Well, I think it'd be fine to do one gc by a background thread.

Thanks,

Quoted 30 lines

Thanks,

Quoted 26 lines

Thanks,

Quoted 12 lines
---
  fs/f2fs/gc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +0 -0
index 6c996e3..41bdfb7 100644

fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) · line 965

Quoted 8 lines
fs/f2fs/gc.c +1 -1
@@ -959,7 +959,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
  		 * garbage collections.
  		 */
  		ret = write_checkpoint(sbi, &cpc);
-		if (ret)
+		if (ret || !has_not_enough_free_secs(sbi, sec_freed, 0))
  			goto stop;
  	} else if (gc_type == BG_GC && !background) {
  		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#5 lore raw

Hi all,

I am really confused by the condition below use sec_freed, is it always equal to zero?

Or, gc more process will recheck this condition?

	if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0))
Quoted 50 lines · Jaegeuk Kim
Quoted 5 lines · Hou Pengyang
Quoted 4 lines · Chao Yu
Quoted 2 lines · Hou Pengyang

Under scenerio with large number of dirty nodes, and these nodes are flushed in SSR mode during cp. enough free segemts now, no need to do fggc.

Quoted 8 lines
Quoted 3 lines

We'd better break out of GC flow once we encounter cp error, so additional condition judgment is not needed.

In (ret || !has_not_enough_free_secs(sbi, sec_freed, 0)), if cp return error(NOT zero), flow will goto stop directly without has_not_enough_free_secs checking;
if cp return ok(zero), has_not_enough_free_secs would be checked.

Well, I think it'd be fine to do one gc by a background thread.

Thanks,

Quoted 30 lines

Thanks,

Quoted 26 lines

Thanks,

Quoted 12 lines
---
  fs/f2fs/gc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +0 -0
index 6c996e3..41bdfb7 100644

fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) · line 965

Quoted 8 lines
fs/f2fs/gc.c +1 -1
@@ -959,7 +959,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
  		 * garbage collections.
  		 */
  		ret = write_checkpoint(sbi, &cpc);
-		if (ret)
+		if (ret || !has_not_enough_free_secs(sbi, sec_freed, 0))
  			goto stop;
  	} else if (gc_type == BG_GC && !background) {
  		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */

.

Quoted 9 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

maintainer
#6 lore raw
Quoted 3 lines · heyunlei

Hi all,

I am really confused by the condition below use sec_freed, is it always equal to zero?

Seems it is always zero. Let's fix it together.

Pengyang,

I merged your patches and finally got this.
How do you think?

Quoted 1 line

From d1c2206e4f245a8fedec3a8f21ad522b3b1b2d0c Mon Sep 17 00:00:00 2001

From: Hou Pengyang <[email protected]>
Date: Sat, 25 Feb 2017 03:57:38 +0000
Subject: [PATCH] f2fs: avoid bggc->fggc when enough free segments are
avaliable after cp

We use has_not_enough_free_secs to check if there are enough free segments,

    	(free_sections(sbi) + freed) <=
	        (node_secs + 2 * dent_secs + imeta_secs +
			         reserved_sections(sbi) + needed);

Under scenario with large number of dirty nodes, these nodes would be flushed during cp, as a result, right side of the inequality would be decreased, while left side stays unchanged if these nodes are flushed in SSR way, which means there are enough free segments after this cp.

For this case, we just do a bggc instead of fggc.

---
 fs/f2fs/gc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
fs/f2fs/gc.c +9 -8
index 1af17c5af603..471ed899f639 100644
@@ -954,21 +954,22 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
 		goto stop;
 	}
 
-	if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {
-		gc_type = FG_GC;
+	if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) {
 		/*
-		 * If there is no victim and no prefree segment but still not
-		 * enough free sections, we should flush dent/node blocks and do
-		 * garbage collections.
+		 * For example, if there are many prefree_segments below given
+		 * threshold, we can make them free by checkpoint. Then, we
+		 * secure free segments which doesn't need fggc any more.
 		 */
 		ret = write_checkpoint(sbi, &cpc);
 		if (ret)
 			goto stop;
-	} else if (gc_type == BG_GC && !background) {
-		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
-		goto stop;
+		if (has_not_enough_free_secs(sbi, 0, 0))
+			gc_type = FG_GC;
 	}
 
+	/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
+	if (gc_type == BG_GC && !background)
+		goto stop;
 	if (!__get_victim(sbi, &segno, gc_type))
 		goto stop;
 	ret = 0;
Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
#7 lore raw
Quoted 12 lines · Jaegeuk Kim
Quoted 3 lines · heyunlei

Hi all,

I am really confused by the condition below use sec_freed, is it always equal to zero?

Seems it is always zero. Let's fix it together.

Pengyang,

I merged your patches and finally got this.
How do you think?

Seems OK to me :)

Thanks,

Quoted 51 lines
Quoted 1 line

From d1c2206e4f245a8fedec3a8f21ad522b3b1b2d0c Mon Sep 17 00:00:00 2001

From: Hou Pengyang <[email protected]>
Date: Sat, 25 Feb 2017 03:57:38 +0000
Subject: [PATCH] f2fs: avoid bggc->fggc when enough free segments are
avaliable after cp

We use has_not_enough_free_secs to check if there are enough free segments,

     	(free_sections(sbi) + freed) <=
	        (node_secs + 2 * dent_secs + imeta_secs +
			         reserved_sections(sbi) + needed);

Under scenario with large number of dirty nodes, these nodes would be flushed during cp, as a result, right side of the inequality would be decreased, while left side stays unchanged if these nodes are flushed in SSR way, which means there are enough free segments after this cp.

For this case, we just do a bggc instead of fggc.

---
  fs/f2fs/gc.c | 17 +++++++++--------
  1 file changed, 9 insertions(+), 8 deletions(-)
fs/f2fs/gc.c +4 -8
index 1af17c5af603..471ed899f639 100644
@@ -954,21 +954,22 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
  		goto stop;
  	}
 
-	if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {
-		gc_type = FG_GC;
+	if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) {
  		/*
-		 * If there is no victim and no prefree segment but still not
-		 * enough free sections, we should flush dent/node blocks and do
-		 * garbage collections.
+		 * For example, if there are many prefree_segments below given
+		 * threshold, we can make them free by checkpoint. Then, we
+		 * secure free segments which doesn't need fggc any more.
  		 */
  		ret = write_checkpoint(sbi, &cpc);
  		if (ret)
  			goto stop;
-	} else if (gc_type == BG_GC && !background) {
-		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
-		goto stop;

fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) · line 975

Quoted 10 lines
fs/f2fs/gc.c +5 -0
+		if (has_not_enough_free_secs(sbi, 0, 0))
+			gc_type = FG_GC;
  	}
 
+	/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
+	if (gc_type == BG_GC && !background)
+		goto stop;
  	if (!__get_victim(sbi, &segno, gc_type))
  		goto stop;
  	ret = 0;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#8 lore raw

Hi Jaegeuk,

Quoted 5 lines · Hou Pengyang

We use has_not_enough_free_secs to check if there are enough free segments,

         (free_sections(sbi) + freed) <=
            (node_secs + 2 * dent_secs + imeta_secs +
                     reserved_sections(sbi) + needed);

Now node SSR is enable, how can we change this condition simply as:

(free_sections(sbi) + freed) <= reserved_sections(sbi)

If dirty node pages can find SSR segment, write it in SSR mode,

or it will consume free segments, and then we do FG_GC.

Another thing is that each process has a chance to do FG_GC, it's no problem

for all normal processes, but may be not a good thing for a process within

certain limits such as lower priority, with bound cpu to do FG_GC. Maybe it

will block system for a long time. So what can we do to improve this?

Thanks.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

maintainer
#9 lore raw
Quoted 5 lines · heyunlei

Hi Jaegeuk,

Quoted 2 lines · Hou Pengyang

We use has_not_enough_free_secs to check if there are enough free segments,

Quoted 7 lines
Quoted 3 lines
         (free_sections(sbi) + freed) <=
            (node_secs + 2 * dent_secs + imeta_secs +
                     reserved_sections(sbi) + needed);

Now node SSR is enable, how can we change this condition simply as:

(free_sections(sbi) + freed) <= reserved_sections(sbi)

Currently, we can't guarantee successful SSR allocation all the time.

Quoted 6 lines

If dirty node pages can find SSR segment, write it in SSR mode,

or it will consume free segments, and then we do FG_GC.

Quoted 7 lines

Another thing is that each process has a chance to do FG_GC, it's no problem

for all normal processes, but may be not a good thing for a process within

certain limits such as lower priority, with bound cpu to do FG_GC. Maybe it

will block system for a long time. So what can we do to improve this?

Could you please elaborate this in more detail?

Thanks,

Quoted 3 lines

Thanks.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#10 lore raw
Quoted 10 lines · Jaegeuk Kim
Quoted 9 lines · heyunlei

Hi Jaegeuk,

Quoted 5 lines · Hou Pengyang

We use has_not_enough_free_secs to check if there are enough free segments,

         (free_sections(sbi) + freed) <=
            (node_secs + 2 * dent_secs + imeta_secs +
                     reserved_sections(sbi) + needed);
Quoted 5 lines
Quoted 3 lines

Now node SSR is enable, how can we change this condition simply as:

(free_sections(sbi) + freed) <= reserved_sections(sbi)

Currently, we can't guarantee successful SSR allocation all the time.

Okay, thanks.

Quoted 9 lines
Quoted 9 lines

If dirty node pages can find SSR segment, write it in SSR mode,

or it will consume free segments, and then we do FG_GC.

Another thing is that each process has a chance to do FG_GC, it's no problem

Quoted 7 lines
Quoted 5 lines

for all normal processes, but may be not a good thing for a process within

certain limits such as lower priority, with bound cpu to do FG_GC. Maybe it

will block system for a long time. So what can we do to improve this?

Could you please elaborate this in more detail?

System bind lots of background processes to one or two cpus. In some corner case,

thread need to do FG GC will compete with other background processes. FG GC can

not be completed in time and then blocks other processes.

Thanks.

Quoted 9 lines

Thanks,

Quoted 3 lines

Thanks.

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

Reviewed-by
#11 lore raw
In reply to Jaegeuk Kim
Quoted 29 lines · Jaegeuk Kim
Quoted 3 lines · heyunlei

Hi all,

I am really confused by the condition below use sec_freed, is it always equal to zero?

Seems it is always zero. Let's fix it together.

Pengyang,

I merged your patches and finally got this.
How do you think?

Quoted 1 line

From d1c2206e4f245a8fedec3a8f21ad522b3b1b2d0c Mon Sep 17 00:00:00 2001

From: Hou Pengyang <[email protected]>
Date: Sat, 25 Feb 2017 03:57:38 +0000
Subject: [PATCH] f2fs: avoid bggc->fggc when enough free segments are
avaliable after cp

We use has_not_enough_free_secs to check if there are enough free segments,

    	(free_sections(sbi) + freed) <=
	        (node_secs + 2 * dent_secs + imeta_secs +
			         reserved_sections(sbi) + needed);

Under scenario with large number of dirty nodes, these nodes would be flushed during cp, as a result, right side of the inequality would be decreased, while left side stays unchanged if these nodes are flushed in SSR way, which means there are enough free segments after this cp.

Quoted 4 lines

For this case, we just do a bggc instead of fggc.

Thanks,

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#12 lore raw
In reply to Jaegeuk Kim
Quoted 10 lines · Jaegeuk Kim
Quoted 9 lines · Hou Pengyang
Quoted 7 lines · Chao Yu
Quoted 2 lines · Hou Pengyang

Under scenerio with large number of dirty nodes, and these nodes are flushed in SSR mode during cp. enough free segemts now, no need to do fggc.

We'd better break out of GC flow once we encounter cp error, so additional condition judgment is not needed.

Quoted 7 lines
Quoted 4 lines

In (ret || !has_not_enough_free_secs(sbi, sec_freed, 0)), if cp return error(NOT zero), flow will goto stop directly without has_not_enough_free_secs checking;
if cp return ok(zero), has_not_enough_free_secs would be checked.

Well, I think it'd be fine to do one gc by a background thread.

Currently we decide whether convert a bggc to fggc by:

if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {

          gc_type = FG_GC;

So how about move up write_checkpoint before gc_type = FG_GC, like:

if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {
          write_checkpoint;
	 if still has_not_enough_free_secs:
               gc_type = FG_GC;
          else
               stay BG_GC;

Thanks,

Quoted 33 lines

Thanks,

Quoted 30 lines

Thanks,

Quoted 26 lines

Thanks,

Quoted 12 lines
---
   fs/f2fs/gc.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +0 -0
index 6c996e3..41bdfb7 100644

fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) · line 965

Quoted 8 lines
fs/f2fs/gc.c +1 -1
@@ -959,7 +959,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
   		 * garbage collections.
   		 */
   		ret = write_checkpoint(sbi, &cpc);
-		if (ret)
+		if (ret || !has_not_enough_free_secs(sbi, sec_freed, 0))
   			goto stop;
   	} else if (gc_type == BG_GC && !background) {
   		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */

.

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#13 lore raw

PATCH 1/2 remove stale comment info about cp before fggc

In reply to Jaegeuk Kim

In commit c026d3677 (f2fs: remove unnecessary condition check for write_checkpoint in f2fs_gc) we have removed all the prefree segments/dirty segments checking before cp, remove related comment.

---
 fs/f2fs/gc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/f2fs/gc.c +1 -5
index 6c996e3..ffff67ac 100644
@@ -953,11 +953,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
 
 	if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {
 		gc_type = FG_GC;
-		/*
-		 * If there is no victim and no prefree segment but still not
-		 * enough free sections, we should flush dent/node blocks and do
-		 * garbage collections.
-		 */
+
 		ret = write_checkpoint(sbi, &cpc);
 		if (ret)
 			goto stop;
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
#14 lore raw

PATCH 2/2 f2fs: avoid bggc->fggc when enough free segments are avaliable after cp

We use has_not_enough_free_secs to check if there are enough free segments,

    	(free_sections(sbi) + freed) <=
	        (node_secs + 2 * dent_secs + imeta_secs +
			         reserved_sections(sbi) + needed);

Under scenario with large number of dirty nodes, these nodes would be flushed during cp, as a result, right side of the inequality would be decreased, while left side stays unchanged if these nodes are flushed in SSR way, which means there are enough free segments after this cp.

For this case, we just do a bggc instead of fggc.

---
 fs/f2fs/gc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/gc.c +6 -1
index ffff67ac..8cf751f 100644
@@ -952,11 +952,16 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
 	}
 
 	if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {
-		gc_type = FG_GC;
 
+		/*
+		 * After cp, there may be enough free segments avaliable, In this case,
+		 * We just do a bggc instead of fggc.
+		 */
 		ret = write_checkpoint(sbi, &cpc);
 		if (ret)
 			goto stop;
+		if (has_not_enough_free_secs(sbi, sec_freed, 0))
+			gc_type = FG_GC;
 	} else if (gc_type == BG_GC && !background) {
 		/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
 		goto stop;
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot