Skip to contentSkip to conversation

erofs: reuse superblock for file-backed mounts

PATCH Superseded Giuseppe Scrivano 3 participants 7 messages Jul 30 – Jul 31

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs: reuse superblock for file-backed mounts

When the same file is mounted multiple times (via path or fd), reuse the existing superblock instead of creating a new one. This allows multiple mounts of the same image to share in-kernel data structures more efficiently.

The backing file is identified by its inode and fsoffset. If mount options conflict, a separate superblock is created transparently as a fallback.

Tested by mounting a 177M Fedora EROFS image 20 times with full traversal:

```
\#!/bin/sh
IMG=${1:-/root/fedora.erofs}
N=20
DIR=$(mktemp -d)
trap "umount $DIR/m* 2>/dev/null; rm -rf $DIR" EXIT

sync; echo 3 > /proc/sys/vm/drop_caches
INODES_BEFORE=$(grep erofs_inode /proc/slabinfo | awk '{print $2}')
MEM_BEFORE=$(grep ^Slab: /proc/meminfo | awk '{print $2}')

for i in $(seq 1 $N); do mkdir $DIR/m$i && mount -t erofs "$IMG" $DIR/m$i && find $DIR/m$i > /dev/null; done

echo "Superblocks: $(grep $DIR /proc/self/mountinfo | awk '{print $3}' | sort -u | wc -l)"
echo "erofs_inode delta: +$(( $(grep erofs_inode /proc/slabinfo | awk '{print $2}') - INODES_BEFORE ))"
echo "Slab delta: +$(( $(grep ^Slab: /proc/meminfo | awk '{print $2}') - MEM_BEFORE )) kB"
```

unpatched kernel:

Superblocks: 20
erofs_inode delta: +46368
Slab delta: +39952 kB
0.08user 0.82system 0:00.98elapsed 93%CPU (0avgtext+0avgdata 4796maxresident)k 19168inputs+10304outputs (24major+16672minor)pagefaults 0swaps

patched kernel:

Superblocks: 1
erofs_inode delta: +2044
Slab delta: +1088 kB
0.07user 0.21system 0:00.31elapsed 91%CPU (0avgtext+0avgdata 4848maxresident)k 19024inputs+6784outputs (25major+16810minor)pagefaults 0swaps

The time difference shows that sharing the superblock also benefits the page cache and inode cache, as subsequent mounts of the same image avoid re-reading the backing file. This is particularly useful for container hosts running multiple containers from the same base image.

---
 Documentation/filesystems/erofs.rst |  4 +++
 fs/erofs/super.c                    | 44 +++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 2 deletions(-)
Documentation/filesystems/erofs.rst +4 -0
index 774e8b236d09..ef6785035b26 100644
@@ -154,6 +154,10 @@ Only regular files are accepted as backing files; to mount an image that
 resides on a block device, use the traditional block device mount path
 instead.
 
+When the same backing file is mounted more than once with compatible
+mount options, the kernel reuses the existing superblock.  If mount
+options conflict, a separate superblock is created transparently.
+
 Sysfs Entries
 =============
 
fs/erofs/super.c +42 -2

62 lines not on this page · raw message

Signature · 1 line
2.55.0
#1 lore raw
Quoted 46 lines · Giuseppe Scrivano

When the same file is mounted multiple times (via path or fd), reuse the existing superblock instead of creating a new one. This allows multiple mounts of the same image to share in-kernel data structures more efficiently.

The backing file is identified by its inode and fsoffset. If mount options conflict, a separate superblock is created transparently as a fallback.

Tested by mounting a 177M Fedora EROFS image 20 times with full traversal:

```
\#!/bin/sh
IMG=${1:-/root/fedora.erofs}
N=20
DIR=$(mktemp -d)
trap "umount $DIR/m* 2>/dev/null; rm -rf $DIR" EXIT

sync; echo 3 > /proc/sys/vm/drop_caches
INODES_BEFORE=$(grep erofs_inode /proc/slabinfo | awk '{print $2}')
MEM_BEFORE=$(grep ^Slab: /proc/meminfo | awk '{print $2}')

for i in $(seq 1 $N); do mkdir $DIR/m$i && mount -t erofs "$IMG" $DIR/m$i && find $DIR/m$i > /dev/null; done

echo "Superblocks: $(grep $DIR /proc/self/mountinfo | awk '{print $3}' | sort -u | wc -l)"
echo "erofs_inode delta: +$(( $(grep erofs_inode /proc/slabinfo | awk '{print $2}') - INODES_BEFORE ))"
echo "Slab delta: +$(( $(grep ^Slab: /proc/meminfo | awk '{print $2}') - MEM_BEFORE )) kB"
```

unpatched kernel:

Superblocks: 20
erofs_inode delta: +46368
Slab delta: +39952 kB
0.08user 0.82system 0:00.98elapsed 93%CPU (0avgtext+0avgdata 4796maxresident)k 19168inputs+10304outputs (24major+16672minor)pagefaults 0swaps

patched kernel:

Superblocks: 1
erofs_inode delta: +2044
Slab delta: +1088 kB
0.07user 0.21system 0:00.31elapsed 91%CPU (0avgtext+0avgdata 4848maxresident)k 19024inputs+6784outputs (25major+16810minor)pagefaults 0swaps

Quoted 4 lines

The time difference shows that sharing the superblock also benefits the page cache and inode cache, as subsequent mounts of the same image avoid re-reading the backing file. This is particularly useful for container hosts running multiple containers from the same base image.

Doesn't this approach break-down as soon as you get to change SB flags (through e.g mount -o remount)? It will change superblock flags for all of them, right?

(I don't think you can switch off the superblock transparently on a reconfigure?)

Signature · 1 line
Pedro
#2 lore raw
Quoted 53 lines · Pedro Falcato
Quoted 47 lines · Giuseppe Scrivano

When the same file is mounted multiple times (via path or fd), reuse the existing superblock instead of creating a new one. This allows multiple mounts of the same image to share in-kernel data structures more efficiently.

The backing file is identified by its inode and fsoffset. If mount options conflict, a separate superblock is created transparently as a fallback.

Tested by mounting a 177M Fedora EROFS image 20 times with full traversal:

```
\#!/bin/sh
IMG=${1:-/root/fedora.erofs}
N=20
DIR=$(mktemp -d)
trap "umount $DIR/m* 2>/dev/null; rm -rf $DIR" EXIT

sync; echo 3 > /proc/sys/vm/drop_caches
INODES_BEFORE=$(grep erofs_inode /proc/slabinfo | awk '{print $2}')
MEM_BEFORE=$(grep ^Slab: /proc/meminfo | awk '{print $2}')

for i in $(seq 1 $N); do mkdir $DIR/m$i && mount -t erofs "$IMG"
$DIR/m$i && find $DIR/m$i > /dev/null; done

echo "Superblocks: $(grep $DIR /proc/self/mountinfo | awk '{print $3}' | sort -u | wc -l)"
echo "erofs_inode delta: +$(( $(grep erofs_inode /proc/slabinfo | awk '{print $2}') - INODES_BEFORE ))"
echo "Slab delta: +$(( $(grep ^Slab: /proc/meminfo | awk '{print $2}') - MEM_BEFORE )) kB"
```

unpatched kernel:

Superblocks: 20
erofs_inode delta: +46368
Slab delta: +39952 kB
0.08user 0.82system 0:00.98elapsed 93%CPU (0avgtext+0avgdata 4796maxresident)k 19168inputs+10304outputs (24major+16672minor)pagefaults 0swaps

patched kernel:

Superblocks: 1
erofs_inode delta: +2044
Slab delta: +1088 kB
0.07user 0.21system 0:00.31elapsed 91%CPU (0avgtext+0avgdata 4848maxresident)k 19024inputs+6784outputs (25major+16810minor)pagefaults 0swaps

Quoted 4 lines

The time difference shows that sharing the superblock also benefits the page cache and inode cache, as subsequent mounts of the same image avoid re-reading the backing file. This is particularly useful for container hosts running multiple containers from the same base image.

Quoted 5 lines

Doesn't this approach break-down as soon as you get to change SB flags (through e.g mount -o remount)? It will change superblock flags for all of them, right?

(I don't think you can switch off the superblock transparently on a reconfigure?)

This is the same preexisting behavior for block device mounts. That said, I realize this can feel confusing since EROFS is not a block device and allowed this so far.

One way to solve this could be an explicit mount option "share_sb" that is opt-in and, once set, blocks any remount operations. Would that work?

Regards,
Giuseppe

#3 lore raw
Quoted 61 lines · Giuseppe Scrivano
Quoted 53 lines · Pedro Falcato
Quoted 47 lines · Giuseppe Scrivano

When the same file is mounted multiple times (via path or fd), reuse the existing superblock instead of creating a new one. This allows multiple mounts of the same image to share in-kernel data structures more efficiently.

The backing file is identified by its inode and fsoffset. If mount options conflict, a separate superblock is created transparently as a fallback.

Tested by mounting a 177M Fedora EROFS image 20 times with full traversal:

```
\#!/bin/sh
IMG=${1:-/root/fedora.erofs}
N=20
DIR=$(mktemp -d)
trap "umount $DIR/m* 2>/dev/null; rm -rf $DIR" EXIT

sync; echo 3 > /proc/sys/vm/drop_caches
INODES_BEFORE=$(grep erofs_inode /proc/slabinfo | awk '{print $2}')
MEM_BEFORE=$(grep ^Slab: /proc/meminfo | awk '{print $2}')

for i in $(seq 1 $N); do mkdir $DIR/m$i && mount -t erofs "$IMG"
$DIR/m$i && find $DIR/m$i > /dev/null; done

echo "Superblocks: $(grep $DIR /proc/self/mountinfo | awk '{print $3}' | sort -u | wc -l)"
echo "erofs_inode delta: +$(( $(grep erofs_inode /proc/slabinfo | awk '{print $2}') - INODES_BEFORE ))"
echo "Slab delta: +$(( $(grep ^Slab: /proc/meminfo | awk '{print $2}') - MEM_BEFORE )) kB"
```

unpatched kernel:

Superblocks: 20
erofs_inode delta: +46368
Slab delta: +39952 kB
0.08user 0.82system 0:00.98elapsed 93%CPU (0avgtext+0avgdata 4796maxresident)k 19168inputs+10304outputs (24major+16672minor)pagefaults 0swaps

patched kernel:

Superblocks: 1
erofs_inode delta: +2044
Slab delta: +1088 kB
0.07user 0.21system 0:00.31elapsed 91%CPU (0avgtext+0avgdata 4848maxresident)k 19024inputs+6784outputs (25major+16810minor)pagefaults 0swaps

Quoted 4 lines

The time difference shows that sharing the superblock also benefits the page cache and inode cache, as subsequent mounts of the same image avoid re-reading the backing file. This is particularly useful for container hosts running multiple containers from the same base image.

Quoted 5 lines

Doesn't this approach break-down as soon as you get to change SB flags (through e.g mount -o remount)? It will change superblock flags for all of them, right?

(I don't think you can switch off the superblock transparently on a reconfigure?)

Quoted 7 lines

This is the same preexisting behavior for block device mounts. That said, I realize this can feel confusing since EROFS is not a block device and allowed this so far.

One way to solve this could be an explicit mount option "share_sb" that is opt-in and, once set, blocks any remount operations. Would that work?

Would something like the following fixup on top of the previous patch be acceptable (suggestions for better names are welcome)?

Thanks,
Giuseppe

fs/erofs/internal.h +1 -0
index 580f8d9f14e7..ac26daf4f78a 100644
@@ -156,6 +156,7 @@ struct erofs_sb_info {
 #define EROFS_MOUNT_DAX_NEVER		0x00000080
 #define EROFS_MOUNT_DIRECT_IO		0x00000100
 #define EROFS_MOUNT_INODE_SHARE		0x00000200
+#define EROFS_MOUNT_SHARE_SB		0x00000400
 
 #define clear_opt(opt, option)	((opt)->mount_opt &= ~EROFS_MOUNT_##option)
 #define set_opt(opt, option)	((opt)->mount_opt |= EROFS_MOUNT_##option)
fs/erofs/super.c +13 -1
index cbd76727f0d3..dd2a351811c8 100644
@@ -386,7 +386,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)
 enum {
 	Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum,
 	Opt_device, Opt_domain_id, Opt_directio, Opt_fsoffset, Opt_inode_share,
-	Opt_source,
+	Opt_source, Opt_share_sb,
 };
 
 static const struct constant_table erofs_param_cache_strategy[] = {
@@ -414,6 +414,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
 	fsparam_flag_no("directio",		Opt_directio),
 	fsparam_u64("fsoffset",			Opt_fsoffset),
 	fsparam_flag("inode_share",		Opt_inode_share),
+	fsparam_flag("share_sb",		Opt_share_sb),
 	fsparam_file_or_string("source",	Opt_source),
 	{}
 };
@@ -560,6 +561,12 @@ static int erofs_fc_parse_param(struct fs_context *fc,
 		else
 			set_opt(&sbi->opt, INODE_SHARE);
 		break;
+	case Opt_share_sb:
+		if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE))
+			errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
+		else
+			set_opt(&sbi->opt, SHARE_SB);
+		break;
 	case Opt_source:
 		return erofs_fc_parse_source(fc, param);
 	}
@@ -798,6 +805,8 @@ static int erofs_fc_test_file_super(struct super_block *sb,
 		return 0;
 	if (!sbi->dif0.file || !new_sbi->dif0.file)
 		return 0;
+	if (!test_opt(&new_sbi->opt, SHARE_SB))
+		return 0;
 	return file_inode(sbi->dif0.file) == file_inode(new_sbi->dif0.file) &&
 	       sbi->dif0.fsoff == new_sbi->dif0.fsoff &&
 	       sbi->opt.mount_opt == new_sbi->opt.mount_opt &&
@@ -874,6 +883,9 @@ static int erofs_fc_reconfigure(struct fs_context *fc)
 
 	DBG_BUGON(!sb_rdonly(sb));
 
+	if (test_opt(&sbi->opt, SHARE_SB))
+		return -EBUSY;
+
 	if (new_sbi->domain_id)
 		erofs_info(sb, "ignoring reconfiguration for domain_id.");
 
#4 lore raw
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The time difference shows that sharing the superblock also benefits the page cache and inode cache, as subsequent mounts of the same image avoid re-reading the backing file. This is particularly useful for container hosts running multiple containers from the same base image.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Doesn't this approach break-down as soon as you get to change SB flags (through e.g mount -o remount)? It will change superblock flags for all of them, right?

(I don't think you can switch off the superblock transparently on a reconfigure?)

This is the same preexisting behavior for block device mounts. That

Yeah, and it sucks ass. :)
Only an incompatible vfs-level RO/RW property causes a silent reuse to fail. Otherwise it not possible to detect that a superblock has been created and requested mount options silently ignore.

In other words, doing this unconditionally is incompatible with current userspace.

Btw, I added FSCONFIG_CMD_CREATE_EXCL for this reason which refuses to reuse an existing superblock for filesystems that would otherwise end up sharing a superblock. This way userspace is guaranteed to not silently get filesystem options ignored.

Quoted 9 lines
Quoted 6 lines

said, I realize this can feel confusing since EROFS is not a block device and allowed this so far.

One way to solve this could be an explicit mount option "share_sb" that is opt-in and, once set, blocks any remount operations. Would that work?

Would something like the following fixup on top of the previous patch be acceptable (suggestions for better names are welcome)?

The patch as written still means that a task A creates a new erofs mount with for file F and marks it as shared. Another task B creates new erofs mount expecting to get a new superblock and will end up sharing it with task A instead.

That is still quite the behavior change and could be used to subvert workloads expectations and be used in (odd) attacks.

So if you want sb-sharing you need it to be an admin-level setting or you need to make it a domain the same way page cache sharing for erofs is a domain. IOW, only task that mount with the same domain end up sharing superblocks. Or it's a global setting.

But doing it this way seems problematic to me.

Quoted 71 lines

Thanks,
Giuseppe

fs/erofs/internal.h +1 -0
index 580f8d9f14e7..ac26daf4f78a 100644
@@ -156,6 +156,7 @@ struct erofs_sb_info {
 #define EROFS_MOUNT_DAX_NEVER		0x00000080
 #define EROFS_MOUNT_DIRECT_IO		0x00000100
 #define EROFS_MOUNT_INODE_SHARE		0x00000200
+#define EROFS_MOUNT_SHARE_SB		0x00000400
 
 #define clear_opt(opt, option)	((opt)->mount_opt &= ~EROFS_MOUNT_##option)
 #define set_opt(opt, option)	((opt)->mount_opt |= EROFS_MOUNT_##option)
fs/erofs/super.c +13 -1
index cbd76727f0d3..dd2a351811c8 100644
@@ -386,7 +386,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)
 enum {
 	Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum,
 	Opt_device, Opt_domain_id, Opt_directio, Opt_fsoffset, Opt_inode_share,
-	Opt_source,
+	Opt_source, Opt_share_sb,
 };
 
 static const struct constant_table erofs_param_cache_strategy[] = {
@@ -414,6 +414,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
 	fsparam_flag_no("directio",		Opt_directio),
 	fsparam_u64("fsoffset",			Opt_fsoffset),
 	fsparam_flag("inode_share",		Opt_inode_share),
+	fsparam_flag("share_sb",		Opt_share_sb),
 	fsparam_file_or_string("source",	Opt_source),
 	{}
 };
@@ -560,6 +561,12 @@ static int erofs_fc_parse_param(struct fs_context *fc,
 		else
 			set_opt(&sbi->opt, INODE_SHARE);
 		break;
+	case Opt_share_sb:
+		if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE))
+			errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
+		else
+			set_opt(&sbi->opt, SHARE_SB);
+		break;
 	case Opt_source:
 		return erofs_fc_parse_source(fc, param);
 	}
@@ -798,6 +805,8 @@ static int erofs_fc_test_file_super(struct super_block *sb,
 		return 0;
 	if (!sbi->dif0.file || !new_sbi->dif0.file)
 		return 0;
+	if (!test_opt(&new_sbi->opt, SHARE_SB))
+		return 0;
 	return file_inode(sbi->dif0.file) == file_inode(new_sbi->dif0.file) &&
 	       sbi->dif0.fsoff == new_sbi->dif0.fsoff &&
 	       sbi->opt.mount_opt == new_sbi->opt.mount_opt &&
@@ -874,6 +883,9 @@ static int erofs_fc_reconfigure(struct fs_context *fc)
 
 	DBG_BUGON(!sb_rdonly(sb));
 
+	if (test_opt(&sbi->opt, SHARE_SB))
+		return -EBUSY;
+
 	if (new_sbi->domain_id)
 		erofs_info(sb, "ignoring reconfiguration for domain_id.");
 
#5 lore raw
Quoted 36 lines · Christian Brauner
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The time difference shows that sharing the superblock also benefits the page cache and inode cache, as subsequent mounts of the same image avoid re-reading the backing file. This is particularly useful for container hosts running multiple containers from the same base image.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Doesn't this approach break-down as soon as you get to change SB flags (through e.g mount -o remount)? It will change superblock flags for all of them, right?

(I don't think you can switch off the superblock transparently on a reconfigure?)

This is the same preexisting behavior for block device mounts. That

Yeah, and it sucks ass. :)
Only an incompatible vfs-level RO/RW property causes a silent reuse to fail. Otherwise it not possible to detect that a superblock has been created and requested mount options silently ignore.

In other words, doing this unconditionally is incompatible with current userspace.

Btw, I added FSCONFIG_CMD_CREATE_EXCL for this reason which refuses to reuse an existing superblock for filesystems that would otherwise end up sharing a superblock. This way userspace is guaranteed to not silently get filesystem options ignored.

Quoted 9 lines
Quoted 6 lines

said, I realize this can feel confusing since EROFS is not a block device and allowed this so far.

One way to solve this could be an explicit mount option "share_sb" that is opt-in and, once set, blocks any remount operations. Would that work?

Would something like the following fixup on top of the previous patch be acceptable (suggestions for better names are welcome)?

Quoted 7 lines

The patch as written still means that a task A creates a new erofs mount with for file F and marks it as shared. Another task B creates new erofs mount expecting to get a new superblock and will end up sharing it with task A instead.

That is still quite the behavior change and could be used to subvert workloads expectations and be used in (odd) attacks.

no, my suggestion is that task B gets the same superblock created by A only if it also specifies share_sb.

If the option is not specified, as is the case for existing workloads, then it gets a new superblock even if A is already mounted with share_sb.

The tasks A and B will get the same superblock only if they both specify share_sb. It is fully opt-in, it doesn't affect any other user that doesn't want this behavior.

Regards,
Giuseppe

Quoted 79 lines

So if you want sb-sharing you need it to be an admin-level setting or you need to make it a domain the same way page cache sharing for erofs is a domain. IOW, only task that mount with the same domain end up sharing superblocks. Or it's a global setting.

But doing it this way seems problematic to me.

Quoted 71 lines

Thanks,
Giuseppe

fs/erofs/internal.h +1 -0
index 580f8d9f14e7..ac26daf4f78a 100644
@@ -156,6 +156,7 @@ struct erofs_sb_info {
 #define EROFS_MOUNT_DAX_NEVER		0x00000080
 #define EROFS_MOUNT_DIRECT_IO		0x00000100
 #define EROFS_MOUNT_INODE_SHARE		0x00000200
+#define EROFS_MOUNT_SHARE_SB		0x00000400
 
 #define clear_opt(opt, option)	((opt)->mount_opt &= ~EROFS_MOUNT_##option)
 #define set_opt(opt, option)	((opt)->mount_opt |= EROFS_MOUNT_##option)
fs/erofs/super.c +13 -1
index cbd76727f0d3..dd2a351811c8 100644
@@ -386,7 +386,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)
 enum {
 	Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum,
 	Opt_device, Opt_domain_id, Opt_directio, Opt_fsoffset, Opt_inode_share,
-	Opt_source,
+	Opt_source, Opt_share_sb,
 };
 
 static const struct constant_table erofs_param_cache_strategy[] = {
@@ -414,6 +414,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
 	fsparam_flag_no("directio",		Opt_directio),
 	fsparam_u64("fsoffset",			Opt_fsoffset),
 	fsparam_flag("inode_share",		Opt_inode_share),
+	fsparam_flag("share_sb",		Opt_share_sb),
 	fsparam_file_or_string("source",	Opt_source),
 	{}
 };
@@ -560,6 +561,12 @@ static int erofs_fc_parse_param(struct fs_context *fc,
 		else
 			set_opt(&sbi->opt, INODE_SHARE);
 		break;
+	case Opt_share_sb:
+		if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE))
+			errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
+		else
+			set_opt(&sbi->opt, SHARE_SB);
+		break;
 	case Opt_source:
 		return erofs_fc_parse_source(fc, param);
 	}
@@ -798,6 +805,8 @@ static int erofs_fc_test_file_super(struct super_block *sb,
 		return 0;
 	if (!sbi->dif0.file || !new_sbi->dif0.file)
 		return 0;
+	if (!test_opt(&new_sbi->opt, SHARE_SB))
+		return 0;
 	return file_inode(sbi->dif0.file) == file_inode(new_sbi->dif0.file) &&
 	       sbi->dif0.fsoff == new_sbi->dif0.fsoff &&
 	       sbi->opt.mount_opt == new_sbi->opt.mount_opt &&
@@ -874,6 +883,9 @@ static int erofs_fc_reconfigure(struct fs_context *fc)
 
 	DBG_BUGON(!sb_rdonly(sb));
 
+	if (test_opt(&sbi->opt, SHARE_SB))
+		return -EBUSY;
+
 	if (new_sbi->domain_id)
 		erofs_info(sb, "ignoring reconfiguration for domain_id.");
 
#6 lore raw
Quoted 43 lines · Giuseppe Scrivano
Quoted 41 lines · Christian Brauner
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The time difference shows that sharing the superblock also benefits the page cache and inode cache, as subsequent mounts of the same image avoid re-reading the backing file. This is particularly useful for container hosts running multiple containers from the same base image.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Doesn't this approach break-down as soon as you get to change SB flags (through e.g mount -o remount)? It will change superblock flags for all of them, right?

(I don't think you can switch off the superblock transparently on a reconfigure?)

This is the same preexisting behavior for block device mounts. That

Yeah, and it sucks ass. :)
Only an incompatible vfs-level RO/RW property causes a silent reuse to fail. Otherwise it not possible to detect that a superblock has been created and requested mount options silently ignore.

In other words, doing this unconditionally is incompatible with current userspace.

Btw, I added FSCONFIG_CMD_CREATE_EXCL for this reason which refuses to reuse an existing superblock for filesystems that would otherwise end up sharing a superblock. This way userspace is guaranteed to not silently get filesystem options ignored.

Quoted 9 lines
Quoted 6 lines

said, I realize this can feel confusing since EROFS is not a block device and allowed this so far.

One way to solve this could be an explicit mount option "share_sb" that is opt-in and, once set, blocks any remount operations. Would that work?

Would something like the following fixup on top of the previous patch be acceptable (suggestions for better names are welcome)?

The patch as written still means that a task A creates a new erofs mount with for file F and marks it as shared. Another task B creates new erofs mount expecting to get a new superblock and will end up sharing it with task A instead.

Quoted 5 lines
Quoted 2 lines

That is still quite the behavior change and could be used to subvert workloads expectations and be used in (odd) attacks.

no, my suggestion is that task B gets the same superblock created by A only if it also specifies share_sb.

Yeah, that works.

Quoted 3 lines

If the option is not specified, as is the case for existing workloads, then it gets a new superblock even if A is already mounted with share_sb.

Sounds good! Ship it.