linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: support cold file defragementation
       [not found] <CGME20210512090930epcms2p2227112d22c961ca129462861108c03b6@epcms2p2>
@ 2021-05-12  9:09 ` Daejun Park
  0 siblings, 0 replies; only message in thread
From: Daejun Park @ 2021-05-12  9:09 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-kernel, linux-f2fs-devel, Daejun Park

F2FS_IOC_DEFRAGMENT performs defragmentation of a file. In
f2fs_defragment_range(), it checks whether in-place update policy is
applied, for avoiding unnecessary write operations.
The cold file may be fragmented according to the write order. However,
in the case of a cold file, the in-place update policy is applied, so it
is can not be defragmented.
This patch temporarily clears the cold bit so that the file can be
defragmented.

Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
 fs/f2fs/file.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index ceb575f99048..c38e9727ce25 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2536,11 +2536,23 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
 	unsigned int total = 0, sec_num;
 	block_t blk_end = 0;
 	bool fragmented = false;
+	bool is_cold = file_is_cold(inode);
 	int err;
 
+	/*
+	 * Cold file can be fragmented by write order. So we clear cold bit from
+	 * the file temporarily.
+	 */
+	if (is_cold)
+		file_clear_cold(inode);
+
 	/* if in-place-update policy is enabled, don't waste time here */
-	if (f2fs_should_update_inplace(inode, NULL))
+	if (f2fs_should_update_inplace(inode, NULL)) {
+		/* restore file temperature */
+		if (is_cold)
+			file_set_cold(inode);
 		return -EINVAL;
+	}
 
 	pg_start = range->start >> PAGE_SHIFT;
 	pg_end = (range->start + range->len) >> PAGE_SHIFT;
@@ -2665,6 +2677,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
 	clear_inode_flag(inode, FI_DO_DEFRAG);
 out:
 	inode_unlock(inode);
+	/* restore file temperature */
+	if (is_cold)
+		file_set_cold(inode);
 	if (!err)
 		range->len = (u64)total << PAGE_SHIFT;
 	return err;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-12  9:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210512090930epcms2p2227112d22c961ca129462861108c03b6@epcms2p2>
2021-05-12  9:09 ` [PATCH] f2fs: support cold file defragementation Daejun Park

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).