Skip to contentSkip to conversation

f2fs:dax: Implement direct access

PATCH Superseded sunqiuyang 1 participant 1 message May 4, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

sunqiuyang

author
#0 lore raw

PATCH 3/3 f2fs:dax: Implement direct access

This patch implements Direct Access (DAX) in F2FS, including:
- a mount option to enable DAX
- read/write and mmap of regular files in the DAX way
- zero-out of non-aligned partial blocks in the DAX way
- garbage collection of DAX files
- incompatibility of DAX with inline data, atomic or volatile write

TODO: We may need new implementation of f2fs_collapse/insert_range() for DAX files, as filemap_write_and_wait_range() does not work for DAX files, and thus the data pages cannot be moved correctly.

---
 fs/f2fs/f2fs.h   |   8 +++
 fs/f2fs/file.c   | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/f2fs/gc.c     |  69 +++++++++++++++++--
 fs/f2fs/inline.c |   4 ++
 fs/f2fs/inode.c  |  88 +++++++++++++++++++++++++
 fs/f2fs/namei.c  |   7 ++
 fs/f2fs/super.c  |  16 +++++
 7 files changed, 383 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +8 -0
index f7957ca..d0e8af5 100644
@@ -87,6 +87,11 @@ struct f2fs_fault_info {
 #define F2FS_MOUNT_FAULT_INJECTION	0x00010000
 #define F2FS_MOUNT_ADAPTIVE		0x00020000
 #define F2FS_MOUNT_LFS			0x00040000
+#ifdef CONFIG_FS_DAX
+#define F2FS_MOUNT_DAX			0x00080000 /* Direct Access */
+#else
+#define F2FS_MOUNT_DAX			0
+#endif
 
 #define clear_opt(sbi, option)	(sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
 #define set_opt(sbi, option)	(sbi->mount_opt.opt |= F2FS_MOUNT_##option)
@@ -2063,6 +2068,9 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
+#ifdef CONFIG_FS_DAX
+extern struct iomap_ops f2fs_iomap_ops;
+#endif
 
 /*
  * namei.c
fs/f2fs/file.c +195 -2

288 lines not on this page · raw message

fs/f2fs/gc.c +65 -4

93 lines not on this page · raw message

fs/f2fs/inline.c +4 -0
index e32a9e5..4b9d853 100644
@@ -28,6 +28,10 @@ bool f2fs_may_inline_data(struct inode *inode)
 	if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
 		return false;
 
+#ifdef CONFIG_FS_DAX
+	if (IS_DAX(inode))
+		return false;
+#endif
 	return true;
 }
 
fs/f2fs/inode.c +88 -0

97 lines not on this page · raw message

fs/f2fs/namei.c +7 -0
index 98f00a3..922d42f 100644
@@ -60,6 +60,13 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
 	if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
 		f2fs_set_encrypted_inode(inode);
 
+#ifdef CONFIG_FS_DAX
+	if (test_opt(sbi, DAX) &&
+	S_ISREG(inode->i_mode) &&
+	!f2fs_has_inline_data(inode) &&
+	!f2fs_encrypted_inode(inode))
+		inode->i_flags |= S_DAX;
+#endif
 	set_inode_flag(inode, FI_NEW_INODE);
 
 	if (test_opt(sbi, INLINE_XATTR))
fs/f2fs/super.c +16 -0
index 30855cf..3463bf9 100644
@@ -106,6 +106,7 @@ enum {
 	Opt_fault_injection,
 	Opt_lazytime,
 	Opt_nolazytime,
+	Opt_dax,
 	Opt_err,
 };
 
@@ -140,6 +141,7 @@ enum {
 	{Opt_fault_injection, "fault_injection=%u"},
 	{Opt_lazytime, "lazytime"},
 	{Opt_nolazytime, "nolazytime"},
+	{Opt_dax, "dax"},
 	{Opt_err, NULL},
 };
 
@@ -482,6 +484,16 @@ static int parse_options(struct super_block *sb, char *options)
 			f2fs_msg(sb, KERN_INFO, "noacl options not supported");
 			break;
 #endif
+#ifdef CONFIG_FS_DAX
+		case Opt_dax:
+			set_opt(sbi, DAX);
+			break;
+#else
+		case Opt_dax:
+			f2fs_msg(sb, KERN_INFO, "dax options not supported");
+			break;
+#endif
+
 		case Opt_active_logs:
 			if (args->from && match_int(args, &arg))
 				return -EINVAL;
@@ -966,6 +978,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 	if (test_opt(sbi, FAULT_INJECTION))
 		seq_puts(seq, ",fault_injection");
 #endif
+#ifdef CONFIG_FS_DAX
+	if (test_opt(sbi, DAX))
+		seq_puts(seq, ",dax");
+#endif
 
 	return 0;
 }
Signature · 6 lines
1.8.3.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot