All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [RFC PATCH] f2fs: add no compress extensions support
@ 2021-04-14  9:47 Fengnan Chang
  2021-04-15  1:31 ` Chao Yu
  0 siblings, 1 reply; 8+ messages in thread
From: Fengnan Chang @ 2021-04-14  9:47 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Fengnan Chang, linux-f2fs-devel

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.

Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
---
 fs/f2fs/f2fs.h  |  2 ++
 fs/f2fs/namei.c | 12 +++++++++++-
 fs/f2fs/super.c | 35 +++++++++++++++++++++++++++++++++--
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 87d734f5589d..3d5d28a2568f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 405d85dbf9f1..09b76a7f048a 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -280,15 +280,25 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
 {
 	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
 	unsigned char (*ext)[F2FS_EXTENSION_LEN];
+	unsigned char (*noext)[F2FS_EXTENSION_LEN];
 	unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
+	unsigned int 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))
 		return;

+	if (is_inode_flag_set(inode, FI_COMPRESSED_FILE)) {
+		noext = F2FS_OPTION(sbi).noextensions;
+		for (i = 0; i < noext_cnt; i++) {
+			if (is_extension_exist(name, noext[i]))
+				f2fs_disable_compressed_file(inode);
+		}
+		return;
+	}
+
 	down_read(&sbi->sb_lock);

 	cold_count = le32_to_cpu(sbi->raw_super->extension_count);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 5020152aa8fc..b5a9ba8ea869 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -153,6 +153,7 @@ enum {
 	Opt_atgc,
 	Opt_gc_merge,
 	Opt_nogc_merge,
+	Opt_nocompress_extension,
 	Opt_err,
 };

@@ -227,6 +228,7 @@ static match_table_t f2fs_tokens = {
 	{Opt_atgc, "atgc"},
 	{Opt_gc_merge, "gc_merge"},
 	{Opt_nogc_merge, "nogc_merge"},
+	{Opt_nocompress_extension, "nocompress_extension=%s"},
 	{Opt_err, NULL},
 };

@@ -546,7 +548,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 +1052,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;
@@ -1072,6 +1099,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 		case Opt_compress_extension:
 		case Opt_compress_chksum:
 		case Opt_compress_mode:
+		case Opt_nocompress_extension:
 			f2fs_info(sbi, "compression options not supported");
 			break;
 #endif
@@ -1664,7 +1692,10 @@ static inline void f2fs_show_compress_options(struct seq_file *seq,
 		seq_printf(seq, ",compress_extension=%s",
 			F2FS_OPTION(sbi).extensions[i]);
 	}
-
+	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");

--
2.29.0



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

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

end of thread, other threads:[~2021-04-21 13:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14  9:47 [f2fs-dev] [RFC PATCH] f2fs: add no compress extensions support Fengnan Chang
2021-04-15  1:31 ` Chao Yu
2021-04-15  1:56   ` [f2fs-dev] 答复: " changfengnan
2021-04-17  2:43     ` Chao Yu
2021-04-17  7:02       ` [f2fs-dev] =?y?q?Re=3A=20=5Bf2fs-dev=5D=20=E7=AD=94=E5=A4=8D=3A=20=20=5BRFC=20PATCH=5D=20f2fs=3A=20add=20no=20compress=20extensions=20support?= Fengnan Chang
2021-04-19 16:22         ` [f2fs-dev] 答复: [RFC PATCH] f2fs: add no compress extensions support Jaegeuk Kim
2021-04-20  2:08           ` [f2fs-dev] 答复: " changfengnan
2021-04-21 13:06             ` changfengnan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.