Skip to contentSkip to conversation

ext4: add nombcache mount option

PATCH In review Tahsin Erdogan 3 participants 4 messages Jun 20, 2017 – Jun 22, 2017 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 32/32 ext4: add nombcache mount option

The main purpose of mb cache is to achieve deduplication in extended attributes. In use cases where opportunity for deduplication is unlikely, it only adds overhead.

Add a mount option to explicitly turn off mb cache.

---
 fs/ext4/ext4.h  |  1 +
 fs/ext4/super.c | 33 ++++++++++++++++++++++-----------
 fs/ext4/xattr.c | 55 ++++++++++++++++++++++++++++++++++++-------------------
 3 files changed, 59 insertions(+), 30 deletions(-)
fs/ext4/ext4.h +1 -0
index 59e9488c4876..21aca1f87187 100644
@@ -1149,6 +1149,7 @@ struct ext4_inode_info {
 #define EXT4_MOUNT_DIOREAD_NOLOCK	0x400000 /* Enable support for dio read nolocking */
 #define EXT4_MOUNT_JOURNAL_CHECKSUM	0x800000 /* Journal checksums */
 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT	0x1000000 /* Journal Async Commit */
+#define EXT4_MOUNT_NO_MBCACHE		0x2000000 /* No mbcache usage */
 #define EXT4_MOUNT_DELALLOC		0x8000000 /* Delalloc support */
 #define EXT4_MOUNT_DATA_ERR_ABORT	0x10000000 /* Abort on file data write */
 #define EXT4_MOUNT_BLOCK_VALIDITY	0x20000000 /* Block validity checking */
fs/ext4/super.c +22 -11
index 4b15bf674d45..4262a1b9b5b2 100644
@@ -1336,7 +1336,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_nojournal_checksum,
+	Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
 };
 
 static const match_table_t tokens = {
@@ -1419,6 +1419,7 @@ static const match_table_t tokens = {
 	{Opt_noinit_itable, "noinit_itable"},
 	{Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
 	{Opt_test_dummy_encryption, "test_dummy_encryption"},
+	{Opt_nombcache, "nombcache"},
 	{Opt_removed, "check=none"},	/* mount option from ext2/3 */
 	{Opt_removed, "nocheck"},	/* mount option from ext2/3 */
 	{Opt_removed, "reservation"},	/* mount option from ext2/3 */
@@ -1626,6 +1627,7 @@ static const struct mount_opts {
 	{Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
 	{Opt_max_dir_size_kb, 0, MOPT_GTE0},
 	{Opt_test_dummy_encryption, 0, MOPT_GTE0},
+	{Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
 	{Opt_err, 0, 0}
 };
 
@@ -4080,19 +4082,22 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	sbi->s_journal->j_commit_callback = ext4_journal_commit_callback;
 
 no_journal:
-	sbi->s_mb_cache = ext4_xattr_create_cache();
-	if (!sbi->s_mb_cache) {
-		ext4_msg(sb, KERN_ERR, "Failed to create an mb_cache");
-		goto failed_mount_wq;
-	}
-
-	if (ext4_has_feature_ea_inode(sb)) {
-		sbi->s_ea_inode_cache = ext4_xattr_create_cache();
-		if (!sbi->s_ea_inode_cache) {
+	if (!test_opt(sb, NO_MBCACHE)) {
+		sbi->s_mb_cache = ext4_xattr_create_cache();
+		if (!sbi->s_mb_cache) {
 			ext4_msg(sb, KERN_ERR,
-				 "Failed to create an s_ea_inode_cache");
+				 "Failed to create xattr block mb_cache");
 			goto failed_mount_wq;
 		}
+
+		if (ext4_has_feature_ea_inode(sb)) {
+			sbi->s_ea_inode_cache = ext4_xattr_create_cache();
+			if (!sbi->s_ea_inode_cache) {
+				ext4_msg(sb, KERN_ERR,
+					 "Failed to create ea_inode mb_cache");
+				goto failed_mount_wq;
+			}
+		}
 	}
 
 	if ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&
@@ -4989,6 +4994,12 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
 		}
 	}
 
+	if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_NO_MBCACHE) {
+		ext4_msg(sb, KERN_ERR, "can't enable nombcache during remount");
+		err = -EINVAL;
+		goto restore_opts;
+	}
+
 	if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_DAX) {
 		ext4_msg(sb, KERN_WARNING, "warning: refusing change of "
 			"dax flag with busy inodes while remounting");
fs/ext4/xattr.c +36 -19

121 lines not on this page · raw message

Signature · 1 line
2.13.1.518.g3df882009-goog
#1 lore raw
Quoted 20 lines · Tahsin Erdogan

The main purpose of mb cache is to achieve deduplication in extended attributes. In use cases where opportunity for deduplication is unlikely, it only adds overhead.

Add a mount option to explicitly turn off mb cache.

---

fs/ext4/ext4.h  |  1 +
fs/ext4/super.c | 33 ++++++++++++++++++++++-----------
fs/ext4/xattr.c | 55 ++++++++++++++++++++++++++++++++++++-------------------
3 files changed, 59 insertions(+), 30 deletions(-)
fs/ext4/ext4.h +0 -0
index 59e9488c4876..21aca1f87187 100644

fs/ext4/ext4.h struct ext4_inode_info { · line 1152

Quoted 4 lines
fs/ext4/ext4.h +1 -0
@@ -1149,6 +1149,7 @@ struct ext4_inode_info {
 #define EXT4_MOUNT_DIOREAD_NOLOCK	0x400000 /* Enable support for dio read nolocking */
 #define EXT4_MOUNT_JOURNAL_CHECKSUM	0x800000 /* Journal checksums */
 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT	0x1000000 /* Journal Async Commit */
+#define EXT4_MOUNT_NO_MBCACHE		0x2000000 /* No mbcache usage */

We've been using 0x00001 for EXT4_MOUNT_NO_MBCACHE.

Quoted 17 lines
fs/ext4/ext4.h +0 -0
 #define EXT4_MOUNT_DELALLOC		0x8000000 /* Delalloc support */
 #define EXT4_MOUNT_DATA_ERR_ABORT	0x10000000 /* Abort on file data write */
 #define EXT4_MOUNT_BLOCK_VALIDITY	0x20000000 /* Block validity checking */
fs/ext4/super.c +1 -1
index 4b15bf674d45..4262a1b9b5b2 100644
@@ -1336,7 +1336,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_nojournal_checksum,
+	Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
 };
 
 static const match_table_t tokens = {

fs/ext4/super.c static const match_table_t tokens = { · line 1422

Quoted 4 lines
fs/ext4/super.c +1 -0
@@ -1419,6 +1419,7 @@ static const match_table_t tokens = {
 	{Opt_noinit_itable, "noinit_itable"},
 	{Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
 	{Opt_test_dummy_encryption, "test_dummy_encryption"},
+	{Opt_nombcache, "nombcache"},

For compatibility, please also add:

	{Opt_nombcache, "no_mbcache"},
Quoted 16 lines
fs/ext4/super.c +1 -0
 	{Opt_removed, "check=none"},	/* mount option from ext2/3 */
 	{Opt_removed, "nocheck"},	/* mount option from ext2/3 */
 	{Opt_removed, "reservation"},	/* mount option from ext2/3 */
@@ -1626,6 +1627,7 @@ static const struct mount_opts {
 	{Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
 	{Opt_max_dir_size_kb, 0, MOPT_GTE0},
 	{Opt_test_dummy_encryption, 0, MOPT_GTE0},
+	{Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
 	{Opt_err, 0, 0}
 };
 
@@ -4080,19 +4082,22 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	sbi->s_journal->j_commit_callback = ext4_journal_commit_callback;
 

no_journal:

fs/ext4/super.c +0 -1
-	sbi->s_mb_cache = ext4_xattr_create_cache();

fs/ext4/super.c static int ext4_fill_super(struct super_block *sb, void *data, int silent) · line 4086

Quoted 10 lines
fs/ext4/super.c +2 -8
-	if (!sbi->s_mb_cache) {
-		ext4_msg(sb, KERN_ERR, "Failed to create an mb_cache");
-		goto failed_mount_wq;
-	}
-
-	if (ext4_has_feature_ea_inode(sb)) {
-		sbi->s_ea_inode_cache = ext4_xattr_create_cache();
-		if (!sbi->s_ea_inode_cache) {
+	if (!test_opt(sb, NO_MBCACHE)) {
+		sbi->s_mb_cache = ext4_xattr_create_cache();

Should be named "s_mb_ea_block_cache" or similar?

fs/ext4/super.c static int ext4_fill_super(struct super_block *sb, void *data, int silent) · line 4094

Quoted 9 lines
fs/ext4/super.c +1 -0
+		if (!sbi->s_mb_cache) {
			ext4_msg(sb, KERN_ERR,
fs/ext4/super.c +1 -1
-				 "Failed to create an s_ea_inode_cache");
+				 "Failed to create xattr block mb_cache");
			goto failed_mount_wq;
		}
fs/ext4/super.c +3 -0
+
+		if (ext4_has_feature_ea_inode(sb)) {
+			sbi->s_ea_inode_cache = ext4_xattr_create_cache();

Should be named "s_mb_ea_inode_cache", or alternately use "s_ea_block_cache" above?

Quoted 10 lines
fs/ext4/super.c +6 -0
+			if (!sbi->s_ea_inode_cache) {
+				ext4_msg(sb, KERN_ERR,
+					 "Failed to create ea_inode mb_cache");
+				goto failed_mount_wq;
+			}
+		}
	}

	if ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&

fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, · line 5001

Quoted 8 lines
fs/ext4/super.c +5 -0
@@ -4989,6 +4994,12 @@ static int ext4_remount(struct super_block *sb, int *flags,
 		}
 	}
 
+	if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_NO_MBCACHE) {
+		ext4_msg(sb, KERN_ERR, "can't enable nombcache during remount");
+		err = -EINVAL;
+		goto restore_opts;
+	}

It appears that this restriction also applies to enabling mbcache during remount as well, so the message should be updated? In particular, if NO_MBCACHE is currently set but isn't passed during the remount then this will always cause the remount to fail. That makes it harder for users to just run something like "mount -o remount,ro".

It seems we are a bit inconsistent with how we handle changing mount options. In some cases, if an option is set to be enabled but cannot be, it is actually ignored (e.g. DAX, JOURNAL_CHECKSUM). In other cases this returns an error.

In this case it is probably easiest to just ignore the change to this option, as is done with JOURNAL_CHECKSUM and DAX.

fs/ext4/xattr.c ext4_xattr_release_block(handle_t *handle, · line 1207

Quoted 11 lines
fs/ext4/super.c +0 -0
 	if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_DAX) {
 		ext4_msg(sb, KERN_WARNING, "warning: refusing change of "
 			"dax flag with busy inodes while remounting");
fs/ext4/xattr.c +0 -0
index 9d1b600dc827..65ead540c684 100644
@@ -1200,11 +1206,13 @@ ext4_xattr_release_block(handle_t *handle,
 		if (ref == EXT4_XATTR_REFCOUNT_MAX - 1) {
 			struct mb_cache_entry *ce;

This could go inside the "if (ext4_mb_cache)" block.

Quoted 4 lines
fs/ext4/xattr.c +0 -4
-			ce = mb_cache_entry_get(ext4_mb_cache, hash,
-						bh->b_blocknr);
-			if (ce) {
-				ce->e_reusable = 1;

fs/ext4/xattr.c ext4_xattr_release_block(handle_t *handle, struct inode *inode, · line 1217

Quoted 10 lines
fs/ext4/xattr.c +7 -1
-				mb_cache_entry_put(ext4_mb_cache, ce);
+			if (ext4_mb_cache) {
+				ce = mb_cache_entry_get(ext4_mb_cache, hash,
+							bh->b_blocknr);
+				if (ce) {
+					ce->e_reusable = 1;
+					mb_cache_entry_put(ext4_mb_cache, ce);
+				}
 			}
 		}

Cheers, Andreas

#2 lore raw
Quoted 11 lines

fs/ext4/super.c static int ext4_remount(struct super_block *sb, int *flags, char *data) · line 5001

Quoted 5 lines
fs/ext4/super.c +5 -0
+     if ((sbi->s_mount_opt ^ old_opts.s_mount_opt) & EXT4_MOUNT_NO_MBCACHE) {
+             ext4_msg(sb, KERN_ERR, "can't enable nombcache during remount");
+             err = -EINVAL;
+             goto restore_opts;
+     }

It appears that this restriction also applies to enabling mbcache during remount as well, so the message should be updated? In particular, if NO_MBCACHE is currently set but isn't passed during the remount then this will always cause the remount to fail. That makes it harder for users to just run something like "mount -o remount,ro".

Remount option handling is a bit strange. If an option is not specified, it is not automatically cleared in sbi->s_mount_opt. So, once nombcache option is set in the original mount, it is not possible to clear it. I don't know whether this option handling behavior in ext4 is deliberate but because of that, the mount -o remount,ro does not result in a mount failure. The check above is effectively only to protect against going from not having nombcache option to having nombcache option, because the opposite is not possible.

Following shows how "debug" option remains set even though it wasn't specified during remount:

# mount -o debug /dev/sdb /mnt/sdb
# mount | grep sdb
/dev/sdb on /mnt/sdb type ext4 (rw,debug)
# cat /proc/mounts | grep sdb
/dev/sdb /mnt/sdb ext4 rw,relatime,debug,data=ordered 0 0
# mount -o remount,ro /dev/sdb /mnt/sdb
# mount | grep sdb
/dev/sdb on /mnt/sdb type ext4 (ro)
# cat /proc/mounts | grep sdb
/dev/sdb /mnt/sdb ext4 ro,relatime,debug,data=ordered 0 0
maintainer
#3 lore raw
Quoted 8 lines · Tahsin Erdogan

Remount option handling is a bit strange. If an option is not specified, it is not automatically cleared in sbi->s_mount_opt. So, once nombcache option is set in the original mount, it is not possible to clear it. I don't know whether this option handling behavior in ext4 is deliberate but because of that, the mount -o remount,ro does not result in a mount failure. The check above is effectively only to protect against going from not having nombcache option to having nombcache option, because the opposite is not possible.

The option handling behavior is deliberate, yes. This is why we have the mount options "lazytime" and "nolazytime", "discard" and "nodiscard", "barrier" and "nobarrier", etc.

-Ted