[3/5] f2fs: add age_extent_cache mount option

Message ID 20221128085859.5295-4-qixiaoyu1@xiaomi.com
State New
Headers
Series Support enhanced hot/cold data separation for f2fs |

Commit Message

qixiaoyu1 Nov. 28, 2022, 8:58 a.m. UTC
  From: xiongping1 <xiongping1@xiaomi.com>

enable data block seperation feature only when
age_extent_cache mount option is on

Signed-off-by: xiongping1 <xiongping1@xiaomi.com>
Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com>
---
 Documentation/filesystems/f2fs.rst |  4 ++++
 fs/f2fs/block_age.c                |  3 +++
 fs/f2fs/f2fs.h                     |  1 +
 fs/f2fs/super.c                    | 27 +++++++++++++++++++++++++++
 4 files changed, 35 insertions(+)
  

Patch

diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst
index 17df9a02ccff..f4e8943f649d 100644
--- a/Documentation/filesystems/f2fs.rst
+++ b/Documentation/filesystems/f2fs.rst
@@ -340,6 +340,10 @@  memory=%s		 Control memory mode. This supports "normal" and "low" modes.
 			 Because of the nature of low memory devices, in this mode, f2fs
 			 will try to save memory sometimes by sacrificing performance.
 			 "normal" mode is the default mode and same as before.
+age_extent_cache	 Enable an age extent cache based on rb-tree, it can record
+			 data block update frequency of the extent per inode, in
+			 order to indicate better temperature info for data block
+			 allocation.
 ======================== ============================================================
 
 Debugfs Entries
diff --git a/fs/f2fs/block_age.c b/fs/f2fs/block_age.c
index c8e8fbe51d8e..bc009616adfb 100644
--- a/fs/f2fs/block_age.c
+++ b/fs/f2fs/block_age.c
@@ -37,6 +37,9 @@  static inline bool f2fs_may_age_extent_tree(struct inode *inode)
 	if (list_empty(&sbi->s_list))
 		return false;
 
+	if (!test_opt(sbi, AGE_EXTENT_CACHE))
+		return false;
+
 	/* don't cache block age info for cold file */
 	if (is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
 			file_is_cold(inode))
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 5cc516228407..428cc560b721 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -106,6 +106,7 @@  extern const char *f2fs_fault_name[FAULT_MAX];
 #define F2FS_MOUNT_MERGE_CHECKPOINT	0x10000000
 #define	F2FS_MOUNT_GC_MERGE		0x20000000
 #define F2FS_MOUNT_COMPRESS_CACHE	0x40000000
+#define F2FS_MOUNT_AGE_EXTENT_CACHE	0x80000000
 
 #define F2FS_OPTION(sbi)	((sbi)->mount_opt)
 #define clear_opt(sbi, option)	(F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 91d3c9d0425d..dcb5905c7264 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -161,6 +161,9 @@  enum {
 	Opt_nogc_merge,
 	Opt_discard_unit,
 	Opt_memory_mode,
+#ifdef CONFIG_F2FS_FS_DATA_SEPARATION
+	Opt_age_extent_cache,
+#endif
 	Opt_err,
 };
 
@@ -238,6 +241,9 @@  static match_table_t f2fs_tokens = {
 	{Opt_nogc_merge, "nogc_merge"},
 	{Opt_discard_unit, "discard_unit=%s"},
 	{Opt_memory_mode, "memory=%s"},
+#ifdef CONFIG_F2FS_FS_DATA_SEPARATION
+	{Opt_age_extent_cache, "age_extent_cache"},
+#endif
 	{Opt_err, NULL},
 };
 
@@ -1253,6 +1259,11 @@  static int parse_options(struct super_block *sb, char *options, bool is_remount)
 			}
 			kfree(name);
 			break;
+#ifdef CONFIG_F2FS_FS_DATA_SEPARATION
+		case Opt_age_extent_cache:
+			set_opt(sbi, AGE_EXTENT_CACHE);
+			break;
+#endif
 		default:
 			f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
 				 p);
@@ -2035,6 +2046,10 @@  static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 	else if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW)
 		seq_printf(seq, ",memory=%s", "low");
 
+#ifdef CONFIG_F2FS_FS_DATA_SEPARATION
+	if (test_opt(sbi, AGE_EXTENT_CACHE))
+		seq_puts(seq, ",age_extent_cache");
+#endif
 	return 0;
 }
 
@@ -2206,6 +2221,9 @@  static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	bool need_restart_discard = false, need_stop_discard = false;
 	bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
 	bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT);
+#ifdef CONFIG_F2FS_FS_DATA_SEPARATION
+	bool no_age_extent_cache = !test_opt(sbi, AGE_EXTENT_CACHE);
+#endif
 	bool no_io_align = !F2FS_IO_ALIGNED(sbi);
 	bool no_atgc = !test_opt(sbi, ATGC);
 	bool no_discard = !test_opt(sbi, DISCARD);
@@ -2300,6 +2318,15 @@  static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 		goto restore_opts;
 	}
 
+#ifdef CONFIG_F2FS_FS_DATA_SEPARATION
+	/* disallow enable/disable age extent_cache dynamically */
+	if (no_age_extent_cache == !!test_opt(sbi, AGE_EXTENT_CACHE)) {
+		err = -EINVAL;
+		f2fs_warn(sbi, "switch age_extent_cache option is not allowed");
+		goto restore_opts;
+	}
+#endif
+
 	if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) {
 		err = -EINVAL;
 		f2fs_warn(sbi, "switch io_bits option is not allowed");