aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaeho Jeong2020-11-30 22:08:02 -0600
committerJaegeuk Kim2020-12-21 15:33:16 -0600
commitf15a200ae8b7bbda6c6ff082994c27d0e71c24a3 (patch)
tree7b268c8fb04d08c895c90132574dbbc02f92c50c
parent516758ca20d4f07fb7a44d1d94c48c9f91056961 (diff)
downloadkernel-f15a200ae8b7bbda6c6ff082994c27d0e71c24a3.tar.gz
kernel-f15a200ae8b7bbda6c6ff082994c27d0e71c24a3.tar.xz
kernel-f15a200ae8b7bbda6c6ff082994c27d0e71c24a3.zip
f2fs: add compress_mode mount option
We will add a new "compress_mode" mount option to control file compression mode. This supports "fs" and "user". In "fs" mode (default), f2fs does automatic compression on the compression enabled files. In "user" mode, f2fs disables the automaic compression and gives the user discretion of choosing the target file and the timing. It means the user can do manual compression/decompression on the compression enabled files using ioctls. Signed-off-by: Daeho Jeong <daehojeong@google.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--Documentation/filesystems/f2fs.rst35
-rw-r--r--fs/f2fs/compress.c2
-rw-r--r--fs/f2fs/data.c2
-rw-r--r--fs/f2fs/f2fs.h30
-rw-r--r--fs/f2fs/segment.c2
-rw-r--r--fs/f2fs/super.c23
6 files changed, 91 insertions, 3 deletions
diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst
index 985ae7d35066..dae15c96e659 100644
--- a/Documentation/filesystems/f2fs.rst
+++ b/Documentation/filesystems/f2fs.rst
@@ -261,6 +261,13 @@ compress_extension=%s Support adding specified extension, so that f2fs can enab
261 Note that, there is one reserved special extension '*', it 261 Note that, there is one reserved special extension '*', it
262 can be set to enable compression for all files. 262 can be set to enable compression for all files.
263compress_chksum Support verifying chksum of raw data in compressed cluster. 263compress_chksum Support verifying chksum of raw data in compressed cluster.
264compress_mode=%s Control file compression mode. This supports "fs" and "user"
265 modes. In "fs" mode (default), f2fs does automatic compression
266 on the compression enabled files. In "user" mode, f2fs disables
267 the automaic compression and gives the user discretion of
268 choosing the target file and the timing. The user can do manual
269 compression/decompression on the compression enabled files using
270 ioctls.
264inlinecrypt When possible, encrypt/decrypt the contents of encrypted 271inlinecrypt When possible, encrypt/decrypt the contents of encrypted
265 files using the blk-crypto framework rather than 272 files using the blk-crypto framework rather than
266 filesystem-layer encryption. This allows the use of 273 filesystem-layer encryption. This allows the use of
@@ -811,6 +818,34 @@ Compress metadata layout::
811 | data length | data chksum | reserved | compressed data | 818 | data length | data chksum | reserved | compressed data |
812 +-------------+-------------+----------+----------------------------+ 819 +-------------+-------------+----------+----------------------------+
813 820
821Compression mode
822--------------------------
823
824f2fs supports "fs" and "user" compression modes with "compression_mode" mount option.
825With this option, f2fs provides a choice to select the way how to compress the
826compression enabled files (refer to "Compression implementation" section for how to
827enable compression on a regular inode).
828
8291) compress_mode=fs
830This is the default option. f2fs does automatic compression in the writeback of the
831compression enabled files.
832
8332) compress_mode=user
834This disables the automaic compression and gives the user discretion of choosing the
835target file and the timing. The user can do manual compression/decompression on the
836compression enabled files using F2FS_IOC_DECOMPRESS_FILE and F2FS_IOC_COMPRESS_FILE
837ioctls like the below.
838
839To decompress a file,
840
841fd = open(filename, O_WRONLY, 0);
842ret = ioctl(fd, F2FS_IOC_DECOMPRESS_FILE);
843
844To compress a file,
845
846fd = open(filename, O_WRONLY, 0);
847ret = ioctl(fd, F2FS_IOC_COMPRESS_FILE);
848
814NVMe Zoned Namespace devices 849NVMe Zoned Namespace devices
815---------------------------- 850----------------------------
816 851
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 7ec1592a0973..d23bebb6ccd3 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -944,7 +944,7 @@ int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index)
944 944
945static bool cluster_may_compress(struct compress_ctx *cc) 945static bool cluster_may_compress(struct compress_ctx *cc)
946{ 946{
947 if (!f2fs_compressed_file(cc->inode)) 947 if (!f2fs_need_compress_data(cc->inode))
948 return false; 948 return false;
949 if (f2fs_is_atomic_file(cc->inode)) 949 if (f2fs_is_atomic_file(cc->inode))
950 return false; 950 return false;
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index bfe0d787c9e6..e85fd8f77f3f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3147,7 +3147,7 @@ static inline bool __should_serialize_io(struct inode *inode,
3147 if (IS_NOQUOTA(inode)) 3147 if (IS_NOQUOTA(inode))
3148 return false; 3148 return false;
3149 3149
3150 if (f2fs_compressed_file(inode)) 3150 if (f2fs_need_compress_data(inode))
3151 return true; 3151 return true;
3152 if (wbc->sync_mode != WB_SYNC_ALL) 3152 if (wbc->sync_mode != WB_SYNC_ALL)
3153 return true; 3153 return true;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 4417f791dbc6..7c02b6d8465c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -148,6 +148,7 @@ struct f2fs_mount_info {
148 unsigned char compress_log_size; /* cluster log size */ 148 unsigned char compress_log_size; /* cluster log size */
149 bool compress_chksum; /* compressed data chksum */ 149 bool compress_chksum; /* compressed data chksum */
150 unsigned char compress_ext_cnt; /* extension count */ 150 unsigned char compress_ext_cnt; /* extension count */
151 int compress_mode; /* compression mode */
151 unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 152 unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
152}; 153};
153 154
@@ -677,6 +678,7 @@ enum {
677 FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ 678 FI_COMPRESSED_FILE, /* indicate file's data can be compressed */
678 FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */ 679 FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */
679 FI_MMAP_FILE, /* indicate file was mmapped */ 680 FI_MMAP_FILE, /* indicate file was mmapped */
681 FI_ENABLE_COMPRESS, /* enable compression in "user" compression mode */
680 FI_MAX, /* max flag, never be used */ 682 FI_MAX, /* max flag, never be used */
681}; 683};
682 684
@@ -1244,6 +1246,18 @@ enum fsync_mode {
1244 FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ 1246 FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */
1245}; 1247};
1246 1248
1249enum {
1250 COMPR_MODE_FS, /*
1251 * automatically compress compression
1252 * enabled files
1253 */
1254 COMPR_MODE_USER, /*
1255 * automatical compression is disabled.
1256 * user can control the file compression
1257 * using ioctls
1258 */
1259};
1260
1247/* 1261/*
1248 * this value is set in page as a private data which indicate that 1262 * this value is set in page as a private data which indicate that
1249 * the page is atomically written, and it is in inmem_pages list. 1263 * the page is atomically written, and it is in inmem_pages list.
@@ -2759,6 +2773,22 @@ static inline int f2fs_compressed_file(struct inode *inode)
2759 is_inode_flag_set(inode, FI_COMPRESSED_FILE); 2773 is_inode_flag_set(inode, FI_COMPRESSED_FILE);
2760} 2774}
2761 2775
2776static inline bool f2fs_need_compress_data(struct inode *inode)
2777{
2778 int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode;
2779
2780 if (!f2fs_compressed_file(inode))
2781 return false;
2782
2783 if (compress_mode == COMPR_MODE_FS)
2784 return true;
2785 else if (compress_mode == COMPR_MODE_USER &&
2786 is_inode_flag_set(inode, FI_ENABLE_COMPRESS))
2787 return true;
2788
2789 return false;
2790}
2791
2762static inline unsigned int addrs_per_inode(struct inode *inode) 2792static inline unsigned int addrs_per_inode(struct inode *inode)
2763{ 2793{
2764 unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 2794 unsigned int addrs = CUR_ADDRS_PER_INODE(inode) -
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index bfc597037413..deca74cb17df 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3261,7 +3261,7 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
3261 else 3261 else
3262 return CURSEG_COLD_DATA; 3262 return CURSEG_COLD_DATA;
3263 } 3263 }
3264 if (file_is_cold(inode) || f2fs_compressed_file(inode)) 3264 if (file_is_cold(inode) || f2fs_need_compress_data(inode))
3265 return CURSEG_COLD_DATA; 3265 return CURSEG_COLD_DATA;
3266 if (file_is_hot(inode) || 3266 if (file_is_hot(inode) ||
3267 is_inode_flag_set(inode, FI_HOT_DATA) || 3267 is_inode_flag_set(inode, FI_HOT_DATA) ||
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 0ac4dbd6488a..c6a3365f4844 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -147,6 +147,7 @@ enum {
147 Opt_compress_log_size, 147 Opt_compress_log_size,
148 Opt_compress_extension, 148 Opt_compress_extension,
149 Opt_compress_chksum, 149 Opt_compress_chksum,
150 Opt_compress_mode,
150 Opt_atgc, 151 Opt_atgc,
151 Opt_err, 152 Opt_err,
152}; 153};
@@ -216,6 +217,7 @@ static match_table_t f2fs_tokens = {
216 {Opt_compress_log_size, "compress_log_size=%u"}, 217 {Opt_compress_log_size, "compress_log_size=%u"},
217 {Opt_compress_extension, "compress_extension=%s"}, 218 {Opt_compress_extension, "compress_extension=%s"},
218 {Opt_compress_chksum, "compress_chksum"}, 219 {Opt_compress_chksum, "compress_chksum"},
220 {Opt_compress_mode, "compress_mode=%s"},
219 {Opt_atgc, "atgc"}, 221 {Opt_atgc, "atgc"},
220 {Opt_err, NULL}, 222 {Opt_err, NULL},
221}; 223};
@@ -939,11 +941,26 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
939 case Opt_compress_chksum: 941 case Opt_compress_chksum:
940 F2FS_OPTION(sbi).compress_chksum = true; 942 F2FS_OPTION(sbi).compress_chksum = true;
941 break; 943 break;
944 case Opt_compress_mode:
945 name = match_strdup(&args[0]);
946 if (!name)
947 return -ENOMEM;
948 if (!strcmp(name, "fs")) {
949 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
950 } else if (!strcmp(name, "user")) {
951 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER;
952 } else {
953 kfree(name);
954 return -EINVAL;
955 }
956 kfree(name);
957 break;
942#else 958#else
943 case Opt_compress_algorithm: 959 case Opt_compress_algorithm:
944 case Opt_compress_log_size: 960 case Opt_compress_log_size:
945 case Opt_compress_extension: 961 case Opt_compress_extension:
946 case Opt_compress_chksum: 962 case Opt_compress_chksum:
963 case Opt_compress_mode:
947 f2fs_info(sbi, "compression options not supported"); 964 f2fs_info(sbi, "compression options not supported");
948 break; 965 break;
949#endif 966#endif
@@ -1532,6 +1549,11 @@ static inline void f2fs_show_compress_options(struct seq_file *seq,
1532 1549
1533 if (F2FS_OPTION(sbi).compress_chksum) 1550 if (F2FS_OPTION(sbi).compress_chksum)
1534 seq_puts(seq, ",compress_chksum"); 1551 seq_puts(seq, ",compress_chksum");
1552
1553 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS)
1554 seq_printf(seq, ",compress_mode=%s", "fs");
1555 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER)
1556 seq_printf(seq, ",compress_mode=%s", "user");
1535} 1557}
1536 1558
1537static int f2fs_show_options(struct seq_file *seq, struct dentry *root) 1559static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
@@ -1681,6 +1703,7 @@ static void default_options(struct f2fs_sb_info *sbi)
1681 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; 1703 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4;
1682 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; 1704 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
1683 F2FS_OPTION(sbi).compress_ext_cnt = 0; 1705 F2FS_OPTION(sbi).compress_ext_cnt = 0;
1706 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
1684 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; 1707 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
1685 1708
1686 sbi->sb->s_flags &= ~SB_INLINECRYPT; 1709 sbi->sb->s_flags &= ~SB_INLINECRYPT;