Skip to contentSkip to conversation

f2fs: compress: add nocompress extensions support

PATCH In review Fengnan Chang via Linux-f2fs-devel 4 participants 9 messages Jun 8, 2021 – Jul 3, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 f2fs: compress: add nocompress extensions support

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
* compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
* compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
 Documentation/filesystems/f2fs.rst | 31 +++++++++++-
 fs/f2fs/f2fs.h                     |  2 +
 fs/f2fs/namei.c                    | 18 +++++--
 fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
 4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +30 -1
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s	 Support adding specified extension, so that f2fs can enab
 			 For other files, we can still enable compression via ioctl.
 			 Note that, there is one reserved special extension '*', it
 			 can be set to enable compression for all files.
+nocompress_extension=%s	   Support adding specified extension, so that f2fs can disable
+			 compression on those corresponding files, just contrary to compression extension.
+			 If you know exactly which files cannot be compressed, you can use this.
+			 The same extension name can't appear in both compress and nocompress
+			 extension at the same time.
+			 If the compress extension specifies all files, the types specified by the
+			 nocompress extension will be treated as special cases and will not be compressed.
+			 Don't allow use '*' to specifie all file in nocompress extension.
+			 After add nocompress_extension, the priority should be:
+			 dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+			 See more in compression sections.
+
 compress_chksum		 Support verifying chksum of raw data in compressed cluster.
 compress_mode=%s	 Control file compression mode. This supports "fs" and "user"
 			 modes. In "fs" mode (default), f2fs does automatic compression
@@ -814,13 +826,30 @@ Compression implementation
   all logical blocks in cluster contain valid data and compress ratio of
   cluster data is lower than specified threshold.
 
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
 
   * chattr +c file
   * chattr +c dir; touch dir/file
   * mount w/ -o compress_extension=ext; touch file.ext
   * mount w/ -o compress_extension=*; touch any_file
 
+- To disable compression on regular inode, there are two ways:
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed.
+    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
 - At this point, compression feature doesn't expose compressed space to user
   directly in order to guarantee potential data updates later to the space.
   Instead, the main goal is to reduce data writes to flash disk as much as
fs/f2fs/f2fs.h +2 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
 	unsigned char compress_level;		/* compress level */
 	bool compress_chksum;			/* compressed data chksum */
 	unsigned char compress_ext_cnt;		/* extension count */
+	unsigned char nocompress_ext_cnt;		/* nocompress extension count */
 	int compress_mode;			/* compression mode */
 	unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];	/* extensions */
+	unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
 };
 
 #define F2FS_FEATURE_ENCRYPT		0x0001
fs/f2fs/namei.c +15 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
 						const unsigned char *name)
 {
 	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
+	unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions;
 	unsigned char (*ext)[F2FS_EXTENSION_LEN];
-	unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
 	int i, cold_count, hot_count;
 
 	if (!f2fs_sb_has_compression(sbi) ||
-			is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
 			F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-			!f2fs_may_compress(inode))
+			!f2fs_may_compress(inode) ||
+			(!ext_cnt && !noext_cnt))
 		return;
 
 	down_read(&sbi->sb_lock);
@@ -311,6 +313,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
 
 	up_read(&sbi->sb_lock);
 
+	for (i = 0; i < noext_cnt; i++) {
+		if (is_extension_exist(name, noext[i])) {
+			f2fs_disable_compressed_file(inode);
+			return;
+		}
+	}
+
+	if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+		return;
+
 	ext = F2FS_OPTION(sbi).extensions;
 
 	for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +78 -1

127 lines not on this page · raw message

Signature · 8 lines
2.29.0



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

Hi:
Any comments about this version?

Thanks.

Quoted 270 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
* compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
* compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
  Documentation/filesystems/f2fs.rst | 31 +++++++++++-
  fs/f2fs/f2fs.h                     |  2 +
  fs/f2fs/namei.c                    | 18 +++++--
  fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
  4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +30 -1
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s	 Support adding specified extension, so that f2fs can enab
  			 For other files, we can still enable compression via ioctl.
  			 Note that, there is one reserved special extension '*', it
  			 can be set to enable compression for all files.
+nocompress_extension=%s	   Support adding specified extension, so that f2fs can disable
+			 compression on those corresponding files, just contrary to compression extension.
+			 If you know exactly which files cannot be compressed, you can use this.
+			 The same extension name can't appear in both compress and nocompress
+			 extension at the same time.
+			 If the compress extension specifies all files, the types specified by the
+			 nocompress extension will be treated as special cases and will not be compressed.
+			 Don't allow use '*' to specifie all file in nocompress extension.
+			 After add nocompress_extension, the priority should be:
+			 dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+			 See more in compression sections.
+
  compress_chksum		 Support verifying chksum of raw data in compressed cluster.
  compress_mode=%s	 Control file compression mode. This supports "fs" and "user"
  			 modes. In "fs" mode (default), f2fs does automatic compression
@@ -814,13 +826,30 @@ Compression implementation
    all logical blocks in cluster contain valid data and compress ratio of
    cluster data is lower than specified threshold.
 
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
 
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
 
+- To disable compression on regular inode, there are two ways:
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed.
+    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space to user
    directly in order to guarantee potential data updates later to the space.
    Instead, the main goal is to reduce data writes to flash disk as much as
fs/f2fs/f2fs.h +2 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
  	unsigned char compress_level;		/* compress level */
  	bool compress_chksum;			/* compressed data chksum */
  	unsigned char compress_ext_cnt;		/* extension count */
+	unsigned char nocompress_ext_cnt;		/* nocompress extension count */
  	int compress_mode;			/* compression mode */
  	unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];	/* extensions */
+	unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
  };
 
  #define F2FS_FEATURE_ENCRYPT		0x0001
fs/f2fs/namei.c +15 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
  						const unsigned char *name)
  {
  	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
+	unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions;
  	unsigned char (*ext)[F2FS_EXTENSION_LEN];
-	unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
  	int i, cold_count, hot_count;
 
  	if (!f2fs_sb_has_compression(sbi) ||
-			is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
  			F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-			!f2fs_may_compress(inode))
+			!f2fs_may_compress(inode) ||
+			(!ext_cnt && !noext_cnt))
  		return;
 
  	down_read(&sbi->sb_lock);
@@ -311,6 +313,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
 
  	up_read(&sbi->sb_lock);
 
+	for (i = 0; i < noext_cnt; i++) {
+		if (is_extension_exist(name, noext[i])) {
+			f2fs_disable_compressed_file(inode);
+			return;
+		}
+	}
+
+	if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+		return;
+
  	ext = F2FS_OPTION(sbi).extensions;
 
  	for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +73 -1
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
  	Opt_compress_algorithm,
  	Opt_compress_log_size,
  	Opt_compress_extension,
+	Opt_nocompress_extension,
  	Opt_compress_chksum,
  	Opt_compress_mode,
  	Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
  	{Opt_compress_algorithm, "compress_algorithm=%s"},
  	{Opt_compress_log_size, "compress_log_size=%u"},
  	{Opt_compress_extension, "compress_extension=%s"},
+	{Opt_nocompress_extension, "nocompress_extension=%s"},
  	{Opt_compress_chksum, "compress_chksum"},
  	{Opt_compress_mode, "compress_mode=%s"},
  	{Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct super_block *sb,
  }
 
  #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+	unsigned char (*ext)[F2FS_EXTENSION_LEN];
+	unsigned char (*noext)[F2FS_EXTENSION_LEN];
+	int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+	ext = F2FS_OPTION(sbi).extensions;
+	ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	noext = F2FS_OPTION(sbi).noextensions;
+	noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+	if (!noext_cnt)
+		return 0;
+
+	for (no_index = 0; no_index < noext_cnt; no_index++) {
+		if (!strcasecmp("*", noext[no_index])) {
+			f2fs_info(sbi, "Don't allow the nocompress extension specifies all files");
+			return -EINVAL;
+		}
+		for (index = 0; index < ext_cnt; index++) {
+			if (!strcasecmp(ext[index], noext[no_index])) {
+				f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+						ext[index]);
+				return -EINVAL;
+			}
+		}
+	}
+	return 0;
+}
+
  #ifdef CONFIG_F2FS_FS_LZ4
  static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
  {
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	substring_t args[MAX_OPT_ARGS];
  #ifdef CONFIG_F2FS_FS_COMPRESSION
  	unsigned char (*ext)[F2FS_EXTENSION_LEN];
-	int ext_cnt;
+	unsigned char (*noext)[F2FS_EXTENSION_LEN];
+	int ext_cnt, noext_cnt;
  #endif
  	char *p, *name;
  	int arg = 0;
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  			F2FS_OPTION(sbi).compress_ext_cnt++;
  			kfree(name);
  			break;
+		case Opt_nocompress_extension:
+			if (!f2fs_sb_has_compression(sbi)) {
+				f2fs_info(sbi, "Image doesn't support compression");
+				break;
+			}
+			name = match_strdup(&args[0]);
+			if (!name)
+				return -ENOMEM;
+
+			noext = F2FS_OPTION(sbi).noextensions;
+			noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+			if (strlen(name) >= F2FS_EXTENSION_LEN ||
+				noext_cnt >= COMPRESS_EXT_NUM) {
+				f2fs_err(sbi,
+					"invalid extension length/number");
+				kfree(name);
+				return -EINVAL;
+			}
+
+			strcpy(noext[noext_cnt], name);
+			F2FS_OPTION(sbi).nocompress_ext_cnt++;
+			kfree(name);
+			break;
  		case Opt_compress_chksum:
  			F2FS_OPTION(sbi).compress_chksum = true;
  			break;
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  		case Opt_compress_algorithm:
  		case Opt_compress_log_size:
  		case Opt_compress_extension:
+		case Opt_nocompress_extension:
  		case Opt_compress_chksum:
  		case Opt_compress_mode:
  			f2fs_info(sbi, "compression options not supported");
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	}
  #endif
 
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+	if (f2fs_test_compress_extension(sbi)) {
+		f2fs_err(sbi, "invalid compress or nocompress extension");
+		return -EINVAL;
+	}
+#endif
+
  	if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
  		f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
  			 F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void f2fs_show_compress_options(struct seq_file *seq,
  			F2FS_OPTION(sbi).extensions[i]);

fs/f2fs/super.c static inline void f2fs_show_compress_options(struct seq_file *seq, · line 1753

Quoted 10 lines
fs/f2fs/super.c +5 -0
  	}
 
+	for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+		seq_printf(seq, ",nocompress_extension=%s",
+			F2FS_OPTION(sbi).noextensions[i]);
+	}
+
  	if (F2FS_OPTION(sbi).compress_chksum)
  		seq_puts(seq, ",compress_chksum");
 

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

#2 lore raw
In reply to Fengnan Chang via Linux-f2fs-devel

Hi chao & jaegeuk:
Any comments about this version?

Thanks.

Quoted 270 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
* compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
* compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
  Documentation/filesystems/f2fs.rst | 31 +++++++++++-
  fs/f2fs/f2fs.h                     |  2 +
  fs/f2fs/namei.c                    | 18 +++++--
  fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
  4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +30 -1
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s	 Support adding specified extension, so that f2fs can enab
  			 For other files, we can still enable compression via ioctl.
  			 Note that, there is one reserved special extension '*', it
  			 can be set to enable compression for all files.
+nocompress_extension=%s	   Support adding specified extension, so that f2fs can disable
+			 compression on those corresponding files, just contrary to compression extension.
+			 If you know exactly which files cannot be compressed, you can use this.
+			 The same extension name can't appear in both compress and nocompress
+			 extension at the same time.
+			 If the compress extension specifies all files, the types specified by the
+			 nocompress extension will be treated as special cases and will not be compressed.
+			 Don't allow use '*' to specifie all file in nocompress extension.
+			 After add nocompress_extension, the priority should be:
+			 dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+			 See more in compression sections.
+
  compress_chksum		 Support verifying chksum of raw data in compressed cluster.
  compress_mode=%s	 Control file compression mode. This supports "fs" and "user"
  			 modes. In "fs" mode (default), f2fs does automatic compression
@@ -814,13 +826,30 @@ Compression implementation
    all logical blocks in cluster contain valid data and compress ratio of
    cluster data is lower than specified threshold.
 
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
 
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
 
+- To disable compression on regular inode, there are two ways:
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed.
+    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space to user
    directly in order to guarantee potential data updates later to the space.
    Instead, the main goal is to reduce data writes to flash disk as much as
fs/f2fs/f2fs.h +2 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
  	unsigned char compress_level;		/* compress level */
  	bool compress_chksum;			/* compressed data chksum */
  	unsigned char compress_ext_cnt;		/* extension count */
+	unsigned char nocompress_ext_cnt;		/* nocompress extension count */
  	int compress_mode;			/* compression mode */
  	unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];	/* extensions */
+	unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
  };
 
  #define F2FS_FEATURE_ENCRYPT		0x0001
fs/f2fs/namei.c +15 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
  						const unsigned char *name)
  {
  	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
+	unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions;
  	unsigned char (*ext)[F2FS_EXTENSION_LEN];
-	unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
  	int i, cold_count, hot_count;
 
  	if (!f2fs_sb_has_compression(sbi) ||
-			is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
  			F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-			!f2fs_may_compress(inode))
+			!f2fs_may_compress(inode) ||
+			(!ext_cnt && !noext_cnt))
  		return;
 
  	down_read(&sbi->sb_lock);
@@ -311,6 +313,16 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
 
  	up_read(&sbi->sb_lock);
 
+	for (i = 0; i < noext_cnt; i++) {
+		if (is_extension_exist(name, noext[i])) {
+			f2fs_disable_compressed_file(inode);
+			return;
+		}
+	}
+
+	if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+		return;
+
  	ext = F2FS_OPTION(sbi).extensions;
 
  	for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +73 -1
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
  	Opt_compress_algorithm,
  	Opt_compress_log_size,
  	Opt_compress_extension,
+	Opt_nocompress_extension,
  	Opt_compress_chksum,
  	Opt_compress_mode,
  	Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
  	{Opt_compress_algorithm, "compress_algorithm=%s"},
  	{Opt_compress_log_size, "compress_log_size=%u"},
  	{Opt_compress_extension, "compress_extension=%s"},
+	{Opt_nocompress_extension, "nocompress_extension=%s"},
  	{Opt_compress_chksum, "compress_chksum"},
  	{Opt_compress_mode, "compress_mode=%s"},
  	{Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct super_block *sb,
  }
 
  #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+	unsigned char (*ext)[F2FS_EXTENSION_LEN];
+	unsigned char (*noext)[F2FS_EXTENSION_LEN];
+	int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+	ext = F2FS_OPTION(sbi).extensions;
+	ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	noext = F2FS_OPTION(sbi).noextensions;
+	noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+	if (!noext_cnt)
+		return 0;
+
+	for (no_index = 0; no_index < noext_cnt; no_index++) {
+		if (!strcasecmp("*", noext[no_index])) {
+			f2fs_info(sbi, "Don't allow the nocompress extension specifies all files");
+			return -EINVAL;
+		}
+		for (index = 0; index < ext_cnt; index++) {
+			if (!strcasecmp(ext[index], noext[no_index])) {
+				f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+						ext[index]);
+				return -EINVAL;
+			}
+		}
+	}
+	return 0;
+}
+
  #ifdef CONFIG_F2FS_FS_LZ4
  static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
  {
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	substring_t args[MAX_OPT_ARGS];
  #ifdef CONFIG_F2FS_FS_COMPRESSION
  	unsigned char (*ext)[F2FS_EXTENSION_LEN];
-	int ext_cnt;
+	unsigned char (*noext)[F2FS_EXTENSION_LEN];
+	int ext_cnt, noext_cnt;
  #endif
  	char *p, *name;
  	int arg = 0;
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  			F2FS_OPTION(sbi).compress_ext_cnt++;
  			kfree(name);
  			break;
+		case Opt_nocompress_extension:
+			if (!f2fs_sb_has_compression(sbi)) {
+				f2fs_info(sbi, "Image doesn't support compression");
+				break;
+			}
+			name = match_strdup(&args[0]);
+			if (!name)
+				return -ENOMEM;
+
+			noext = F2FS_OPTION(sbi).noextensions;
+			noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+			if (strlen(name) >= F2FS_EXTENSION_LEN ||
+				noext_cnt >= COMPRESS_EXT_NUM) {
+				f2fs_err(sbi,
+					"invalid extension length/number");
+				kfree(name);
+				return -EINVAL;
+			}
+
+			strcpy(noext[noext_cnt], name);
+			F2FS_OPTION(sbi).nocompress_ext_cnt++;
+			kfree(name);
+			break;
  		case Opt_compress_chksum:
  			F2FS_OPTION(sbi).compress_chksum = true;
  			break;
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  		case Opt_compress_algorithm:
  		case Opt_compress_log_size:
  		case Opt_compress_extension:
+		case Opt_nocompress_extension:
  		case Opt_compress_chksum:
  		case Opt_compress_mode:
  			f2fs_info(sbi, "compression options not supported");
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
  	}
  #endif
 
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+	if (f2fs_test_compress_extension(sbi)) {
+		f2fs_err(sbi, "invalid compress or nocompress extension");
+		return -EINVAL;
+	}
+#endif
+
  	if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
  		f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
  			 F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void f2fs_show_compress_options(struct seq_file *seq,
  			F2FS_OPTION(sbi).extensions[i]);

fs/f2fs/super.c static inline void f2fs_show_compress_options(struct seq_file *seq, · line 1753

Quoted 10 lines
fs/f2fs/super.c +5 -0
  	}
 
+	for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+		seq_printf(seq, ",nocompress_extension=%s",
+			F2FS_OPTION(sbi).noextensions[i]);
+	}
+
  	if (F2FS_OPTION(sbi).compress_chksum)
  		seq_puts(seq, ",compress_chksum");
 

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

#3 lore raw

Hi chao & jaegeuk:
Any comments about this version? It's have been a while,are you not
agree with this patch? Pelase give me some feedback.

Thanks

Quoted 296 lines · Fengnan Chang

Hi chao & jaegeuk:
  Any comments about this version?

Thanks.

Quoted 290 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
    * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
    * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
  Documentation/filesystems/f2fs.rst | 31 +++++++++++- fs/f2fs/f2fs.h                     |  2 +
  fs/f2fs/namei.c                    | 18 +++++-- fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-

  4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +0 -0
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s     Support adding 

specified extension, so that f2fs can enab
               For other files, we can still enable compression via ioctl. Note that, there is one reserved special extension '*', it can be set to enable compression for all files. +nocompress_extension=%s       Support adding specified extension, so that f2fs can disable
+             compression on those corresponding files, just contrary to compression extension.
+             If you know exactly which files cannot be compressed,
you can use this.
+             The same extension name can't appear in both compress
and nocompress
+             extension at the same time.
+             If the compress extension specifies all files, the types specified by the
+             nocompress extension will be treated as special cases
and will not be compressed.
+             Don't allow use '*' to specifie all file in nocompress extension.
+             After add nocompress_extension, the priority should be:
+             dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+             See more in compression sections.
+
  compress_chksum         Support verifying chksum of raw data in compressed cluster. compress_mode=%s     Control file compression mode. This supports "fs" and "user" modes. In "fs" mode (default), f2fs does automatic compression

Documentation/filesystems/f2fs.rst +0 -0
@@ -814,13 +826,30 @@ Compression implementation

    all logical blocks in cluster contain valid data and compress ratio of cluster data is lower than specified threshold.
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
+- To disable compression on regular inode, there are two ways:

Documentation/filesystems/f2fs.rst +7 -0
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir; 

touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed.
+    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space to user directly in order to guarantee potential data updates later to the space. Instead, the main goal is to reduce data writes to flash disk as much as

fs/f2fs/f2fs.h +0 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {

      unsigned char compress_level;        /* compress level */
      bool compress_chksum;            /* compressed data chksum */ unsigned char compress_ext_cnt;        /* extension count */
+    unsigned char nocompress_ext_cnt;        /* nocompress extension
count */
      int compress_mode;            /* compression mode */
      unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];    /* extensions */ +    unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];
/* extensions */
  };
  #define F2FS_FEATURE_ENCRYPT        0x0001

fs/f2fs/namei.c +3 -1
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct 
 f2fs_sb_info *sbi, struct inode *inode,
                           const unsigned char *name)
   {
       __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN] = 
 F2FS_OPTION(sbi).noextensions;
       unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
       int i, cold_count, hot_count;

      if (!f2fs_sb_has_compression(sbi) ||
-            is_inode_flag_set(inode, FI_COMPRESSED_FILE) || F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL || -            !f2fs_may_compress(inode))
+            !f2fs_may_compress(inode) ||
+            (!ext_cnt && !noext_cnt))
          return;
      down_read(&sbi->sb_lock);

fs/f2fs/namei.c +10 -0
@@ -311,6 +313,16 @@ static void set_compress_inode(struct 
 f2fs_sb_info *sbi, struct inode *inode,
       up_read(&sbi->sb_lock);
+    for (i = 0; i < noext_cnt; i++) {
+        if (is_extension_exist(name, noext[i])) {
+            f2fs_disable_compressed_file(inode);
+            return;
+        }
+    }
+
+    if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+        return;
+
       ext = F2FS_OPTION(sbi).extensions;
       for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +4 -0
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
       Opt_compress_algorithm,
       Opt_compress_log_size,
       Opt_compress_extension,
+    Opt_nocompress_extension,
       Opt_compress_chksum,
       Opt_compress_mode,
       Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
       {Opt_compress_algorithm, "compress_algorithm=%s"},
       {Opt_compress_log_size, "compress_log_size=%u"},
       {Opt_compress_extension, "compress_extension=%s"},
+    {Opt_nocompress_extension, "nocompress_extension=%s"},
       {Opt_compress_chksum, "compress_chksum"},
       {Opt_compress_mode, "compress_mode=%s"},
       {Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct 
 super_block *sb,
   }
   #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and 

non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */

fs/f2fs/super.c +17 -0
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+    unsigned char (*ext)[F2FS_EXTENSION_LEN];
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+    ext = F2FS_OPTION(sbi).extensions;
+    ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    noext = F2FS_OPTION(sbi).noextensions;
+    noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+    if (!noext_cnt)
+        return 0;
+
+    for (no_index = 0; no_index < noext_cnt; no_index++) {
+        if (!strcasecmp("*", noext[no_index])) {
+            f2fs_info(sbi, "Don't allow the nocompress extension 

specifies all files");
+            return -EINVAL;
+        }
+        for (index = 0; index < ext_cnt; index++) {
+            if (!strcasecmp(ext[index], noext[no_index])) { +                f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+                        ext[index]);
+                return -EINVAL;
+            }
+        }
+    }
+    return 0;

fs/f2fs/super.c +2 -0
+}
+

  #ifdef CONFIG_F2FS_FS_LZ4
  static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) {

fs/f2fs/super.c +2 -1
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb, 
 char *options, bool is_remount)
       substring_t args[MAX_OPT_ARGS];
   #ifdef CONFIG_F2FS_FS_COMPRESSION
       unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    int ext_cnt;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt;
   #endif
       char *p, *name;

      int arg = 0;

fs/f2fs/super.c +24 -0
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block 
 *sb, char *options, bool is_remount)
               F2FS_OPTION(sbi).compress_ext_cnt++;
               kfree(name);
               break;
+        case Opt_nocompress_extension:
+            if (!f2fs_sb_has_compression(sbi)) {
+                f2fs_info(sbi, "Image doesn't support compression");
+                break;
+            }
+            name = match_strdup(&args[0]);
+            if (!name)
+                return -ENOMEM;
+
+            noext = F2FS_OPTION(sbi).noextensions;
+            noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+            if (strlen(name) >= F2FS_EXTENSION_LEN ||
+                noext_cnt >= COMPRESS_EXT_NUM) {
+                f2fs_err(sbi,
+                    "invalid extension length/number");
+                kfree(name);
+                return -EINVAL;
+            }
+
+            strcpy(noext[noext_cnt], name);
+            F2FS_OPTION(sbi).nocompress_ext_cnt++;
+            kfree(name);
+            break;

          case Opt_compress_chksum:
              F2FS_OPTION(sbi).compress_chksum = true; break;

fs/f2fs/super.c +0 -0
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb, 
 char *options, bool is_remount)

          case Opt_compress_algorithm:
          case Opt_compress_log_size:
          case Opt_compress_extension:
+        case Opt_nocompress_extension:
          case Opt_compress_chksum:
          case Opt_compress_mode:
              f2fs_info(sbi, "compression options not supported");

fs/f2fs/super.c +7 -0
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block 
 *sb, char *options, bool is_remount)
       }
   #endif
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+    if (f2fs_test_compress_extension(sbi)) {
+        f2fs_err(sbi, "invalid compress or nocompress extension");
+        return -EINVAL;
+    }
+#endif
+
       if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
           f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
                F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void 
 f2fs_show_compress_options(struct seq_file *seq,
               F2FS_OPTION(sbi).extensions[i]);
       }
Quoted 8 lines

fs/f2fs/super.c static inline void f2fs_show_compress_options(struct seq_file *seq, · line 1753

Quoted 8 lines
fs/f2fs/super.c +5 -0
+    for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+        seq_printf(seq, ",nocompress_extension=%s",
+            F2FS_OPTION(sbi).noextensions[i]);
+    }
+
       if (F2FS_OPTION(sbi).compress_chksum)
           seq_puts(seq, ",compress_chksum");
 

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

maintainer
#4 lore raw

Hi all,

I think code in this patch is clear, not sure about the comments, Jaegeuk, any comments on this patch, Fengnan has pinged many times....

Let me know, if you are too busy to review this patch these days.

Thanks

Quoted 315 lines · Fengnan Chang

Hi chao & jaegeuk:
Any comments about this version? It's have been a while,are you not
agree with this patch? Pelase give me some feedback.

Thanks

Quoted 308 lines · Fengnan Chang

Hi chao & jaegeuk:
  Any comments about this version?

Thanks.

Quoted 302 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
    * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
    * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
   Documentation/filesystems/f2fs.rst | 31 +++++++++++-
   fs/f2fs/f2fs.h                     |  2 +
   fs/f2fs/namei.c                    | 18 +++++--
   fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
   4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +0 -0
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s     Support adding

specified extension, so that f2fs can enab
               For other files, we can still enable compression via
ioctl.
               Note that, there is one reserved special extension '*', it can be set to enable compression for all files.
+nocompress_extension=%s       Support adding specified extension, so that f2fs can disable
+             compression on those corresponding files, just contrary to compression extension.
+             If you know exactly which files cannot be compressed, you can use this.
+             The same extension name can't appear in both compress and nocompress
+             extension at the same time.
+             If the compress extension specifies all files, the types specified by the
+             nocompress extension will be treated as special cases and will not be compressed.
+             Don't allow use '*' to specifie all file in nocompress extension.
+             After add nocompress_extension, the priority should be:
+             dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+             See more in compression sections.
+
  compress_chksum         Support verifying chksum of raw data in
compressed cluster.
  compress_mode=%s     Control file compression mode. This supports
"fs" and "user"
               modes. In "fs" mode (default), f2fs does automatic
compression

Documentation/filesystems/f2fs.rst +0 -0
@@ -814,13 +826,30 @@ Compression implementation
     all logical blocks in cluster contain valid data and compress

ratio of
    cluster data is lower than specified threshold.
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
+- To disable compression on regular inode, there are two ways:

Documentation/filesystems/f2fs.rst +7 -0
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir;

touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed. +    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space
to user
    directly in order to guarantee potential data updates later to the
space.
    Instead, the main goal is to reduce data writes to flash disk as
much as

fs/f2fs/f2fs.h +1 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
       unsigned char compress_level;        /* compress level */
       bool compress_chksum;            /* compressed data chksum */
       unsigned char compress_ext_cnt;        /* extension count */
+    unsigned char nocompress_ext_cnt;        /* nocompress extension

count */
      int compress_mode;            /* compression mode */ unsigned char
extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];    /* extensions */ +    unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
  };
  #define F2FS_FEATURE_ENCRYPT        0x0001

fs/f2fs/namei.c +5 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
                           const unsigned char *name)
   {
       __u8 (*extlist)[F2FS_EXTENSION_LEN] =
 sbi->raw_super->extension_list;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN] =
 F2FS_OPTION(sbi).noextensions;
       unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
       int i, cold_count, hot_count;
       if (!f2fs_sb_has_compression(sbi) ||
-            is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
               F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-            !f2fs_may_compress(inode))
+            !f2fs_may_compress(inode) ||
+            (!ext_cnt && !noext_cnt))
           return;

      down_read(&sbi->sb_lock);

fs/f2fs/namei.c +10 -0
@@ -311,6 +313,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
       up_read(&sbi->sb_lock);
+    for (i = 0; i < noext_cnt; i++) {
+        if (is_extension_exist(name, noext[i])) {
+            f2fs_disable_compressed_file(inode);
+            return;
+        }
+    }
+
+    if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+        return;
+
       ext = F2FS_OPTION(sbi).extensions;
       for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +4 -0
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
       Opt_compress_algorithm,
       Opt_compress_log_size,
       Opt_compress_extension,
+    Opt_nocompress_extension,
       Opt_compress_chksum,
       Opt_compress_mode,
       Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
       {Opt_compress_algorithm, "compress_algorithm=%s"},
       {Opt_compress_log_size, "compress_log_size=%u"},
       {Opt_compress_extension, "compress_extension=%s"},
+    {Opt_nocompress_extension, "nocompress_extension=%s"},
       {Opt_compress_chksum, "compress_chksum"},
       {Opt_compress_mode, "compress_mode=%s"},
       {Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct
 super_block *sb,
   }
   #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and

non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */

fs/f2fs/super.c +17 -0
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+    unsigned char (*ext)[F2FS_EXTENSION_LEN];
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+    ext = F2FS_OPTION(sbi).extensions;
+    ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    noext = F2FS_OPTION(sbi).noextensions;
+    noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+    if (!noext_cnt)
+        return 0;
+
+    for (no_index = 0; no_index < noext_cnt; no_index++) {
+        if (!strcasecmp("*", noext[no_index])) {
+            f2fs_info(sbi, "Don't allow the nocompress extension

specifies all files");
+            return -EINVAL;
+        }
+        for (index = 0; index < ext_cnt; index++) {
+            if (!strcasecmp(ext[index], noext[no_index])) { +                f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+                        ext[index]);
+                return -EINVAL;
+            }
+        }
+    }
+    return 0;

fs/f2fs/super.c +2 -0
+}
+
   #ifdef CONFIG_F2FS_FS_LZ4
   static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char

*str)
  {

fs/f2fs/super.c +2 -1
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
       substring_t args[MAX_OPT_ARGS];
   #ifdef CONFIG_F2FS_FS_COMPRESSION
       unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    int ext_cnt;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt;
   #endif
       char *p, *name;

      int arg = 0;

fs/f2fs/super.c +24 -0
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
               F2FS_OPTION(sbi).compress_ext_cnt++;
               kfree(name);
               break;
+        case Opt_nocompress_extension:
+            if (!f2fs_sb_has_compression(sbi)) {
+                f2fs_info(sbi, "Image doesn't support compression");
+                break;
+            }
+            name = match_strdup(&args[0]);
+            if (!name)
+                return -ENOMEM;
+
+            noext = F2FS_OPTION(sbi).noextensions;
+            noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+            if (strlen(name) >= F2FS_EXTENSION_LEN ||
+                noext_cnt >= COMPRESS_EXT_NUM) {
+                f2fs_err(sbi,
+                    "invalid extension length/number");
+                kfree(name);
+                return -EINVAL;
+            }
+
+            strcpy(noext[noext_cnt], name);
+            F2FS_OPTION(sbi).nocompress_ext_cnt++;
+            kfree(name);
+            break;
           case Opt_compress_chksum:
               F2FS_OPTION(sbi).compress_chksum = true;

              break;

fs/f2fs/super.c +1 -0
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
           case Opt_compress_algorithm:
           case Opt_compress_log_size:
           case Opt_compress_extension:
+        case Opt_nocompress_extension:
           case Opt_compress_chksum:
           case Opt_compress_mode:

              f2fs_info(sbi, "compression options not supported");

fs/f2fs/super.c +7 -0
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
       }
   #endif
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+    if (f2fs_test_compress_extension(sbi)) {
+        f2fs_err(sbi, "invalid compress or nocompress extension");
+        return -EINVAL;
+    }
+#endif
+
       if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
           f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
                F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void
 f2fs_show_compress_options(struct seq_file *seq,
               F2FS_OPTION(sbi).extensions[i]);
       }
Quoted 8 lines
Quoted 8 lines

fs/f2fs/super.c static inline void f2fs_show_compress_options(struct seq_file *seq, · line 1753

Quoted 8 lines
fs/f2fs/super.c +5 -0
+    for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+        seq_printf(seq, ",nocompress_extension=%s",
+            F2FS_OPTION(sbi).noextensions[i]);
+    }
+
       if (F2FS_OPTION(sbi).compress_chksum)
           seq_puts(seq, ",compress_chksum");
 

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

maintainer
#5 lore raw
Quoted 6 lines · Chao Yu

Hi all,

I think code in this patch is clear, not sure about the comments, Jaegeuk, any comments on this patch, Fengnan has pinged many times....

Let me know, if you are too busy to review this patch these days.

I reviewed it, and looks good to me. Merged in -dev.

Quoted 319 lines

Thanks

Quoted 315 lines · Fengnan Chang

Hi chao & jaegeuk:
Any comments about this version? It's have been a while,are you not
agree with this patch? Pelase give me some feedback.

Thanks

Quoted 308 lines · Fengnan Chang

Hi chao & jaegeuk:
  Any comments about this version?

Thanks.

Quoted 302 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
    * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
    * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
   Documentation/filesystems/f2fs.rst | 31 +++++++++++-
   fs/f2fs/f2fs.h                     |  2 +
   fs/f2fs/namei.c                    | 18 +++++--
   fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
   4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +0 -0
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s     Support adding

specified extension, so that f2fs can enab
               For other files, we can still enable compression via
ioctl.
               Note that, there is one reserved special extension '*', it can be set to enable compression for all files.
+nocompress_extension=%s       Support adding specified extension, so that f2fs can disable
+             compression on those corresponding files, just contrary to compression extension.
+             If you know exactly which files cannot be compressed, you can use this.
+             The same extension name can't appear in both compress and nocompress
+             extension at the same time.
+             If the compress extension specifies all files, the types specified by the
+             nocompress extension will be treated as special cases and will not be compressed.
+             Don't allow use '*' to specifie all file in nocompress extension.
+             After add nocompress_extension, the priority should be:
+             dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+             See more in compression sections.
+
  compress_chksum         Support verifying chksum of raw data in
compressed cluster.
  compress_mode=%s     Control file compression mode. This supports
"fs" and "user"
               modes. In "fs" mode (default), f2fs does automatic
compression

Documentation/filesystems/f2fs.rst +0 -0
@@ -814,13 +826,30 @@ Compression implementation
     all logical blocks in cluster contain valid data and compress

ratio of
    cluster data is lower than specified threshold.
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
+- To disable compression on regular inode, there are two ways:

Documentation/filesystems/f2fs.rst +7 -0
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir;

touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed. +    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space
to user
    directly in order to guarantee potential data updates later to the
space.
    Instead, the main goal is to reduce data writes to flash disk as
much as

fs/f2fs/f2fs.h +1 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
       unsigned char compress_level;        /* compress level */
       bool compress_chksum;            /* compressed data chksum */
       unsigned char compress_ext_cnt;        /* extension count */
+    unsigned char nocompress_ext_cnt;        /* nocompress extension

count */
      int compress_mode;            /* compression mode */ unsigned char
extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];    /* extensions */ +    unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
  };
  #define F2FS_FEATURE_ENCRYPT        0x0001

fs/f2fs/namei.c +5 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
                           const unsigned char *name)
   {
       __u8 (*extlist)[F2FS_EXTENSION_LEN] =
 sbi->raw_super->extension_list;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN] =
 F2FS_OPTION(sbi).noextensions;
       unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
       int i, cold_count, hot_count;
       if (!f2fs_sb_has_compression(sbi) ||
-            is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
               F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-            !f2fs_may_compress(inode))
+            !f2fs_may_compress(inode) ||
+            (!ext_cnt && !noext_cnt))
           return;

      down_read(&sbi->sb_lock);

fs/f2fs/namei.c +10 -0
@@ -311,6 +313,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
       up_read(&sbi->sb_lock);
+    for (i = 0; i < noext_cnt; i++) {
+        if (is_extension_exist(name, noext[i])) {
+            f2fs_disable_compressed_file(inode);
+            return;
+        }
+    }
+
+    if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+        return;
+
       ext = F2FS_OPTION(sbi).extensions;
       for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +4 -0
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
       Opt_compress_algorithm,
       Opt_compress_log_size,
       Opt_compress_extension,
+    Opt_nocompress_extension,
       Opt_compress_chksum,
       Opt_compress_mode,
       Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
       {Opt_compress_algorithm, "compress_algorithm=%s"},
       {Opt_compress_log_size, "compress_log_size=%u"},
       {Opt_compress_extension, "compress_extension=%s"},
+    {Opt_nocompress_extension, "nocompress_extension=%s"},
       {Opt_compress_chksum, "compress_chksum"},
       {Opt_compress_mode, "compress_mode=%s"},
       {Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct
 super_block *sb,
   }
   #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and

non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */

fs/f2fs/super.c +17 -0
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+    unsigned char (*ext)[F2FS_EXTENSION_LEN];
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+    ext = F2FS_OPTION(sbi).extensions;
+    ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    noext = F2FS_OPTION(sbi).noextensions;
+    noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+    if (!noext_cnt)
+        return 0;
+
+    for (no_index = 0; no_index < noext_cnt; no_index++) {
+        if (!strcasecmp("*", noext[no_index])) {
+            f2fs_info(sbi, "Don't allow the nocompress extension

specifies all files");
+            return -EINVAL;
+        }
+        for (index = 0; index < ext_cnt; index++) {
+            if (!strcasecmp(ext[index], noext[no_index])) { +                f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+                        ext[index]);
+                return -EINVAL;
+            }
+        }
+    }
+    return 0;

fs/f2fs/super.c +2 -0
+}
+
   #ifdef CONFIG_F2FS_FS_LZ4
   static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char

*str)
  {

fs/f2fs/super.c +2 -1
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
       substring_t args[MAX_OPT_ARGS];
   #ifdef CONFIG_F2FS_FS_COMPRESSION
       unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    int ext_cnt;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt;
   #endif
       char *p, *name;

      int arg = 0;

fs/f2fs/super.c +24 -0
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
               F2FS_OPTION(sbi).compress_ext_cnt++;
               kfree(name);
               break;
+        case Opt_nocompress_extension:
+            if (!f2fs_sb_has_compression(sbi)) {
+                f2fs_info(sbi, "Image doesn't support compression");
+                break;
+            }
+            name = match_strdup(&args[0]);
+            if (!name)
+                return -ENOMEM;
+
+            noext = F2FS_OPTION(sbi).noextensions;
+            noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+            if (strlen(name) >= F2FS_EXTENSION_LEN ||
+                noext_cnt >= COMPRESS_EXT_NUM) {
+                f2fs_err(sbi,
+                    "invalid extension length/number");
+                kfree(name);
+                return -EINVAL;
+            }
+
+            strcpy(noext[noext_cnt], name);
+            F2FS_OPTION(sbi).nocompress_ext_cnt++;
+            kfree(name);
+            break;
           case Opt_compress_chksum:
               F2FS_OPTION(sbi).compress_chksum = true;

              break;

fs/f2fs/super.c +1 -0
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
           case Opt_compress_algorithm:
           case Opt_compress_log_size:
           case Opt_compress_extension:
+        case Opt_nocompress_extension:
           case Opt_compress_chksum:
           case Opt_compress_mode:

              f2fs_info(sbi, "compression options not supported");

fs/f2fs/super.c +7 -0
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
       }
   #endif
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+    if (f2fs_test_compress_extension(sbi)) {
+        f2fs_err(sbi, "invalid compress or nocompress extension");
+        return -EINVAL;
+    }
+#endif
+
       if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
           f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
                F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void
 f2fs_show_compress_options(struct seq_file *seq,
               F2FS_OPTION(sbi).extensions[i]);
       }
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fs/f2fs/super.c static inline void f2fs_show_compress_options(struct seq_file *seq, · line 1753

Quoted 8 lines
fs/f2fs/super.c +5 -0
+    for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+        seq_printf(seq, ",nocompress_extension=%s",
+            F2FS_OPTION(sbi).noextensions[i]);
+    }
+
       if (F2FS_OPTION(sbi).compress_chksum)
           seq_puts(seq, ",compress_chksum");
 

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

maintainer Reviewed-by
#6 lore raw
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · Chao Yu

Hi all,

I think code in this patch is clear, not sure about the comments, Jaegeuk, any comments on this patch, Fengnan has pinged many times....

Let me know, if you are too busy to review this patch these days.

I reviewed it, and looks good to me. Merged in -dev.

Cool,

Thanks,

Quoted 320 lines
Quoted 320 lines

Thanks

Quoted 315 lines · Fengnan Chang

Hi chao & jaegeuk:
Any comments about this version? It's have been a while,are you not
agree with this patch? Pelase give me some feedback.

Thanks

Quoted 308 lines · Fengnan Chang

Hi chao & jaegeuk:
  Any comments about this version?

Thanks.

Quoted 302 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
    * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
    * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
    Documentation/filesystems/f2fs.rst | 31 +++++++++++-
    fs/f2fs/f2fs.h                     |  2 +
    fs/f2fs/namei.c                    | 18 +++++--
    fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
    4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +0 -0
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s     Support adding

specified extension, so that f2fs can enab
               For other files, we can still enable compression via
ioctl.
               Note that, there is one reserved special extension '*', it can be set to enable compression for all files.
+nocompress_extension=%s       Support adding specified extension, so that f2fs can disable
+             compression on those corresponding files, just contrary to compression extension.
+             If you know exactly which files cannot be compressed, you can use this.
+             The same extension name can't appear in both compress and nocompress
+             extension at the same time.
+             If the compress extension specifies all files, the types specified by the
+             nocompress extension will be treated as special cases and will not be compressed.
+             Don't allow use '*' to specifie all file in nocompress extension.
+             After add nocompress_extension, the priority should be:
+             dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+             See more in compression sections.
+
  compress_chksum         Support verifying chksum of raw data in
compressed cluster.
  compress_mode=%s     Control file compression mode. This supports
"fs" and "user"
               modes. In "fs" mode (default), f2fs does automatic
compression

Documentation/filesystems/f2fs.rst +0 -0
@@ -814,13 +826,30 @@ Compression implementation
      all logical blocks in cluster contain valid data and compress

ratio of
    cluster data is lower than specified threshold.
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
+- To disable compression on regular inode, there are two ways:

Documentation/filesystems/f2fs.rst +7 -0
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir;

touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed. +    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space
to user
    directly in order to guarantee potential data updates later to the
space.
    Instead, the main goal is to reduce data writes to flash disk as
much as

fs/f2fs/f2fs.h +1 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
        unsigned char compress_level;        /* compress level */
        bool compress_chksum;            /* compressed data chksum */
        unsigned char compress_ext_cnt;        /* extension count */
+    unsigned char nocompress_ext_cnt;        /* nocompress extension

count */
      int compress_mode;            /* compression mode */ unsigned char
extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];    /* extensions */ +    unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
  };
  #define F2FS_FEATURE_ENCRYPT        0x0001

fs/f2fs/namei.c +5 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
                            const unsigned char *name)
    {
        __u8 (*extlist)[F2FS_EXTENSION_LEN] =
 sbi->raw_super->extension_list;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN] =
 F2FS_OPTION(sbi).noextensions;
        unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
        int i, cold_count, hot_count;
        if (!f2fs_sb_has_compression(sbi) ||
-            is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
                F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-            !f2fs_may_compress(inode))
+            !f2fs_may_compress(inode) ||
+            (!ext_cnt && !noext_cnt))
            return;
        down_read(&sbi->sb_lock);
fs/f2fs/namei.c +10 -0
@@ -311,6 +313,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
        up_read(&sbi->sb_lock);
+    for (i = 0; i < noext_cnt; i++) {
+        if (is_extension_exist(name, noext[i])) {
+            f2fs_disable_compressed_file(inode);
+            return;
+        }
+    }
+
+    if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+        return;
+
        ext = F2FS_OPTION(sbi).extensions;
        for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +4 -0
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
        Opt_compress_algorithm,
        Opt_compress_log_size,
        Opt_compress_extension,
+    Opt_nocompress_extension,
        Opt_compress_chksum,
        Opt_compress_mode,
        Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
        {Opt_compress_algorithm, "compress_algorithm=%s"},
        {Opt_compress_log_size, "compress_log_size=%u"},
        {Opt_compress_extension, "compress_extension=%s"},
+    {Opt_nocompress_extension, "nocompress_extension=%s"},
        {Opt_compress_chksum, "compress_chksum"},
        {Opt_compress_mode, "compress_mode=%s"},
        {Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct
 super_block *sb,
    }
    #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and

non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */

fs/f2fs/super.c +17 -0
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+    unsigned char (*ext)[F2FS_EXTENSION_LEN];
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+    ext = F2FS_OPTION(sbi).extensions;
+    ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    noext = F2FS_OPTION(sbi).noextensions;
+    noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+    if (!noext_cnt)
+        return 0;
+
+    for (no_index = 0; no_index < noext_cnt; no_index++) {
+        if (!strcasecmp("*", noext[no_index])) {
+            f2fs_info(sbi, "Don't allow the nocompress extension

specifies all files");
+            return -EINVAL;
+        }
+        for (index = 0; index < ext_cnt; index++) {
+            if (!strcasecmp(ext[index], noext[no_index])) { +                f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+                        ext[index]);
+                return -EINVAL;
+            }
+        }
+    }
+    return 0;

fs/f2fs/super.c +2 -0
+}
+
    #ifdef CONFIG_F2FS_FS_LZ4
    static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char

*str)
  {

fs/f2fs/super.c +2 -1
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
        substring_t args[MAX_OPT_ARGS];
    #ifdef CONFIG_F2FS_FS_COMPRESSION
        unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    int ext_cnt;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt;
    #endif
        char *p, *name;
        int arg = 0;
fs/f2fs/super.c +24 -0
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
                F2FS_OPTION(sbi).compress_ext_cnt++;
                kfree(name);
                break;
+        case Opt_nocompress_extension:
+            if (!f2fs_sb_has_compression(sbi)) {
+                f2fs_info(sbi, "Image doesn't support compression");
+                break;
+            }
+            name = match_strdup(&args[0]);
+            if (!name)
+                return -ENOMEM;
+
+            noext = F2FS_OPTION(sbi).noextensions;
+            noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+            if (strlen(name) >= F2FS_EXTENSION_LEN ||
+                noext_cnt >= COMPRESS_EXT_NUM) {
+                f2fs_err(sbi,
+                    "invalid extension length/number");
+                kfree(name);
+                return -EINVAL;
+            }
+
+            strcpy(noext[noext_cnt], name);
+            F2FS_OPTION(sbi).nocompress_ext_cnt++;
+            kfree(name);
+            break;
            case Opt_compress_chksum:
                F2FS_OPTION(sbi).compress_chksum = true;

              break;

fs/f2fs/super.c +1 -0
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
            case Opt_compress_algorithm:
            case Opt_compress_log_size:
            case Opt_compress_extension:
+        case Opt_nocompress_extension:
            case Opt_compress_chksum:
            case Opt_compress_mode:
                f2fs_info(sbi, "compression options not supported");
fs/f2fs/super.c +7 -0
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
        }
    #endif
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+    if (f2fs_test_compress_extension(sbi)) {
+        f2fs_err(sbi, "invalid compress or nocompress extension");
+        return -EINVAL;
+    }
+#endif
+
        if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
            f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
                 F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void
 f2fs_show_compress_options(struct seq_file *seq,
                F2FS_OPTION(sbi).extensions[i]);
        }
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fs/f2fs/super.c static inline void f2fs_show_compress_options(struct seq_file *seq, · line 1753

Quoted 8 lines
fs/f2fs/super.c +5 -0
+    for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+        seq_printf(seq, ",nocompress_extension=%s",
+            F2FS_OPTION(sbi).noextensions[i]);
+    }
+
        if (F2FS_OPTION(sbi).compress_chksum)
            seq_puts(seq, ",compress_chksum");
 

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

maintainer
#7 lore raw
Quoted 7 lines · Chao Yu
Quoted 6 lines · Jaegeuk Kim
Quoted 5 lines · Chao Yu

Hi all,

I think code in this patch is clear, not sure about the comments, Jaegeuk, any comments on this patch, Fengnan has pinged many times....

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Let me know, if you are too busy to review this patch these days.

I reviewed it, and looks good to me. Merged in -dev.

Cool,

Chao, please check f2fs-dev branch, as I had to modify in set_compress_inode() to address build failure and neat code.

Thanks,

Quoted 323 lines

Thanks,

Quoted 320 lines
Quoted 320 lines

Thanks

Quoted 315 lines · Fengnan Chang

Hi chao & jaegeuk:
Any comments about this version? It's have been a while,are you not
agree with this patch? Pelase give me some feedback.

Thanks

Quoted 308 lines · Fengnan Chang

Hi chao & jaegeuk:
  Any comments about this version?

Thanks.

Quoted 302 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
    * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
    * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
    Documentation/filesystems/f2fs.rst | 31 +++++++++++-
    fs/f2fs/f2fs.h                     |  2 +
    fs/f2fs/namei.c                    | 18 +++++--
    fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
    4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +0 -0
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s     Support adding

specified extension, so that f2fs can enab
               For other files, we can still enable compression via
ioctl.
               Note that, there is one reserved special extension '*', it can be set to enable compression for all files.
+nocompress_extension=%s       Support adding specified extension, so that f2fs can disable
+             compression on those corresponding files, just contrary to compression extension.
+             If you know exactly which files cannot be compressed, you can use this.
+             The same extension name can't appear in both compress and nocompress
+             extension at the same time.
+             If the compress extension specifies all files, the types specified by the
+             nocompress extension will be treated as special cases and will not be compressed.
+             Don't allow use '*' to specifie all file in nocompress extension.
+             After add nocompress_extension, the priority should be:
+             dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+             See more in compression sections.
+
  compress_chksum         Support verifying chksum of raw data in
compressed cluster.
  compress_mode=%s     Control file compression mode. This supports
"fs" and "user"
               modes. In "fs" mode (default), f2fs does automatic
compression

Documentation/filesystems/f2fs.rst +0 -0
@@ -814,13 +826,30 @@ Compression implementation
      all logical blocks in cluster contain valid data and compress

ratio of
    cluster data is lower than specified threshold.
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
+- To disable compression on regular inode, there are two ways:

Documentation/filesystems/f2fs.rst +7 -0
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir;

touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed. +    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space
to user
    directly in order to guarantee potential data updates later to the
space.
    Instead, the main goal is to reduce data writes to flash disk as
much as

fs/f2fs/f2fs.h +1 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
        unsigned char compress_level;        /* compress level */
        bool compress_chksum;            /* compressed data chksum */
        unsigned char compress_ext_cnt;        /* extension count */
+    unsigned char nocompress_ext_cnt;        /* nocompress extension

count */
      int compress_mode;            /* compression mode */ unsigned char
extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];    /* extensions */ +    unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */
  };
  #define F2FS_FEATURE_ENCRYPT        0x0001

fs/f2fs/namei.c +5 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
                            const unsigned char *name)
    {
        __u8 (*extlist)[F2FS_EXTENSION_LEN] =
 sbi->raw_super->extension_list;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN] =
 F2FS_OPTION(sbi).noextensions;
        unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
        int i, cold_count, hot_count;
        if (!f2fs_sb_has_compression(sbi) ||
-            is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
                F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-            !f2fs_may_compress(inode))
+            !f2fs_may_compress(inode) ||
+            (!ext_cnt && !noext_cnt))
            return;
        down_read(&sbi->sb_lock);
fs/f2fs/namei.c +10 -0
@@ -311,6 +313,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
        up_read(&sbi->sb_lock);
+    for (i = 0; i < noext_cnt; i++) {
+        if (is_extension_exist(name, noext[i])) {
+            f2fs_disable_compressed_file(inode);
+            return;
+        }
+    }
+
+    if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+        return;
+
        ext = F2FS_OPTION(sbi).extensions;
        for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +4 -0
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
        Opt_compress_algorithm,
        Opt_compress_log_size,
        Opt_compress_extension,
+    Opt_nocompress_extension,
        Opt_compress_chksum,
        Opt_compress_mode,
        Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
        {Opt_compress_algorithm, "compress_algorithm=%s"},
        {Opt_compress_log_size, "compress_log_size=%u"},
        {Opt_compress_extension, "compress_extension=%s"},
+    {Opt_nocompress_extension, "nocompress_extension=%s"},
        {Opt_compress_chksum, "compress_chksum"},
        {Opt_compress_mode, "compress_mode=%s"},
        {Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct
 super_block *sb,
    }
    #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and

non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */

fs/f2fs/super.c +17 -0
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+    unsigned char (*ext)[F2FS_EXTENSION_LEN];
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+    ext = F2FS_OPTION(sbi).extensions;
+    ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    noext = F2FS_OPTION(sbi).noextensions;
+    noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+    if (!noext_cnt)
+        return 0;
+
+    for (no_index = 0; no_index < noext_cnt; no_index++) {
+        if (!strcasecmp("*", noext[no_index])) {
+            f2fs_info(sbi, "Don't allow the nocompress extension

specifies all files");
+            return -EINVAL;
+        }
+        for (index = 0; index < ext_cnt; index++) {
+            if (!strcasecmp(ext[index], noext[no_index])) { +                f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+                        ext[index]);
+                return -EINVAL;
+            }
+        }
+    }
+    return 0;

fs/f2fs/super.c +2 -0
+}
+
    #ifdef CONFIG_F2FS_FS_LZ4
    static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char

*str)
  {

fs/f2fs/super.c +2 -1
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
        substring_t args[MAX_OPT_ARGS];
    #ifdef CONFIG_F2FS_FS_COMPRESSION
        unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    int ext_cnt;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt;
    #endif
        char *p, *name;
        int arg = 0;
fs/f2fs/super.c +24 -0
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
                F2FS_OPTION(sbi).compress_ext_cnt++;
                kfree(name);
                break;
+        case Opt_nocompress_extension:
+            if (!f2fs_sb_has_compression(sbi)) {
+                f2fs_info(sbi, "Image doesn't support compression");
+                break;
+            }
+            name = match_strdup(&args[0]);
+            if (!name)
+                return -ENOMEM;
+
+            noext = F2FS_OPTION(sbi).noextensions;
+            noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+            if (strlen(name) >= F2FS_EXTENSION_LEN ||
+                noext_cnt >= COMPRESS_EXT_NUM) {
+                f2fs_err(sbi,
+                    "invalid extension length/number");
+                kfree(name);
+                return -EINVAL;
+            }
+
+            strcpy(noext[noext_cnt], name);
+            F2FS_OPTION(sbi).nocompress_ext_cnt++;
+            kfree(name);
+            break;
            case Opt_compress_chksum:
                F2FS_OPTION(sbi).compress_chksum = true;

              break;

fs/f2fs/super.c +1 -0
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
            case Opt_compress_algorithm:
            case Opt_compress_log_size:
            case Opt_compress_extension:
+        case Opt_nocompress_extension:
            case Opt_compress_chksum:
            case Opt_compress_mode:
                f2fs_info(sbi, "compression options not supported");
fs/f2fs/super.c +7 -0
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
        }
    #endif
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+    if (f2fs_test_compress_extension(sbi)) {
+        f2fs_err(sbi, "invalid compress or nocompress extension");
+        return -EINVAL;
+    }
+#endif
+
        if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
            f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
                 F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void
 f2fs_show_compress_options(struct seq_file *seq,
                F2FS_OPTION(sbi).extensions[i]);
        }
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fs/f2fs/super.c static inline void f2fs_show_compress_options(struct seq_file *seq, · line 1753

Quoted 8 lines
fs/f2fs/super.c +5 -0
+    for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+        seq_printf(seq, ",nocompress_extension=%s",
+            F2FS_OPTION(sbi).noextensions[i]);
+    }
+
        if (F2FS_OPTION(sbi).compress_chksum)
            seq_puts(seq, ",compress_chksum");
 

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

maintainer
#8 lore raw
Quoted 10 lines · Jaegeuk Kim
Quoted 9 lines · Chao Yu
Quoted 8 lines · Jaegeuk Kim
Quoted 6 lines · Chao Yu

Hi all,

I think code in this patch is clear, not sure about the comments, Jaegeuk, any comments on this patch, Fengnan has pinged many times....

Let me know, if you are too busy to review this patch these days.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I reviewed it, and looks good to me. Merged in -dev.

Cool,

Chao, please check f2fs-dev branch, as I had to modify in set_compress_inode() to address build failure and neat code.

Looks good to me.

Thanks,

Quoted 326 lines

Thanks,

Quoted 323 lines

Thanks,

Quoted 320 lines
Quoted 320 lines

Thanks

Quoted 315 lines · Fengnan Chang

Hi chao & jaegeuk:
Any comments about this version? It's have been a while,are you not
agree with this patch? Pelase give me some feedback.

Thanks

Quoted 308 lines · Fengnan Chang

Hi chao & jaegeuk:
  Any comments about this version?

Thanks.

Quoted 302 lines · Fengnan Chang

When we create a directory with enable compression, all file write into directory will try to compress.But sometimes we may know, new file cannot meet compression ratio requirements.
We need a nocompress extension to skip those files to avoid unnecessary compress page test.

After add nocompress_extension, the priority should be:
dir_flag < comp_extention,nocompress_extension < comp_file_flag, no_comp_file_flag.

Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
    * compress_extension=so; nocompress_extension=zip; chattr +c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip can enable compress on bar.zip.
    * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be compresse, bar.zip and baz.txt should be non-compressed. chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip and baz.txt.

---
     Documentation/filesystems/f2fs.rst | 31 +++++++++++-
     fs/f2fs/f2fs.h                     |  2 +
     fs/f2fs/namei.c                    | 18 +++++--
     fs/f2fs/super.c                    | 79 +++++++++++++++++++++++++++++-
     4 files changed, 125 insertions(+), 5 deletions(-)
Documentation/filesystems/f2fs.rst +0 -0
index 992bf91eeec8..c68f1c822665 100644
@@ -281,6 +281,18 @@ compress_extension=%s     Support adding

specified extension, so that f2fs can enab
               For other files, we can still enable compression via
ioctl.
               Note that, there is one reserved special extension '*', it can be set to enable compression for all files.
+nocompress_extension=%s       Support adding specified extension, so that f2fs can disable
+             compression on those corresponding files, just contrary to compression extension.
+             If you know exactly which files cannot be compressed, you can use this.
+             The same extension name can't appear in both compress and nocompress
+             extension at the same time.
+             If the compress extension specifies all files, the types specified by the
+             nocompress extension will be treated as special cases and will not be compressed.
+             Don't allow use '*' to specifie all file in nocompress extension.
+             After add nocompress_extension, the priority should be:
+             dir_flag < comp_extention,nocompress_extension < comp_file_flag,no_comp_file_flag.
+             See more in compression sections.
+
  compress_chksum         Support verifying chksum of raw data in
compressed cluster.
  compress_mode=%s     Control file compression mode. This supports
"fs" and "user"
               modes. In "fs" mode (default), f2fs does automatic
compression

Documentation/filesystems/f2fs.rst +0 -0
@@ -814,13 +826,30 @@ Compression implementation
       all logical blocks in cluster contain valid data and compress

ratio of
    cluster data is lower than specified threshold.
-- To enable compression on regular inode, there are three ways:
+- To enable compression on regular inode, there are four ways:
    * chattr +c file
    * chattr +c dir; touch dir/file
    * mount w/ -o compress_extension=ext; touch file.ext
    * mount w/ -o compress_extension=*; touch any_file
+- To disable compression on regular inode, there are two ways:

Documentation/filesystems/f2fs.rst +7 -0
+
+  * chattr -c file
+  * mount w/ -o nocompress_extension=ext; touch file.ext
+
+- Priority in between FS_COMPR_FL, FS_NOCOMP_FS, extensions:
+
+  * compress_extension=so; nocompress_extension=zip; chattr +c dir;

touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so and baz.txt
+    should be compresse, bar.zip should be non-compressed. chattr +c dir/bar.zip
+    can enable compress on bar.zip.
+  * compress_extension=so; nocompress_extension=zip; chattr -c dir; touch
+    dir/foo.so; touch dir/bar.zip; touch dir/baz.txt; then foo.so should be
+    compresse, bar.zip and baz.txt should be non-compressed. +    chattr+c dir/bar.zip; chattr+c dir/baz.txt; can enable compress on bar.zip
+    and baz.txt.
+
  - At this point, compression feature doesn't expose compressed space
to user
    directly in order to guarantee potential data updates later to the
space.
    Instead, the main goal is to reduce data writes to flash disk as
much as

fs/f2fs/f2fs.h +1 -0
index 9ad502f92529..7d13d4d64d59 100644
@@ -150,8 +150,10 @@ struct f2fs_mount_info {
         unsigned char compress_level;        /* compress level */
         bool compress_chksum;            /* compressed data chksum */
         unsigned char compress_ext_cnt;        /* extension count */
+    unsigned char nocompress_ext_cnt;        /* nocompress extension

count */
      int compress_mode;            /* compression mode */ unsigned char
extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];    /* extensions */ +    unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */

     };
     #define F2FS_FEATURE_ENCRYPT        0x0001
fs/f2fs/namei.c +5 -3
index d4139e166b95..f343842da4f3 100644
@@ -287,14 +287,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
                             const unsigned char *name)
     {
         __u8 (*extlist)[F2FS_EXTENSION_LEN] =
 sbi->raw_super->extension_list;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN] =
 F2FS_OPTION(sbi).noextensions;
         unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
         int i, cold_count, hot_count;
         if (!f2fs_sb_has_compression(sbi) ||
-            is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
                 F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
-            !f2fs_may_compress(inode))
+            !f2fs_may_compress(inode) ||
+            (!ext_cnt && !noext_cnt))
             return;
         down_read(&sbi->sb_lock);
fs/f2fs/namei.c +10 -0
@@ -311,6 +313,16 @@ static void set_compress_inode(struct
 f2fs_sb_info *sbi, struct inode *inode,
         up_read(&sbi->sb_lock);
+    for (i = 0; i < noext_cnt; i++) {
+        if (is_extension_exist(name, noext[i])) {
+            f2fs_disable_compressed_file(inode);
+            return;
+        }
+    }
+
+    if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
+        return;
+
         ext = F2FS_OPTION(sbi).extensions;
         for (i = 0; i < ext_cnt; i++) {
fs/f2fs/super.c +4 -0
index 6788e7b71e27..e720323b900c 100644
@@ -148,6 +148,7 @@ enum {
         Opt_compress_algorithm,
         Opt_compress_log_size,
         Opt_compress_extension,
+    Opt_nocompress_extension,
         Opt_compress_chksum,
         Opt_compress_mode,
         Opt_atgc,
@@ -222,6 +223,7 @@ static match_table_t f2fs_tokens = {
         {Opt_compress_algorithm, "compress_algorithm=%s"},
         {Opt_compress_log_size, "compress_log_size=%u"},
         {Opt_compress_extension, "compress_extension=%s"},
+    {Opt_nocompress_extension, "nocompress_extension=%s"},
         {Opt_compress_chksum, "compress_chksum"},
         {Opt_compress_mode, "compress_mode=%s"},
         {Opt_atgc, "atgc"},
@@ -473,6 +475,43 @@ static int f2fs_set_test_dummy_encryption(struct
 super_block *sb,
     }
     #ifdef CONFIG_F2FS_FS_COMPRESSION
+/*
+ * 1. The same extension name cannot not appear in both compress and

non-compress extension
+ * at the same time.
+ * 2. If the compress extension specifies all files, the types specified by the non-compress
+ * extension will be treated as special cases and will not be compressed.
+ * 3. Don't allow the non-compress extension specifies all files.
+ */

fs/f2fs/super.c +17 -0
+static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
+{
+    unsigned char (*ext)[F2FS_EXTENSION_LEN];
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt, index = 0, no_index = 0;
+
+    ext = F2FS_OPTION(sbi).extensions;
+    ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+    noext = F2FS_OPTION(sbi).noextensions;
+    noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+    if (!noext_cnt)
+        return 0;
+
+    for (no_index = 0; no_index < noext_cnt; no_index++) {
+        if (!strcasecmp("*", noext[no_index])) {
+            f2fs_info(sbi, "Don't allow the nocompress extension

specifies all files");
+            return -EINVAL;
+        }
+        for (index = 0; index < ext_cnt; index++) {
+            if (!strcasecmp(ext[index], noext[no_index])) { +                f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
+                        ext[index]);
+                return -EINVAL;
+            }
+        }
+    }
+    return 0;

fs/f2fs/super.c +2 -0
+}
+
     #ifdef CONFIG_F2FS_FS_LZ4
     static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char

*str)
  {

fs/f2fs/super.c +2 -1
@@ -546,7 +585,8 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
         substring_t args[MAX_OPT_ARGS];
     #ifdef CONFIG_F2FS_FS_COMPRESSION
         unsigned char (*ext)[F2FS_EXTENSION_LEN];
-    int ext_cnt;
+    unsigned char (*noext)[F2FS_EXTENSION_LEN];
+    int ext_cnt, noext_cnt;
     #endif
         char *p, *name;
         int arg = 0;
fs/f2fs/super.c +24 -0
@@ -1049,6 +1089,30 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
                 F2FS_OPTION(sbi).compress_ext_cnt++;
                 kfree(name);
                 break;
+        case Opt_nocompress_extension:
+            if (!f2fs_sb_has_compression(sbi)) {
+                f2fs_info(sbi, "Image doesn't support compression");
+                break;
+            }
+            name = match_strdup(&args[0]);
+            if (!name)
+                return -ENOMEM;
+
+            noext = F2FS_OPTION(sbi).noextensions;
+            noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
+
+            if (strlen(name) >= F2FS_EXTENSION_LEN ||
+                noext_cnt >= COMPRESS_EXT_NUM) {
+                f2fs_err(sbi,
+                    "invalid extension length/number");
+                kfree(name);
+                return -EINVAL;
+            }
+
+            strcpy(noext[noext_cnt], name);
+            F2FS_OPTION(sbi).nocompress_ext_cnt++;
+            kfree(name);
+            break;
             case Opt_compress_chksum:
                 F2FS_OPTION(sbi).compress_chksum = true;
                 break;
fs/f2fs/super.c +1 -0
@@ -1070,6 +1134,7 @@ static int parse_options(struct super_block *sb,
 char *options, bool is_remount)
             case Opt_compress_algorithm:
             case Opt_compress_log_size:
             case Opt_compress_extension:
+        case Opt_nocompress_extension:
             case Opt_compress_chksum:
             case Opt_compress_mode:
                 f2fs_info(sbi, "compression options not supported");
fs/f2fs/super.c +7 -0
@@ -1123,6 +1188,13 @@ static int parse_options(struct super_block
 *sb, char *options, bool is_remount)
         }
     #endif
+#ifdef CONFIG_F2FS_FS_COMPRESSION
+    if (f2fs_test_compress_extension(sbi)) {
+        f2fs_err(sbi, "invalid compress or nocompress extension");
+        return -EINVAL;
+    }
+#endif
+
         if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
             f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
                  F2FS_IO_SIZE_KB(sbi));
@@ -1671,6 +1743,11 @@ static inline void
 f2fs_show_compress_options(struct seq_file *seq,
                 F2FS_OPTION(sbi).extensions[i]);
         }
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fs/f2fs/super.c static inline void · line 1753

Quoted 8 lines
fs/f2fs/super.c +5 -0
+    for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
+        seq_printf(seq, ",nocompress_extension=%s",
+            F2FS_OPTION(sbi).noextensions[i]);
+    }
+
         if (F2FS_OPTION(sbi).compress_chksum)
             seq_puts(seq, ",compress_chksum");
 

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