Skip to contentSkip to conversation

f2fs: drop non uptodata page during GC

PATCH In review Yunlei He 4 participants 9 messages Nov 7, 2025 – Dec 27, 2025 F2FS file system

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: drop non uptodata page during GC

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

---
 fs/f2fs/gc.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/gc.c +5 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
 	struct node_info ni;
 	struct folio *folio, *mfolio;
 	block_t newaddr;
+	bool need_invalidate = true;
 	int err = 0;
 	bool lfs_mode = f2fs_lfs_mode(fio.sbi);
 	int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode *inode, block_t bidx,
 put_out:
 	f2fs_put_dnode(&dn);
 out:
+	if (folio_test_uptodate(folio))
+		need_invalidate = false;
 	f2fs_folio_put(folio, true);
+	if (need_invalidate)
+		invalidate_mapping_pages(mapping, bidx, bidx);
 	return err;
 }
 
Signature · 8 lines
2.34.1



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

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Quoted 20 lines
---
  fs/f2fs/gc.c | 5 +++++
  1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
  	struct node_info ni;
  	struct folio *folio, *mfolio;
  	block_t newaddr;
+	bool need_invalidate = true;
  	int err = 0;
  	bool lfs_mode = f2fs_lfs_mode(fio.sbi);
  	int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c static int move_data_block(struct inode *inode, block_t bidx, · line 1455

Quoted 5 lines
fs/f2fs/gc.c +2 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode *inode, block_t bidx,
  put_out:
  	f2fs_put_dnode(&dn);
  out:
+	if (folio_test_uptodate(folio))
+		need_invalidate = false;

How about dropping such folio under its lock?

if (!folio_test_uptodate())
truncate_inode_partial_folio()

fs/f2fs/gc.c static int move_data_block(struct inode *inode, block_t bidx, · line 1461

Quoted 6 lines
fs/f2fs/gc.c +2 -0
  	f2fs_folio_put(folio, true);
+	if (need_invalidate)
+		invalidate_mapping_pages(mapping, bidx, bidx);
  	return err;
  }
 

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

#2 lore raw
Quoted 10 lines · On 11/8/25 11:11, Chao Yu via Linux-f2fs-devel wrote:

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Yes, move_data_block() doesn’t read any data to folio, and the GC usually selects cold data. Therefore, this folio is typically not uptodate, and there’s no need for it to occupy the page cache.

Quoted 30 lines
Quoted 22 lines

---
  fs/f2fs/gc.c | 5 +++++

  1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode *inode, 
 block_t bidx,
       struct node_info ni;
       struct folio *folio, *mfolio;
       block_t newaddr;
+    bool need_invalidate = true;
       int err = 0;
       bool lfs_mode = f2fs_lfs_mode(fio.sbi);

      int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c +0 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode *inode, 
 block_t bidx,
Quoted 5 lines

  put_out:
      f2fs_put_dnode(&dn);
  out:
+    if (folio_test_uptodate(folio))
+        need_invalidate = false;

How about dropping such folio under its lock?

Quoted 3 lines

if (!folio_test_uptodate())
    truncate_inode_partial_folio()

truncate_inode_partial_folio() is more efficient since it avoids looking up the folio again, but it’s declared in mm/internal.h, so it cannot be called directly.

Yongpeng,

Quoted 8 lines
Quoted 5 lines

      f2fs_folio_put(folio, true);
+    if (need_invalidate)
+        invalidate_mapping_pages(mapping, bidx, bidx); return err;
  }

Quoted 4 lines

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

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

#3 lore raw
Quoted 44 lines · Yongpeng Yang
Quoted 10 lines · On 11/8/25 11:11, Chao Yu via Linux-f2fs-devel wrote:

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Yes, move_data_block() doesn’t read any data to folio, and the GC usually selects cold data. Therefore, this folio is typically not uptodate, and there’s no need for it to occupy the page cache.

Quoted 28 lines
Quoted 20 lines

---
  fs/f2fs/gc.c | 5 +++++

  1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
       struct node_info ni;
       struct folio *folio, *mfolio;
       block_t newaddr;
+    bool need_invalidate = true;
       int err = 0;
       bool lfs_mode = f2fs_lfs_mode(fio.sbi);

      int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c +0 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode *inode, block_t bidx,
Quoted 5 lines

  put_out:
      f2fs_put_dnode(&dn);
  out:
+    if (folio_test_uptodate(folio))
+        need_invalidate = false;

How about dropping such folio under its lock?

Quoted 7 lines
Quoted 3 lines

if (!folio_test_uptodate())
     truncate_inode_partial_folio()

truncate_inode_partial_folio() is more efficient since it avoids looking up the folio again, but it’s declared in mm/internal.h, so it cannot be called directly.

Yeah, or generic_error_remove_folio(), not sure.

I just take a look to check whether there is a better alternative scheme.

Thanks,

Quoted 16 lines

Yongpeng,

Quoted 12 lines
Quoted 5 lines

      f2fs_folio_put(folio, true);
+    if (need_invalidate)
+        invalidate_mapping_pages(mapping, bidx, bidx); return err;
  }

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

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

#4 lore raw
Quoted 49 lines · On 11/10/25 17:32, Chao Yu via Linux-f2fs-devel wrote:
Quoted 48 lines · Yongpeng Yang
Quoted 10 lines · On 11/8/25 11:11, Chao Yu via Linux-f2fs-devel wrote:

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Yes, move_data_block() doesn’t read any data to folio, and the GC usually selects cold data. Therefore, this folio is typically not uptodate, and there’s no need for it to occupy the page cache.

Quoted 31 lines
Quoted 20 lines

---
  fs/f2fs/gc.c | 5 +++++

  1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
       struct node_info ni;
       struct folio *folio, *mfolio;
       block_t newaddr;
+    bool need_invalidate = true;
       int err = 0;
       bool lfs_mode = f2fs_lfs_mode(fio.sbi);

      int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c +0 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode *inode, block_t bidx,
Quoted 5 lines

  put_out:
      f2fs_put_dnode(&dn);
  out:
+    if (folio_test_uptodate(folio))
+        need_invalidate = false;

How about dropping such folio under its lock?

if (!folio_test_uptodate())
     truncate_inode_partial_folio()

Quoted 7 lines
Quoted 3 lines

truncate_inode_partial_folio() is more efficient since it avoids looking up the folio again, but it’s declared in mm/internal.h, so it cannot be called directly.

Yeah, or generic_error_remove_folio(), not sure.

I just take a look to check whether there is a better alternative scheme.

How about the following modification? The folio is marked with PG_dropbehind using __folio_set_dropbehind(), and is subsequently removed from the page cache through folio_end_dropbehind().

Thanks,
Yongpeng

fs/f2fs/gc.c +0 -0
@@ -1326,6 +1326,7 @@ static int move_data_block(struct inode *inode,

block_t bidx,

        folio = f2fs_grab_cache_folio(mapping, bidx, false);
        if (IS_ERR(folio))
                return PTR_ERR(folio);

+ __folio_set_dropbehind(folio);

        if (!check_valid_map(F2FS_I_SB(inode), segno, off)) {
                err = -ENOENT;
@@ -1453,7 +1454,10 @@ static int move_data_block(struct inode *inode,
block_t bidx,
 put_out:
        f2fs_put_dnode(&dn);
 out:
-       f2fs_folio_put(folio, true);
+       folio_unlock(folio);
+       folio_end_dropbehind(folio);
+       folio_put(folio);
        return err;

}

Quoted 22 lines

Thanks,

Quoted 16 lines

Yongpeng,

Quoted 12 lines
Quoted 5 lines

      f2fs_folio_put(folio, true);
+    if (need_invalidate)
+        invalidate_mapping_pages(mapping, bidx, bidx); return err;
  }

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

Quoted 4 lines

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

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

#5 lore raw
Quoted 78 lines · Yongpeng Yang
Quoted 49 lines · On 11/10/25 17:32, Chao Yu via Linux-f2fs-devel wrote:
Quoted 48 lines · Yongpeng Yang
Quoted 10 lines · On 11/8/25 11:11, Chao Yu via Linux-f2fs-devel wrote:

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Yes, move_data_block() doesn’t read any data to folio, and the GC usually selects cold data. Therefore, this folio is typically not uptodate, and there’s no need for it to occupy the page cache.

Quoted 31 lines
Quoted 20 lines
---
   fs/f2fs/gc.c | 5 +++++
   1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
       struct node_info ni;
       struct folio *folio, *mfolio;
       block_t newaddr;
+    bool need_invalidate = true;
       int err = 0;
       bool lfs_mode = f2fs_lfs_mode(fio.sbi);
       int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c static int move_data_block(struct inode *inode, block_t bidx, · line 1455

Quoted 5 lines
fs/f2fs/gc.c +2 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode *inode, block_t bidx,
   put_out:
       f2fs_put_dnode(&dn);
   out:
+    if (folio_test_uptodate(folio))
+        need_invalidate = false;

How about dropping such folio under its lock?

if (!folio_test_uptodate())
     truncate_inode_partial_folio()

Quoted 7 lines
Quoted 3 lines

truncate_inode_partial_folio() is more efficient since it avoids looking up the folio again, but it’s declared in mm/internal.h, so it cannot be called directly.

Yeah, or generic_error_remove_folio(), not sure.

I just take a look to check whether there is a better alternative scheme.

How about the following modification? The folio is marked with PG_dropbehind using __folio_set_dropbehind(), and is subsequently removed from the page cache through folio_end_dropbehind().

Thanks,
Yongpeng

fs/f2fs/gc.c +1 -0
@@ -1326,6 +1326,7 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
         folio = f2fs_grab_cache_folio(mapping, bidx, false);
         if (IS_ERR(folio))
                 return PTR_ERR(folio);
+       __folio_set_dropbehind(folio);
 
         if (!check_valid_map(F2FS_I_SB(inode), segno, off)) {
                 err = -ENOENT;

fs/f2fs/gc.c static int move_data_block(struct inode *inode, · line 1460

Quoted 8 lines
fs/f2fs/gc.c +3 -1
@@ -1453,7 +1454,10 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
  put_out:
         f2fs_put_dnode(&dn);
  out:
-       f2fs_folio_put(folio, true);
+       folio_unlock(folio);
+       folio_end_dropbehind(folio);
+       folio_put(folio);

Maybe:

out:
if (!folio_test_uptodate)
folio_set_dropbehind
folio_unlock
folio_end_dropbehind folio_test_clear_dropbehind // make sure to clear the flag folio_put

Thanks,

Quoted 25 lines
fs/f2fs/gc.c +0 -0
         return err;
  }
Quoted 23 lines

Thanks,

Quoted 16 lines

Yongpeng,

Quoted 12 lines

fs/f2fs/gc.c static int move_data_block(struct inode *inode, block_t bidx, · line 1460

Quoted 5 lines
fs/f2fs/gc.c +2 -0
       f2fs_folio_put(folio, true);
+    if (need_invalidate)
+        invalidate_mapping_pages(mapping, bidx, bidx);
       return err;
   }

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

Quoted 5 lines
Quoted 4 lines

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

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

#6 lore raw
Quoted 94 lines · On 12/26/25 11:07, Chao Yu via Linux-f2fs-devel wrote:
Quoted 83 lines · Yongpeng Yang
Quoted 56 lines · On 11/10/25 17:32, Chao Yu via Linux-f2fs-devel wrote:
Quoted 46 lines · Yongpeng Yang
Quoted 10 lines · On 11/8/25 11:11, Chao Yu via Linux-f2fs-devel wrote:

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Yes, move_data_block() doesn’t read any data to folio, and the GC usually selects cold data. Therefore, this folio is typically not uptodate, and there’s no need for it to occupy the page cache.

Quoted 30 lines
Quoted 22 lines

---
   fs/f2fs/gc.c | 5 +++++

   1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode
 *inode, block_t bidx,
        struct node_info ni;
        struct folio *folio, *mfolio;
        block_t newaddr;
+    bool need_invalidate = true;
        int err = 0;
        bool lfs_mode = f2fs_lfs_mode(fio.sbi);

       int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c +0 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode
 *inode, block_t bidx,
Quoted 5 lines

   put_out:
       f2fs_put_dnode(&dn);
   out:
+    if (folio_test_uptodate(folio))
+        need_invalidate = false;

How about dropping such folio under its lock?

Quoted 8 lines
Quoted 3 lines

if (!folio_test_uptodate())
      truncate_inode_partial_folio()

truncate_inode_partial_folio() is more efficient since it avoids looking
up the folio again, but it’s declared in mm/internal.h, so it cannot be called directly.

Quoted 4 lines

Yeah, or generic_error_remove_folio(), not sure.

I just take a look to check whether there is a better alternative scheme.

How about the following modification? The folio is marked with PG_dropbehind using __folio_set_dropbehind(), and is subsequently removed from the page cache through folio_end_dropbehind().

Thanks,
Yongpeng

fs/f2fs/gc.c +1 -0
@@ -1326,6 +1326,7 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
          folio = f2fs_grab_cache_folio(mapping, bidx, false);
          if (IS_ERR(folio))
                  return PTR_ERR(folio);
+       __folio_set_dropbehind(folio);
 
          if (!check_valid_map(F2FS_I_SB(inode), segno, off)) {

                 err = -ENOENT;

fs/f2fs/gc.c +0 -0
@@ -1453,7 +1454,10 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
Quoted 7 lines

  put_out:
         f2fs_put_dnode(&dn);
  out:
-       f2fs_folio_put(folio, true);
+       folio_unlock(folio);
+       folio_end_dropbehind(folio);
+       folio_put(folio);

Maybe:

Quoted 6 lines

out:
    if (!folio_test_uptodate)
        folio_set_dropbehind
    folio_unlock
    folio_end_dropbehind
    folio_test_clear_dropbehind // make sure to clear the flag

Oh, I miss this, folio_end_dropbehind->folio_trylock may fail. I'll fix this and send v2 patch.

Thanks
Yongpeng,

Quoted 37 lines

    folio_put

Thanks,

Quoted 30 lines

         return err;
  }

Quoted 26 lines

Thanks,

Quoted 16 lines

Yongpeng,

Quoted 12 lines
Quoted 5 lines

       f2fs_folio_put(folio, true);
+    if (need_invalidate)
+        invalidate_mapping_pages(mapping, bidx, bidx); return err;
   }

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

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

Quoted 4 lines

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

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

#7 lore raw
Quoted 95 lines · Yongpeng Yang
Quoted 94 lines · On 12/26/25 11:07, Chao Yu via Linux-f2fs-devel wrote:
Quoted 82 lines · Yongpeng Yang
Quoted 56 lines · On 11/10/25 17:32, Chao Yu via Linux-f2fs-devel wrote:
Quoted 46 lines · Yongpeng Yang
Quoted 10 lines · On 11/8/25 11:11, Chao Yu via Linux-f2fs-devel wrote:

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Yes, move_data_block() doesn’t read any data to folio, and the GC usually selects cold data. Therefore, this folio is typically not uptodate, and there’s no need for it to occupy the page cache.

Quoted 30 lines
Quoted 21 lines
---
    fs/f2fs/gc.c | 5 +++++
    1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode
 *inode, block_t bidx,
        struct node_info ni;
        struct folio *folio, *mfolio;
        block_t newaddr;
+    bool need_invalidate = true;
        int err = 0;
        bool lfs_mode = f2fs_lfs_mode(fio.sbi);

       int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c static int move_data_block(struct inode · line 1456

Quoted 6 lines
fs/f2fs/gc.c +2 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode
 *inode, block_t bidx,
    put_out:
        f2fs_put_dnode(&dn);
    out:
+    if (folio_test_uptodate(folio))
+        need_invalidate = false;

How about dropping such folio under its lock?

Quoted 8 lines
Quoted 3 lines

if (!folio_test_uptodate())
      truncate_inode_partial_folio()

truncate_inode_partial_folio() is more efficient since it avoids looking
up the folio again, but it’s declared in mm/internal.h, so it cannot be called directly.

Quoted 4 lines

Yeah, or generic_error_remove_folio(), not sure.

I just take a look to check whether there is a better alternative scheme.

How about the following modification? The folio is marked with PG_dropbehind using __folio_set_dropbehind(), and is subsequently removed from the page cache through folio_end_dropbehind().

Thanks,
Yongpeng

fs/f2fs/gc.c +1 -0
@@ -1326,6 +1326,7 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
          folio = f2fs_grab_cache_folio(mapping, bidx, false);
          if (IS_ERR(folio))
                  return PTR_ERR(folio);
+       __folio_set_dropbehind(folio);
 
          if (!check_valid_map(F2FS_I_SB(inode), segno, off)) {

                 err = -ENOENT;

fs/f2fs/gc.c static int move_data_block(struct inode *inode, · line 1460

Quoted 8 lines
fs/f2fs/gc.c +3 -1
@@ -1453,7 +1454,10 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
   put_out:
          f2fs_put_dnode(&dn);
   out:
-       f2fs_folio_put(folio, true);
+       folio_unlock(folio);
+       folio_end_dropbehind(folio);
+       folio_put(folio);

Maybe:

Quoted 6 lines
Quoted 6 lines

out:
    if (!folio_test_uptodate)
        folio_set_dropbehind
    folio_unlock
    folio_end_dropbehind
    folio_test_clear_dropbehind // make sure to clear the flag

Oh, btw, folio_test_clear_dropbehind() should be covered w/ folio lock.

Quoted 49 lines

Oh, I miss this, folio_end_dropbehind->folio_trylock may fail. I'll fix this and send v2 patch.

Thanks
Yongpeng,

Quoted 41 lines

    folio_put

Thanks,

Quoted 25 lines
fs/f2fs/gc.c +0 -0
          return err;
   }
Quoted 23 lines

Thanks,

Quoted 16 lines

Yongpeng,

Quoted 12 lines

fs/f2fs/gc.c static int move_data_block(struct inode · line 1461

Quoted 5 lines
fs/f2fs/gc.c +2 -0
        f2fs_folio_put(folio, true);
+    if (need_invalidate)
+        invalidate_mapping_pages(mapping, bidx, bidx);
        return err;
    }

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

Quoted 5 lines
Quoted 4 lines

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

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

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

#8 lore raw
Quoted 96 lines · On 12/27/25 9:24 AM, Chao Yu via Linux-f2fs-devel wrote:
Quoted 95 lines · Yongpeng Yang
Quoted 94 lines · On 12/26/25 11:07, Chao Yu via Linux-f2fs-devel wrote:
Quoted 83 lines · Yongpeng Yang
Quoted 56 lines · On 11/10/25 17:32, Chao Yu via Linux-f2fs-devel wrote:
Quoted 46 lines · Yongpeng Yang
Quoted 10 lines · On 11/8/25 11:11, Chao Yu via Linux-f2fs-devel wrote:

Yunlei,

Quoted 4 lines · Yunlei He

From: Yunlei He <[email protected]>

GC move fbe data block will add some non uptodate page, we'd better release it at the end.

This is just for saving memory, right?

Yes, move_data_block() doesn’t read any data to folio, and the GC usually selects cold data. Therefore, this folio is typically not uptodate, and there’s no need for it to occupy the page cache.

Quoted 30 lines
Quoted 22 lines

---
    fs/f2fs/gc.c | 5 +++++

    1 file changed, 5 insertions(+)
fs/f2fs/gc.c +1 -0
index 8abf521530ff..09b65e6ea853 100644
@@ -1315,6 +1315,7 @@ static int move_data_block(struct inode
 *inode, block_t bidx,
         struct node_info ni;
         struct folio *folio, *mfolio;
         block_t newaddr;
+    bool need_invalidate = true;
         int err = 0;
         bool lfs_mode = f2fs_lfs_mode(fio.sbi);

        int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) &&

fs/f2fs/gc.c +0 -0
@@ -1450,7 +1451,11 @@ static int move_data_block(struct inode
 *inode, block_t bidx,
Quoted 5 lines

    put_out:
        f2fs_put_dnode(&dn);
    out:
+    if (folio_test_uptodate(folio))
+        need_invalidate = false;

How about dropping such folio under its lock?

Quoted 8 lines
Quoted 3 lines

if (!folio_test_uptodate())
       truncate_inode_partial_folio()

truncate_inode_partial_folio() is more efficient since it avoids looking
up the folio again, but it’s declared in mm/internal.h, so it cannot be called directly.

Quoted 4 lines

Yeah, or generic_error_remove_folio(), not sure.

I just take a look to check whether there is a better alternative scheme.

How about the following modification? The folio is marked with PG_dropbehind using __folio_set_dropbehind(), and is subsequently removed from the page cache through folio_end_dropbehind().

Thanks,
Yongpeng

fs/f2fs/gc.c +1 -0
@@ -1326,6 +1326,7 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
           folio = f2fs_grab_cache_folio(mapping, bidx, false);
           if (IS_ERR(folio))
                   return PTR_ERR(folio);
+       __folio_set_dropbehind(folio);
 
           if (!check_valid_map(F2FS_I_SB(inode), segno, off)) {

                  err = -ENOENT;

fs/f2fs/gc.c +0 -0
@@ -1453,7 +1454,10 @@ static int move_data_block(struct inode *inode,
 block_t bidx,
Quoted 7 lines

   put_out:
          f2fs_put_dnode(&dn);
   out:
-       f2fs_folio_put(folio, true);
+       folio_unlock(folio);
+       folio_end_dropbehind(folio);
+       folio_put(folio);

Maybe:

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

out:
     if (!folio_test_uptodate)
         folio_set_dropbehind
     folio_unlock
     folio_end_dropbehind
     folio_test_clear_dropbehind // make sure to clear the flag

Oh, btw, folio_test_clear_dropbehind() should be covered w/ folio lock.

Yes, I overlooked it. __filemap_get_folio_mpol will clear PG_dropbehind flag when fgp_flags /wo FGP_DONTCACHE flag. So, we don't need to clear it in move_data_block. I'll drop this in v3 patch.

Thanks
Yongpeng,

Quoted 52 lines
Quoted 49 lines

Oh, I miss this, folio_end_dropbehind->folio_trylock may fail. I'll fix this and send v2 patch.

Thanks
Yongpeng,

Quoted 41 lines

     folio_put

Thanks,

Quoted 30 lines

          return err;
   }

Quoted 26 lines

Thanks,

Quoted 16 lines

Yongpeng,

Quoted 12 lines
Quoted 5 lines

        f2fs_folio_put(folio, true);
+    if (need_invalidate)
+        invalidate_mapping_pages(mapping, bidx, bidx); return err;
    }

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

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

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

Quoted 4 lines

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

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