f2fs: compress: fix to avoid fragment w/ OPU during f2fs_ioc_compress_file()
authorChao Yu <chao@kernel.org>
Mon, 4 Sep 2023 15:12:42 +0000 (23:12 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 12 Sep 2023 20:49:34 +0000 (13:49 -0700)
If file has both cold and compress flag, during f2fs_ioc_compress_file(),
f2fs will trigger IPU for non-compress cluster and OPU for compress
cluster, so that, data of the file may be fragmented.

Fix it by always triggering OPU for IOs from user mode compression.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c

index cd9cedc35d7ff87b4f2f01776ef30b6593fc1c6c..96342aba8022fda5efc086363994c92f33d4bd1a 100644 (file)
@@ -2665,6 +2665,11 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)
                return true;
        if (f2fs_is_atomic_file(inode))
                return true;
+       /* rewrite low ratio compress data w/ OPU mode to avoid fragmentation */
+       if (f2fs_compressed_file(inode) &&
+               F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER &&
+               is_inode_flag_set(inode, FI_ENABLE_COMPRESS))
+               return true;
 
        /* swap file is migrating in aligned write mode */
        if (is_inode_flag_set(inode, FI_ALIGNED_WRITE))