[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1384811492-37040-1-git-send-email-ross.zwisler@linux.intel.com>
Date: Mon, 18 Nov 2013 14:51:32 -0700
From: Ross Zwisler <ross.zwisler@...ux.intel.com>
To: andreas.dilger@...el.com, linux-ext4@...r.kernel.org,
linux-fsdevel@...r.kernel.org
Cc: Ross Zwisler <ross.zwisler@...ux.intel.com>
Subject: [PATCH] ext4: Add XIP functionality
This is a port of the XIP functionality found in the current version of
ext2. This patch set is intended to achieve feature parity with XIP in
ext2 rather than non-XIP in ext4. In particular, it lacks support for
splice and AIO. We'll be submitting patches in the future to add that
functionality, but we think this is a good start.
There are also a couple of bugs that also appear in ext2 around handling
of the xip mount option; we're currently investigating and will submit
patches to fix both in ext2 and ext4, but didn't want to delay getting
this patch out for comment.
The motivation behind this work is that we believe that the XIP feature
will begin to find new uses as various persistent memory devices and
technologies come on to the market. Having direct, byte-addressable
access to persistent memory without having an additional copy in the
page cache can be a win in terms of I/O latency and overall memory
usage.
This patch applies cleanly to v3.12, and was tested using brd as our
block driver.
Signed-off-by: Ross Zwisler <ross.zwisler@...ux.intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@...el.com>
---
Documentation/filesystems/ext4.txt | 2 +
Documentation/filesystems/xip.txt | 3 ++
fs/Kconfig | 2 +-
fs/ext4/Kconfig | 11 +++++
fs/ext4/Makefile | 1 +
fs/ext4/ext4.h | 2 +
fs/ext4/file.c | 17 +++++++
fs/ext4/inode.c | 48 +++++++++++++++++---
fs/ext4/namei.c | 11 ++++-
fs/ext4/super.c | 41 ++++++++++++++++-
fs/ext4/xip.c | 91 ++++++++++++++++++++++++++++++++++++++
fs/ext4/xip.h | 26 +++++++++++
12 files changed, 245 insertions(+), 10 deletions(-)
create mode 100644 fs/ext4/xip.c
create mode 100644 fs/ext4/xip.h
diff --git a/Documentation/filesystems/ext4.txt b/Documentation/filesystems/ext4.txt
index 919a329..c32c398 100644
--- a/Documentation/filesystems/ext4.txt
+++ b/Documentation/filesystems/ext4.txt
@@ -386,6 +386,8 @@ max_dir_size_kb=n This limits the size of directories so that any
i_version Enable 64-bit inode version support. This option is
off by default.
+xip Use execute in place (no caching) if possible.
+
Data Mode
=========
There are 3 different data modes:
diff --git a/Documentation/filesystems/xip.txt b/Documentation/filesystems/xip.txt
index 0466ee5..54baa05 100644
--- a/Documentation/filesystems/xip.txt
+++ b/Documentation/filesystems/xip.txt
@@ -38,6 +38,8 @@ alternative, memory technology devices can be used for this.
The block device operation is optional, these block devices support it as of
today:
- dcssblk: s390 dcss block device driver
+- brd: Ram backed block device driver
+- axonram: Axon DDR2 device driver
An address space operation named get_xip_mem is used to retrieve references
to a page frame number and a kernel address. To obtain these values a reference
@@ -49,6 +51,7 @@ This address space operation is mutually exclusive with readpage&writepage that
do page cache read/write operations.
The following filesystems support it as of today:
- ext2: the second extended filesystem, see Documentation/filesystems/ext2.txt
+- ext4: the fourth extended filesystem, see Documentation/filesystems/ext4.txt
A set of file operations that do utilize get_xip_page can be found in
mm/filemap_xip.c . The following file operation implementations are provided:
diff --git a/fs/Kconfig b/fs/Kconfig
index c229f82..595cc00 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -17,7 +17,7 @@ source "fs/ext4/Kconfig"
config FS_XIP
# execute in place
bool
- depends on EXT2_FS_XIP
+ depends on EXT2_FS_XIP || EXT4_FS_XIP
default y
source "fs/jbd/Kconfig"
diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig
index efea5d5..62952cb 100644
--- a/fs/ext4/Kconfig
+++ b/fs/ext4/Kconfig
@@ -73,3 +73,14 @@ config EXT4_DEBUG
If you select Y here, then you will be able to turn on debugging
with a command such as:
echo 1 > /sys/module/ext4/parameters/mballoc_debug
+
+config EXT4_FS_XIP
+ bool "Ext4 execute in place support"
+ depends on EXT4_FS && MMU
+ help
+ Execute in place can be used on memory-backed block devices. If you
+ enable this option, you can select to mount block devices which are
+ capable of this feature without using the page cache.
+
+ If you do not use a block device that is capable of using this,
+ or if unsure, say N.
diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile
index 0310fec..3f1ec56 100644
--- a/fs/ext4/Makefile
+++ b/fs/ext4/Makefile
@@ -12,3 +12,4 @@ ext4-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o page-io.o \
ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o
+ext4-$(CONFIG_EXT4_FS_XIP) += xip.o
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index af815ea..9f4cc26 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -953,6 +953,7 @@ struct ext4_inode_info {
#define EXT4_MOUNT_ERRORS_MASK 0x00070
#define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
#define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
+#define EXT4_MOUNT_XIP 0x00200 /* Execute in place */
#define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
#define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
#define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
@@ -2554,6 +2555,7 @@ extern const struct file_operations ext4_dir_operations;
/* file.c */
extern const struct inode_operations ext4_file_inode_operations;
extern const struct file_operations ext4_file_operations;
+extern const struct file_operations ext4_xip_file_operations;
extern loff_t ext4_llseek(struct file *file, loff_t offset, int origin);
extern void ext4_unwritten_wait(struct inode *inode);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 3da2194..b9499b2 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -609,6 +609,23 @@ const struct file_operations ext4_file_operations = {
.fallocate = ext4_fallocate,
};
+#ifdef CONFIG_EXT4_FS_XIP
+const struct file_operations ext4_xip_file_operations = {
+ .llseek = ext4_llseek,
+ .read = xip_file_read,
+ .write = xip_file_write,
+ .unlocked_ioctl = ext4_ioctl,
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = ext4_compat_ioctl,
+#endif
+ .mmap = xip_file_mmap,
+ .open = ext4_file_open,
+ .release = ext4_release_file,
+ .fsync = ext4_sync_file,
+ .fallocate = ext4_fallocate,
+};
+#endif
+
const struct inode_operations ext4_file_inode_operations = {
.setattr = ext4_setattr,
.getattr = ext4_getattr,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e274e9c..dea66bb 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -43,6 +43,7 @@
#include "xattr.h"
#include "acl.h"
#include "truncate.h"
+#include "xip.h"
#include <trace/events/ext4.h>
@@ -663,6 +664,23 @@ found:
WARN_ON(1);
}
+ if (ext4_use_xip(inode->i_sb)) {
+ ext4_fsblk_t fs_blk;
+
+ for (fs_blk = map->m_pblk;
+ fs_blk < map->m_pblk + map->m_len; fs_blk++) {
+ /*
+ * we need to clear the block
+ */
+ ret = ext4_clear_xip_target(inode, fs_blk);
+
+ if (ret) {
+ retval = ret;
+ goto has_zeroout;
+ }
+ }
+ }
+
/*
* If the extent has been zeroed out, we don't need to update
* extent status tree.
@@ -3266,6 +3284,11 @@ static const struct address_space_operations ext4_aops = {
.error_remove_page = generic_error_remove_page,
};
+const struct address_space_operations ext4_xip_aops = {
+ .bmap = ext4_bmap,
+ .get_xip_mem = ext4_get_xip_mem,
+};
+
static const struct address_space_operations ext4_journalled_aops = {
.readpage = ext4_readpage,
.readpages = ext4_readpages,
@@ -3313,7 +3336,9 @@ void ext4_set_aops(struct inode *inode)
default:
BUG();
}
- if (test_opt(inode->i_sb, DELALLOC))
+ if (ext4_use_xip(inode->i_sb))
+ inode->i_mapping->a_ops = &ext4_xip_aops;
+ else if (test_opt(inode->i_sb, DELALLOC))
inode->i_mapping->a_ops = &ext4_da_aops;
else
inode->i_mapping->a_ops = &ext4_aops;
@@ -4197,7 +4222,10 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
if (S_ISREG(inode->i_mode)) {
inode->i_op = &ext4_file_inode_operations;
- inode->i_fop = &ext4_file_operations;
+ if (ext4_use_xip(inode->i_sb))
+ inode->i_fop = &ext4_xip_file_operations;
+ else
+ inode->i_fop = &ext4_file_operations;
ext4_set_aops(inode);
} else if (S_ISDIR(inode->i_mode)) {
inode->i_op = &ext4_dir_inode_operations;
@@ -4645,11 +4673,19 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
} else
ext4_wait_for_tail_page_commit(inode);
}
- /*
- * Truncate pagecache after we've waited for commit
- * in data=journal mode to make pages freeable.
- */
+
+ if (mapping_is_xip(inode->i_mapping)) {
+ error = xip_truncate_page(inode->i_mapping,
+ inode->i_size);
+ if (error)
+ goto err_out;
+ } else {
+ /*
+ * Truncate pagecache after we've waited for commit
+ * in data=journal mode to make pages freeable.
+ */
truncate_pagecache(inode, inode->i_size);
+ }
}
/*
* We want to call ext4_truncate() even if attr->ia_size ==
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 5a0408d..20a9cf8 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -39,6 +39,7 @@
#include "xattr.h"
#include "acl.h"
+#include "xip.h"
#include <trace/events/ext4.h>
/*
@@ -2250,7 +2251,10 @@ retry:
err = PTR_ERR(inode);
if (!IS_ERR(inode)) {
inode->i_op = &ext4_file_inode_operations;
- inode->i_fop = &ext4_file_operations;
+ if (ext4_use_xip(inode->i_sb))
+ inode->i_fop = &ext4_xip_file_operations;
+ else
+ inode->i_fop = &ext4_file_operations;
ext4_set_aops(inode);
err = ext4_add_nondir(handle, dentry, inode);
if (!err && IS_DIRSYNC(dir))
@@ -2314,7 +2318,10 @@ retry:
err = PTR_ERR(inode);
if (!IS_ERR(inode)) {
inode->i_op = &ext4_file_inode_operations;
- inode->i_fop = &ext4_file_operations;
+ if (ext4_use_xip(inode->i_sb))
+ inode->i_fop = &ext4_xip_file_operations;
+ else
+ inode->i_fop = &ext4_file_operations;
ext4_set_aops(inode);
d_tmpfile(dentry, inode);
err = ext4_orphan_add(handle, inode);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 2c2e6cb..18e70d2 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -50,6 +50,7 @@
#include "xattr.h"
#include "acl.h"
#include "mballoc.h"
+#include "xip.h"
#define CREATE_TRACE_POINTS
#include <trace/events/ext4.h>
@@ -1143,7 +1144,7 @@ enum {
Opt_inode_readahead_blks, Opt_journal_ioprio,
Opt_dioread_nolock, Opt_dioread_lock,
Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
- Opt_max_dir_size_kb,
+ Opt_max_dir_size_kb, Opt_xip,
};
static const match_table_t tokens = {
@@ -1224,6 +1225,7 @@ static const match_table_t tokens = {
{Opt_removed, "reservation"}, /* mount option from ext2/3 */
{Opt_removed, "noreservation"}, /* mount option from ext2/3 */
{Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
+ {Opt_xip, "xip"},
{Opt_err, NULL},
};
@@ -1417,6 +1419,7 @@ static const struct mount_opts {
{Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},
{Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
{Opt_max_dir_size_kb, 0, MOPT_GTE0},
+ {Opt_xip, EXT4_MOUNT_XIP, MOPT_SET},
{Opt_err, 0, 0}
};
@@ -1619,6 +1622,10 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
}
sbi->s_jquota_fmt = m->mount_opt;
#endif
+#ifndef CONFIG_EXT4_FS_XIP
+ } else if (token == Opt_xip) {
+ ext4_msg(sb, KERN_INFO, "xip option not supported");
+#endif
} else {
if (!args->from)
arg = 1;
@@ -3525,11 +3532,19 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
}
if (test_opt(sb, DELALLOC))
clear_opt(sb, DELALLOC);
+ if (test_opt(sb, XIP)) {
+ ext4_msg(sb, KERN_ERR, "can't mount with "
+ "both data=journal and xip");
+ goto failed_mount;
+ }
}
sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
(test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
+ ext4_xip_verify_sb(sb); /* see if bdev supports xip, unset
+ EXT4_MOUNT_XIP if not */
+
if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
(EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
@@ -3576,6 +3591,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
goto failed_mount;
}
+ if (ext4_use_xip(sb) && blocksize != PAGE_SIZE) {
+ if (!silent)
+ ext4_msg(sb, KERN_ERR,
+ "error: unsupported blocksize for xip");
+ goto failed_mount;
+ }
+
if (sb->s_blocksize != blocksize) {
/* Validate the filesystem blocksize */
if (!sb_set_blocksize(sb, blocksize)) {
@@ -4707,6 +4729,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
struct ext4_super_block *es;
struct ext4_sb_info *sbi = EXT4_SB(sb);
unsigned long old_sb_flags;
+ unsigned long old_mount_opt = sbi->s_mount_opt;
struct ext4_mount_options old_opts;
int enable_quota = 0;
ext4_group_t g;
@@ -4773,7 +4796,23 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
(test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
+ ext4_xip_verify_sb(sb); /* see if bdev supports xip, unset
+ EXT4_MOUNT_XIP if not */
+
+ if (ext4_use_xip(sb) && sb->s_blocksize != PAGE_SIZE) {
+ ext4_msg(sb, KERN_WARNING,
+ "warning: unsupported blocksize for xip");
+ err = -EINVAL;
+ goto restore_opts;
+ }
+
es = sbi->s_es;
+ if ((sbi->s_mount_opt ^ old_mount_opt) & EXT4_MOUNT_XIP) {
+ ext4_msg(sb, KERN_WARNING, "warning: refusing change of "
+ "xip flag with busy inodes while remounting");
+ sbi->s_mount_opt &= ~EXT4_MOUNT_XIP;
+ sbi->s_mount_opt |= old_mount_opt & EXT4_MOUNT_XIP;
+ }
if (sbi->s_journal) {
ext4_init_journal_params(sb, sbi->s_journal);
diff --git a/fs/ext4/xip.c b/fs/ext4/xip.c
new file mode 100644
index 0000000..e0a430a
--- /dev/null
+++ b/fs/ext4/xip.c
@@ -0,0 +1,91 @@
+/*
+ * linux/fs/ext4/xip.c
+ *
+ * Copyright (C) 2005 IBM Corporation
+ * Author: Carsten Otte (cotte@...ibm.com)
+ */
+
+#include <linux/mm.h>
+#include <linux/fs.h>
+#include <linux/genhd.h>
+#include <linux/buffer_head.h>
+#include <linux/blkdev.h>
+#include "ext4.h"
+#include "xip.h"
+
+static inline int
+__inode_direct_access(struct inode *inode, sector_t block,
+ void **kaddr, unsigned long *pfn)
+{
+ struct block_device *bdev = inode->i_sb->s_bdev;
+ const struct block_device_operations *ops = bdev->bd_disk->fops;
+ sector_t sector;
+
+ sector = block * (PAGE_SIZE / 512); /* ext4 block to bdev sector */
+
+ BUG_ON(!ops->direct_access);
+ return ops->direct_access(bdev, sector, kaddr, pfn);
+}
+
+static inline int
+__ext4_get_block(struct inode *inode, pgoff_t pgoff, int create,
+ sector_t *result)
+{
+ struct buffer_head tmp;
+ int rc;
+
+ memset(&tmp, 0, sizeof(struct buffer_head));
+ tmp.b_size = inode->i_sb->s_blocksize;
+ rc = ext4_get_block(inode, pgoff, &tmp, create);
+ *result = tmp.b_blocknr;
+
+ /* did we get a sparse block (hole in the file)? */
+ if (!tmp.b_blocknr && !rc) {
+ BUG_ON(create);
+ rc = -ENODATA;
+ }
+
+ return rc;
+}
+
+int
+ext4_clear_xip_target(struct inode *inode, sector_t block)
+{
+ void *kaddr;
+ unsigned long pfn;
+ int rc;
+
+ rc = __inode_direct_access(inode, block, &kaddr, &pfn);
+ if (!rc)
+ clear_page(kaddr);
+ return rc;
+}
+
+void ext4_xip_verify_sb(struct super_block *sb)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+ if ((sbi->s_mount_opt & EXT4_MOUNT_XIP) &&
+ !sb->s_bdev->bd_disk->fops->direct_access) {
+ sbi->s_mount_opt &= (~EXT4_MOUNT_XIP);
+ ext4_msg(sb, KERN_WARNING,
+ "warning: ignoring xip option - "
+ "not supported by bdev");
+ }
+}
+
+int ext4_get_xip_mem(struct address_space *mapping, pgoff_t pgoff, int create,
+ void **kmem, unsigned long *pfn)
+{
+ int rc;
+ sector_t block;
+
+ /* first, retrieve the sector number */
+ rc = __ext4_get_block(mapping->host, pgoff, create, &block);
+ if (rc)
+ return rc;
+
+ /* retrieve address of the target data */
+ rc = __inode_direct_access(mapping->host, block, kmem, pfn);
+ return rc;
+}
diff --git a/fs/ext4/xip.h b/fs/ext4/xip.h
new file mode 100644
index 0000000..1d992ca
--- /dev/null
+++ b/fs/ext4/xip.h
@@ -0,0 +1,26 @@
+/*
+ * linux/fs/ext4/xip.h
+ *
+ * Copyright (C) 2005 IBM Corporation
+ * Author: Carsten Otte (cotte@...ibm.com)
+ */
+
+#ifdef CONFIG_EXT4_FS_XIP
+extern void ext4_xip_verify_sb(struct super_block *);
+extern int ext4_clear_xip_target(struct inode *, sector_t);
+
+static inline int ext4_use_xip(struct super_block *sb)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+ return sbi->s_mount_opt & EXT4_MOUNT_XIP;
+}
+int ext4_get_xip_mem(struct address_space *, pgoff_t, int,
+ void **, unsigned long *);
+#define mapping_is_xip(map) unlikely(map->a_ops->get_xip_mem)
+#else
+#define mapping_is_xip(map) 0
+#define ext4_xip_verify_sb(sb) do { } while (0)
+#define ext4_use_xip(sb) 0
+#define ext4_clear_xip_target(inode, chain) 0
+#define ext4_get_xip_mem NULL
+#endif
--
1.8.4.357.g8d83871
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists