linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs:reclaim truncated space during the recovery process
@ 2025-08-01  2:45 Wang Xiaojun via Linux-f2fs-devel
  2025-08-06  6:57 ` Chao Yu via Linux-f2fs-devel
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Xiaojun via Linux-f2fs-devel @ 2025-08-01  2:45 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel

In the following scenarios, F2FS cannot reclaim truncated space.

case 1: 
write file A, size is 1G | CP | truncate A to 1M | fsync A | SPO

case 2: 
CP | write file A, size is 1G | fsync A | truncate A to 1M | fsync A |SPO

During the recovery process, F2FS will recover file A,
but the 1-1G space cannot be reclaimed.

Signed-off-by: Wang Xiaojun <wangxiaojun@vivo.com>
---
 fs/f2fs/f2fs.h     |  1 +
 fs/f2fs/recovery.c | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 46be7560548c..d37204567b66 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -459,6 +459,7 @@ struct fsync_inode_entry {
 	struct inode *inode;	/* vfs inode pointer */
 	block_t blkaddr;	/* block address locating the last fsync */
 	block_t last_dentry;	/* block address locating the last dentry */
+	loff_t old_max_size;	/* old max file size for truncate */
 };
 
 #define nats_in_cursum(jnl)		(le16_to_cpu((jnl)->n_nats))
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 4cb3a91801b4..2f482742857c 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -95,6 +95,7 @@ static struct fsync_inode_entry *add_fsync_inode(struct f2fs_sb_info *sbi,
 	entry = f2fs_kmem_cache_alloc(fsync_entry_slab,
 					GFP_F2FS_ZERO, true, NULL);
 	entry->inode = inode;
+	entry->old_max_size = i_size_read(inode);
 	list_add_tail(&entry->list, head);
 
 	return entry;
@@ -828,6 +829,8 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
 				break;
 			}
 			recovered_inode++;
+			if (entry->old_max_size < i_size_read(entry->inode))
+				entry->old_max_size = i_size_read(entry->inode);
 		}
 		if (entry->last_dentry == blkaddr) {
 			err = recover_dentry(entry->inode, folio, dir_list);
@@ -844,8 +847,18 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
 		}
 		recovered_dnode++;
 
-		if (entry->blkaddr == blkaddr)
+		if (entry->blkaddr == blkaddr) {
+			if (entry->old_max_size > i_size_read(entry->inode)) {
+				err = f2fs_truncate_blocks(entry->inode,
+					i_size_read(entry->inode), false);
+				if (err) {
+					f2fs_folio_put(folio, true);
+					break;
+				}
+				f2fs_mark_inode_dirty_sync(entry->inode, true);
+			}
 			list_move_tail(&entry->list, tmp_inode_list);
+		}
 next:
 		ra_blocks = adjust_por_ra_blocks(sbi, ra_blocks, blkaddr,
 					next_blkaddr_of_node(folio));
-- 
2.34.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs:reclaim truncated space during the recovery process
  2025-08-01  2:45 [f2fs-dev] [PATCH] f2fs:reclaim truncated space during the recovery process Wang Xiaojun via Linux-f2fs-devel
@ 2025-08-06  6:57 ` Chao Yu via Linux-f2fs-devel
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-08-06  6:57 UTC (permalink / raw)
  To: Wang Xiaojun, jaegeuk; +Cc: linux-f2fs-devel

On 8/1/25 10:45, Wang Xiaojun wrote:
> In the following scenarios, F2FS cannot reclaim truncated space.
> 
> case 1: 
> write file A, size is 1G | CP | truncate A to 1M | fsync A | SPO
> 
> case 2: 
> CP | write file A, size is 1G | fsync A | truncate A to 1M | fsync A |SPO
> 
> During the recovery process, F2FS will recover file A,
> but the 1-1G space cannot be reclaimed.
> 
> Signed-off-by: Wang Xiaojun <wangxiaojun@vivo.com>

Xiaojun,

Can you please add a fixes line?

> ---
>  fs/f2fs/f2fs.h     |  1 +
>  fs/f2fs/recovery.c | 15 ++++++++++++++-
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 46be7560548c..d37204567b66 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -459,6 +459,7 @@ struct fsync_inode_entry {
>  	struct inode *inode;	/* vfs inode pointer */
>  	block_t blkaddr;	/* block address locating the last fsync */
>  	block_t last_dentry;	/* block address locating the last dentry */
> +	loff_t old_max_size;	/* old max file size for truncate */

Nitpick,

How about max_i_size?

>  };
>  
>  #define nats_in_cursum(jnl)		(le16_to_cpu((jnl)->n_nats))
> diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
> index 4cb3a91801b4..2f482742857c 100644
> --- a/fs/f2fs/recovery.c
> +++ b/fs/f2fs/recovery.c
> @@ -95,6 +95,7 @@ static struct fsync_inode_entry *add_fsync_inode(struct f2fs_sb_info *sbi,
>  	entry = f2fs_kmem_cache_alloc(fsync_entry_slab,
>  					GFP_F2FS_ZERO, true, NULL);
>  	entry->inode = inode;
> +	entry->old_max_size = i_size_read(inode);
>  	list_add_tail(&entry->list, head);
>  
>  	return entry;
> @@ -828,6 +829,8 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
>  				break;
>  			}
>  			recovered_inode++;
> +			if (entry->old_max_size < i_size_read(entry->inode))
> +				entry->old_max_size = i_size_read(entry->inode);

loff_t i_size = i_size_read(entry->inode);

if (entry->max_i_size < i_size)
	entry->max_i_size = i_size;

>  		}
>  		if (entry->last_dentry == blkaddr) {
>  			err = recover_dentry(entry->inode, folio, dir_list);
> @@ -844,8 +847,18 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
>  		}
>  		recovered_dnode++;
>  
> -		if (entry->blkaddr == blkaddr)
> +		if (entry->blkaddr == blkaddr) {
> +			if (entry->old_max_size > i_size_read(entry->inode)) {
> +				err = f2fs_truncate_blocks(entry->inode,
> +					i_size_read(entry->inode), false);

Ditto,

Thanks,

> +				if (err) {
> +					f2fs_folio_put(folio, true);
> +					break;
> +				}
> +				f2fs_mark_inode_dirty_sync(entry->inode, true);
> +			}
>  			list_move_tail(&entry->list, tmp_inode_list);
> +		}
>  next:
>  		ra_blocks = adjust_por_ra_blocks(sbi, ra_blocks, blkaddr,
>  					next_blkaddr_of_node(folio));



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-06  6:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-01  2:45 [f2fs-dev] [PATCH] f2fs:reclaim truncated space during the recovery process Wang Xiaojun via Linux-f2fs-devel
2025-08-06  6:57 ` Chao Yu via Linux-f2fs-devel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).