Skip to contentSkip to conversation

fs: inode: shmem: Reduce risk of inum overflow

PATCH Superseded Chris Down 8 participants 27 messages Jan 5, 2020 – Feb 25, 2020

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Chris Down

author
#0 lore raw

v5 cover fs: inode: shmem: Reduce risk of inum overflow

In Facebook production we are seeing heavy i_ino wraparounds on tmpfs. On affected tiers, in excess of 10% of hosts show multiple files with different content and the same inode number, with some servers even having as many as 150 duplicated inode numbers with differing file content.

This causes actual, tangible problems in production. For example, we have complaints from those working on remote caches that their application is reporting cache corruptions because it uses (device, inodenum) to establish the identity of a particular cache object, but because it's not unique any more, the application refuses to continue and reports cache corruption. Even worse, sometimes applications may not even detect the corruption but may continue anyway, causing phantom and hard to debug behaviour.

In general, userspace applications expect that (device, inodenum) should be enough to be uniquely point to one inode, which seems fair enough. One might also need to check the generation, but in this case:

1. That's not currently exposed to userspace (ioctl(...FS_IOC_GETVERSION...) returns ENOTTY on tmpfs);
2. Even with generation, there shouldn't be two live inodes with the same inode number on one device.

In order to mitigate this, we take a two-pronged approach:

1. Moving inum generation from being global to per-sb for tmpfs. This itself allows some reduction in i_ino churn. This works on both 64- and 32- bit machines.
2. Adding inode{64,32} for tmpfs. This fix is supported on machines with 64-bit ino_t only: we allow users to mount tmpfs with a new inode64 option that uses the full width of ino_t, or CONFIG_TMPFS_INODE64.

You can see how this compares to previous related patches which didn't implement this per-superblock:

- https://patchwork.kernel.org/patch/11254001/
- https://patchwork.kernel.org/patch/11023915/

Chris Down (2):
tmpfs: Add per-superblock i_ino support
tmpfs: Support 64-bit inums per-sb

 Documentation/filesystems/tmpfs.txt | 11 ++++
 fs/Kconfig                          | 15 +++++
 include/linux/shmem_fs.h            |  2 +
 mm/shmem.c                          | 94 ++++++++++++++++++++++++++++-
 4 files changed, 121 insertions(+), 1 deletion(-)
Signature · 1 line
2.24.1
author
#1 lore raw

PATCH v5 1/2 tmpfs: Add per-superblock i_ino support

get_next_ino has a number of problems:

- It uses and returns a uint, which is susceptible to become overflowed if a lot of volatile inodes that use get_next_ino are created.
- It's global, with no specificity per-sb or even per-filesystem. This means it's not that difficult to cause inode number wraparounds on a single device, which can result in having multiple distinct inodes with the same inode number.

This patch adds a per-superblock counter that mitigates the second case. This design also allows us to later have a specific i_ino size per-device, for example, allowing users to choose whether to use 32- or 64-bit inodes for each tmpfs mount. This is implemented in the next commit.

---
 include/linux/shmem_fs.h |  1 +
 mm/shmem.c               | 30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

v5: Nothing in code, just resending with correct linux-mm domain.

include/linux/shmem_fs.h +1 -0
index de8e4b71e3ba..7fac91f490dc 100644
@@ -35,6 +35,7 @@ struct shmem_sb_info {
 	unsigned char huge;	    /* Whether to try for hugepages */
 	kuid_t uid;		    /* Mount uid for root directory */
 	kgid_t gid;		    /* Mount gid for root directory */
+	ino_t next_ino;		    /* The next per-sb inode number to use */
 	struct mempolicy *mpol;     /* default memory policy for mappings */
 	spinlock_t shrinklist_lock;   /* Protects shrinklist */
 	struct list_head shrinklist;  /* List of shinkable inodes */
mm/shmem.c +29 -1
index 8793e8cc1a48..9e97ba972225 100644
@@ -2236,6 +2236,12 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
 	return 0;
 }
 
+/*
+ * shmem_get_inode - reserve, allocate, and initialise a new inode
+ *
+ * If this tmpfs is from kern_mount we use get_next_ino, which is global, since
+ * inum churn there is low and this avoids taking locks.
+ */
 static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
 				     umode_t mode, dev_t dev, unsigned long flags)
 {
@@ -2248,7 +2254,28 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
 
 	inode = new_inode(sb);
 	if (inode) {
-		inode->i_ino = get_next_ino();
+		if (sb->s_flags & SB_KERNMOUNT) {
+			/*
+			 * __shmem_file_setup, one of our callers, is lock-free:
+			 * it doesn't hold stat_lock in shmem_reserve_inode
+			 * since max_inodes is always 0, and is called from
+			 * potentially unknown contexts. As such, use the global
+			 * allocator which doesn't require the per-sb stat_lock.
+			 */
+			inode->i_ino = get_next_ino();
+		} else {
+			spin_lock(&sbinfo->stat_lock);
+			if (unlikely(sbinfo->next_ino > UINT_MAX)) {
+				/*
+				 * Emulate get_next_ino uint wraparound for
+				 * compatibility
+				 */
+				sbinfo->next_ino = 1;
+			}
+			inode->i_ino = sbinfo->next_ino++;
+			spin_unlock(&sbinfo->stat_lock);
+		}
+
 		inode_init_owner(inode, dir, mode);
 		inode->i_blocks = 0;
 		inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
@@ -3662,6 +3689,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
 #else
 	sb->s_flags |= SB_NOUSER;
 #endif
+	sbinfo->next_ino = 1;
 	sbinfo->max_blocks = ctx->blocks;
 	sbinfo->free_inodes = sbinfo->max_inodes = ctx->inodes;
 	sbinfo->uid = ctx->uid;
Signature · 1 line
2.24.1
author
#9 lore raw

PATCH v5 2/2 tmpfs: Support 64-bit inums per-sb

In reply to Chris Down

The default is still set to inode32 for backwards compatibility, but system administrators can opt in to the new 64-bit inode numbers by either:

1. Passing inode64 on the command line when mounting, or
2. Configuring the kernel with CONFIG_TMPFS_INODE64=y

The inode64 and inode32 names are used based on existing precedent from XFS.

---
 Documentation/filesystems/tmpfs.txt | 11 +++++
 fs/Kconfig                          | 15 +++++++
 include/linux/shmem_fs.h            |  1 +
 mm/shmem.c                          | 66 ++++++++++++++++++++++++++++-
 4 files changed, 92 insertions(+), 1 deletion(-)

v5: Nothing in code, just resending with correct linux-mm domain.

Documentation/filesystems/tmpfs.txt +11 -0
index 5ecbc03e6b2f..203e12a684c9 100644
@@ -136,6 +136,15 @@ These options do not have any effect on remount. You can change these
 parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.
 
 
+tmpfs has a mount option to select whether it will wrap at 32- or 64-bit inode
+numbers:
+
+inode64   Use 64-bit inode numbers
+inode32   Use 32-bit inode numbers
+
+On 64-bit, the default is set by CONFIG_TMPFS_INODE64. On 32-bit, inode64 is
+not legal and will produce an error at mount time.
+
 So 'mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs'
 will give you tmpfs instance on /mytmpfs which can allocate 10GB
 RAM/SWAP in 10240 inodes and it is only accessible by root.
@@ -147,3 +156,5 @@ Updated:
    Hugh Dickins, 4 June 2007
 Updated:
    KOSAKI Motohiro, 16 Mar 2010
+Updated:
+   Chris Down, 2 Jan 2020
fs/Kconfig +15 -0
index 7b623e9fc1b0..e74f127df22a 100644
@@ -199,6 +199,21 @@ config TMPFS_XATTR
 
 	  If unsure, say N.
 
+config TMPFS_INODE64
+	bool "Use 64-bit ino_t by default in tmpfs"
+	depends on TMPFS && 64BIT
+	default n
+	help
+	  tmpfs has historically used only inode numbers as wide as an unsigned
+	  int. In some cases this can cause wraparound, potentially resulting in
+	  multiple files with the same inode number on a single device. This option
+	  makes tmpfs use the full width of ino_t by default, similarly to the
+	  inode64 mount option.
+
+	  To override this default, use the inode32 or inode64 mount options.
+
+	  If unsure, say N.
+
 config HUGETLBFS
 	bool "HugeTLB file system support"
 	depends on X86 || IA64 || SPARC64 || (S390 && 64BIT) || \
include/linux/shmem_fs.h +1 -0
index 7fac91f490dc..8925eb774518 100644
@@ -35,6 +35,7 @@ struct shmem_sb_info {
 	unsigned char huge;	    /* Whether to try for hugepages */
 	kuid_t uid;		    /* Mount uid for root directory */
 	kgid_t gid;		    /* Mount gid for root directory */
+	bool full_inums;	    /* If i_ino should be uint or ino_t */
 	ino_t next_ino;		    /* The next per-sb inode number to use */
 	struct mempolicy *mpol;     /* default memory policy for mappings */
 	spinlock_t shrinklist_lock;   /* Protects shrinklist */
mm/shmem.c +65 -1

147 lines not on this page · raw message

Signature · 1 line
2.24.1
#2 lore raw

Re: [PATCH v5 1/2] tmpfs: Add per-superblock i_ino support

In reply to Chris Down
Quoted 70 lines · Chris Down

get_next_ino has a number of problems:

- It uses and returns a uint, which is susceptible to become overflowed if a lot of volatile inodes that use get_next_ino are created.
- It's global, with no specificity per-sb or even per-filesystem. This means it's not that difficult to cause inode number wraparounds on a single device, which can result in having multiple distinct inodes with the same inode number.

This patch adds a per-superblock counter that mitigates the second case. This design also allows us to later have a specific i_ino size per-device, for example, allowing users to choose whether to use 32- or 64-bit inodes for each tmpfs mount. This is implemented in the next commit.

---
 include/linux/shmem_fs.h |  1 +
 mm/shmem.c               | 30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

v5: Nothing in code, just resending with correct linux-mm domain.

include/linux/shmem_fs.h +1 -0
index de8e4b71e3ba..7fac91f490dc 100644
@@ -35,6 +35,7 @@ struct shmem_sb_info {
 	unsigned char huge;	    /* Whether to try for hugepages */
 	kuid_t uid;		    /* Mount uid for root directory */
 	kgid_t gid;		    /* Mount gid for root directory */
+	ino_t next_ino;		    /* The next per-sb inode number to use */
 	struct mempolicy *mpol;     /* default memory policy for mappings */
 	spinlock_t shrinklist_lock;   /* Protects shrinklist */
 	struct list_head shrinklist;  /* List of shinkable inodes */
mm/shmem.c +7 -1
index 8793e8cc1a48..9e97ba972225 100644
@@ -2236,6 +2236,12 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
 	return 0;
 }
 
+/*
+ * shmem_get_inode - reserve, allocate, and initialise a new inode
+ *
+ * If this tmpfs is from kern_mount we use get_next_ino, which is global, since
+ * inum churn there is low and this avoids taking locks.
+ */
 static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
 				     umode_t mode, dev_t dev, unsigned long flags)
 {
@@ -2248,7 +2254,28 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
 
 	inode = new_inode(sb);
 	if (inode) {
-		inode->i_ino = get_next_ino();
+		if (sb->s_flags & SB_KERNMOUNT) {

mm/shmem.c static struct inode *shmem_get_inode(struct super_block *sb, const struct inode · line 2267

Quoted 10 lines
mm/shmem.c +10 -0
+			/*
+			 * __shmem_file_setup, one of our callers, is lock-free:
+			 * it doesn't hold stat_lock in shmem_reserve_inode
+			 * since max_inodes is always 0, and is called from
+			 * potentially unknown contexts. As such, use the global
+			 * allocator which doesn't require the per-sb stat_lock.
+			 */
+			inode->i_ino = get_next_ino();
+		} else {
+			spin_lock(&sbinfo->stat_lock);

Use spin_lock will affect performance, how about define

unsigned long __percpu *last_ino_number; /* Last inode number */ atomic64_t shared_last_ino_number; /* Shared last inode number */ in shmem_sb_info, whose performance will be better?

Quoted 22 lines
mm/shmem.c +12 -0
+			if (unlikely(sbinfo->next_ino > UINT_MAX)) {
+				/*
+				 * Emulate get_next_ino uint wraparound for
+				 * compatibility
+				 */
+				sbinfo->next_ino = 1;
+			}
+			inode->i_ino = sbinfo->next_ino++;
+			spin_unlock(&sbinfo->stat_lock);
+		}
+
 		inode_init_owner(inode, dir, mode);
 		inode->i_blocks = 0;
 		inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
@@ -3662,6 +3689,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
 #else
 	sb->s_flags |= SB_NOUSER;
 #endif
+	sbinfo->next_ino = 1;
 	sbinfo->max_blocks = ctx->blocks;
 	sbinfo->free_inodes = sbinfo->max_inodes = ctx->inodes;
 	sbinfo->uid = ctx->uid;
#3 lore raw

Re: [PATCH v5 1/2] tmpfs: Add per-superblock i_ino support

Quoted 86 lines · zhengbin (A)
Quoted 70 lines · Chris Down

get_next_ino has a number of problems:

- It uses and returns a uint, which is susceptible to become overflowed if a lot of volatile inodes that use get_next_ino are created.
- It's global, with no specificity per-sb or even per-filesystem. This means it's not that difficult to cause inode number wraparounds on a single device, which can result in having multiple distinct inodes with the same inode number.

This patch adds a per-superblock counter that mitigates the second case. This design also allows us to later have a specific i_ino size per-device, for example, allowing users to choose whether to use 32- or 64-bit inodes for each tmpfs mount. This is implemented in the next commit.

---
 include/linux/shmem_fs.h |  1 +
 mm/shmem.c               | 30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

v5: Nothing in code, just resending with correct linux-mm domain.

include/linux/shmem_fs.h +1 -0
index de8e4b71e3ba..7fac91f490dc 100644
@@ -35,6 +35,7 @@ struct shmem_sb_info {
      unsigned char huge;         /* Whether to try for hugepages */
      kuid_t uid;                 /* Mount uid for root directory */
      kgid_t gid;                 /* Mount gid for root directory */
+     ino_t next_ino;             /* The next per-sb inode number to use */
      struct mempolicy *mpol;     /* default memory policy for mappings */
      spinlock_t shrinklist_lock;   /* Protects shrinklist */
      struct list_head shrinklist;  /* List of shinkable inodes */
mm/shmem.c +7 -1
index 8793e8cc1a48..9e97ba972225 100644
@@ -2236,6 +2236,12 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
      return 0;
 }
 
+/*
+ * shmem_get_inode - reserve, allocate, and initialise a new inode
+ *
+ * If this tmpfs is from kern_mount we use get_next_ino, which is global, since
+ * inum churn there is low and this avoids taking locks.
+ */
 static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
                                   umode_t mode, dev_t dev, unsigned long flags)
 {
@@ -2248,7 +2254,28 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
 
      inode = new_inode(sb);
      if (inode) {
-             inode->i_ino = get_next_ino();
+             if (sb->s_flags & SB_KERNMOUNT) {

mm/shmem.c static struct inode *shmem_get_inode(struct super_block *sb, const struct inode · line 2267

Quoted 10 lines
mm/shmem.c +10 -0
+                     /*
+                      * __shmem_file_setup, one of our callers, is lock-free:
+                      * it doesn't hold stat_lock in shmem_reserve_inode
+                      * since max_inodes is always 0, and is called from
+                      * potentially unknown contexts. As such, use the global
+                      * allocator which doesn't require the per-sb stat_lock.
+                      */
+                     inode->i_ino = get_next_ino();
+             } else {
+                     spin_lock(&sbinfo->stat_lock);

Use spin_lock will affect performance, how about define

Quoted 4 lines

unsigned long __percpu *last_ino_number; /* Last inode number */ atomic64_t shared_last_ino_number; /* Shared last inode number */ in shmem_sb_info, whose performance will be better?

Please take a look at shmem_reserve_inode().
spin lock is already being taken in shmem_get_inode()
so there is nothing to be gained from complicating next_ino counter.

This fact would have been a lot clearer if next_ino was incremented inside shmem_reserve_inode() and its value returned to be used by shmem_get_inode(), but I am also fine with code as it is with the comment above.

Thanks,
Amir.

author
#8 lore raw

Re: [PATCH v5 1/2] tmpfs: Add per-superblock i_ino support

In reply to zhengbin (A)
Quoted 1 line · zhengbin (A)

Use spin_lock will affect performance

"Performance" isn't a binary. In discussions, you should avoid invoking the performance boogeyman without presenting any real-world data. :-)

We already have to take this spin lock before when setting the free inode count. The two sites can be merged, but it seems unnecessary to conflate their purpose at this time.

#10 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Chris Down
Quoted 9 lines · Chris Down

The default is still set to inode32 for backwards compatibility, but system administrators can opt in to the new 64-bit inode numbers by either:

1. Passing inode64 on the command line when mounting, or
2. Configuring the kernel with CONFIG_TMPFS_INODE64=y

The inode64 and inode32 names are used based on existing precedent from XFS.

Please don't copy this misfeature of XFS.

The inode32/inode64 XFS options were a horrible hack made more than 20 years ago when NFSv2 was still in use and 64 bit inodes could not be used for NFSv2 exports. It was then continued to be used because 32bit NFSv3 clients were unable to handle 64 bit inodes.

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

I don't think we should be repeating past mistakes by trying to cater for broken 32 bit applications on 64 bit machines in this day and age.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author
#11 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

Quoted 9 lines · Dave Chinner

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Quoted 3 lines

I don't think we should be repeating past mistakes by trying to cater for broken 32 bit applications on 64 bit machines in this day and age.

I'm very glad to hear that. I strongly support moving to 64-bit inums in all cases if there is precedent that it's not a compatibility issue, but from the comments on my original[0] patch (especially that they strayed from the original patches' change to use ino_t directly into slab reuse), I'd been given the impression that it was known to be one.

From my perspective I have no evidence that inode32 is needed other than the comment from Jeff above get_next_ino. If that turns out not to be a problem, I am more than happy to just wholesale migrate 64-bit inodes per-sb in tmpfs.

0: https://lore.kernel.org/patchwork/patch/1170963/

#12 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

Quoted 20 lines · Chris Down
Quoted 9 lines · Dave Chinner

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Quoted 3 lines

I don't think we should be repeating past mistakes by trying to cater for broken 32 bit applications on 64 bit machines in this day and age.

I'm very glad to hear that. I strongly support moving to 64-bit inums in all cases if there is precedent that it's not a compatibility issue, but from the comments on my original[0] patch (especially that they strayed from the original patches' change to use ino_t directly into slab reuse), I'd been given the impression that it was known to be one.

Quoted 4 lines

From my perspective I have no evidence that inode32 is needed other than the comment from Jeff above get_next_ino. If that turns out not to be a problem, I am more than happy to just wholesale migrate 64-bit inodes per-sb in tmpfs.

Well, that's my comment above about 32 bit apps using non-LFS compliant interfaces in this day and age. It's essentially a legacy interface these days, and anyone trying to access a modern linux filesystem (btrfs, XFS, ext4, etc) ion 64 bit systems need to handle 64 bit inodes because they all can create >32bit inode numbers in their default configurations.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#13 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

Quoted 27 lines · Dave Chinner
Quoted 20 lines · Chris Down
Quoted 9 lines · Dave Chinner

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Quoted 3 lines

I don't think we should be repeating past mistakes by trying to cater for broken 32 bit applications on 64 bit machines in this day and age.

I'm very glad to hear that. I strongly support moving to 64-bit inums in all cases if there is precedent that it's not a compatibility issue, but from the comments on my original[0] patch (especially that they strayed from the original patches' change to use ino_t directly into slab reuse), I'd been given the impression that it was known to be one.

Quoted 4 lines

From my perspective I have no evidence that inode32 is needed other than the comment from Jeff above get_next_ino. If that turns out not to be a problem, I am more than happy to just wholesale migrate 64-bit inodes per-sb in tmpfs.

Quoted 7 lines

Well, that's my comment above about 32 bit apps using non-LFS compliant interfaces in this day and age. It's essentially a legacy interface these days, and anyone trying to access a modern linux filesystem (btrfs, XFS, ext4, etc) ion 64 bit systems need to handle 64 bit inodes because they all can create >32bit inode numbers in their default configurations.

Chris,

Following Dave's comment, let's keep the config option, but make it default to Y and remove the mount option for now.
If somebody shouts, mount option could be re-added later. This way at least we leave an option for workaround for an unlikely breakage.

Thanks,
Amir.

maintainer
#4 lore raw

Re: [PATCH v5 1/2] tmpfs: Add per-superblock i_ino support

In reply to Amir Goldstein
Quoted 90 lines · Amir Goldstein
Quoted 84 lines · zhengbin (A)
Quoted 70 lines · Chris Down

get_next_ino has a number of problems:

- It uses and returns a uint, which is susceptible to become overflowed if a lot of volatile inodes that use get_next_ino are created.
- It's global, with no specificity per-sb or even per-filesystem. This means it's not that difficult to cause inode number wraparounds on a single device, which can result in having multiple distinct inodes with the same inode number.

This patch adds a per-superblock counter that mitigates the second case. This design also allows us to later have a specific i_ino size per-device, for example, allowing users to choose whether to use 32- or 64-bit inodes for each tmpfs mount. This is implemented in the next commit.

---
 include/linux/shmem_fs.h |  1 +
 mm/shmem.c               | 30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

v5: Nothing in code, just resending with correct linux-mm domain.

include/linux/shmem_fs.h +1 -0
index de8e4b71e3ba..7fac91f490dc 100644
@@ -35,6 +35,7 @@ struct shmem_sb_info {
      unsigned char huge;         /* Whether to try for hugepages */
      kuid_t uid;                 /* Mount uid for root directory */
      kgid_t gid;                 /* Mount gid for root directory */
+     ino_t next_ino;             /* The next per-sb inode number to use */
      struct mempolicy *mpol;     /* default memory policy for mappings */
      spinlock_t shrinklist_lock;   /* Protects shrinklist */
      struct list_head shrinklist;  /* List of shinkable inodes */
mm/shmem.c +7 -1
index 8793e8cc1a48..9e97ba972225 100644
@@ -2236,6 +2236,12 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
      return 0;
 }
 
+/*
+ * shmem_get_inode - reserve, allocate, and initialise a new inode
+ *
+ * If this tmpfs is from kern_mount we use get_next_ino, which is global, since
+ * inum churn there is low and this avoids taking locks.
+ */
 static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
                                   umode_t mode, dev_t dev, unsigned long flags)
 {
@@ -2248,7 +2254,28 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
 
      inode = new_inode(sb);
      if (inode) {
-             inode->i_ino = get_next_ino();
+             if (sb->s_flags & SB_KERNMOUNT) {

mm/shmem.c static struct inode *shmem_get_inode(struct super_block *sb, const struct inode · line 2267

Quoted 10 lines
mm/shmem.c +10 -0
+                     /*
+                      * __shmem_file_setup, one of our callers, is lock-free:
+                      * it doesn't hold stat_lock in shmem_reserve_inode
+                      * since max_inodes is always 0, and is called from
+                      * potentially unknown contexts. As such, use the global
+                      * allocator which doesn't require the per-sb stat_lock.
+                      */
+                     inode->i_ino = get_next_ino();
+             } else {
+                     spin_lock(&sbinfo->stat_lock);

Use spin_lock will affect performance, how about define

Quoted 4 lines

unsigned long __percpu *last_ino_number; /* Last inode number */ atomic64_t shared_last_ino_number; /* Shared last inode number */ in shmem_sb_info, whose performance will be better?

Quoted 8 lines

Please take a look at shmem_reserve_inode().
spin lock is already being taken in shmem_get_inode()
so there is nothing to be gained from complicating next_ino counter.

This fact would have been a lot clearer if next_ino was incremented inside shmem_reserve_inode() and its value returned to be used by shmem_get_inode(), but I am also fine with code as it is with the comment above.

Chris, Amir, thank you both for all the work you have been putting into this over the holiday. I'm only now catching up, sorry.

It appears that what you are ending up with above is very close to the patch Google has been using for several years. I'm glad Chris has explored some interesting options, disappointed that you had no more success than I had in trying to solve it efficiently with 32-bit inos, agree with the way in which Amir cut it back. That we've come to the same conclusions independently is good confirmation of this approach.

Only yesterday did I get to see that Amir had asked to see my patch on the 27th: rediffed against 5.5-rc5, appended now below. I'm showing it, though it's known deficient in three ways (not to mention lack of config or mount options, but I now see Dave Chinner has an interesting take on those) - better make it visible to you now, than me delay you further.

It does indicate a couple of improvements to Chris's current patch:
reducing use of stat_lock, as Amir suggested (in both nr_inodes limited and unlimited cases); and need to fix shmem_encode_fh(), which neither of us did yet. Where we should go from here, fix Chris's or fix mine, I've not decided.

From: Hugh Dickins <[email protected]>
Date: Fri, 7 Aug 2015 20:08:53 -0700
Subject: [PATCH] tmpfs: provide 64-bit inode numbers

Some programs (including ld.so and clang) try to deduplicate opened files by comparing st_dev and st_ino, which breaks down when two files on the same tmpfs have the same inode number: we are now hitting this problem too often. J. R. Okajima has reported the same problem with backup tools.

tmpfs is currently sharing the same 32-bit get_next_ino() pool as sockets, pipes, ramfs, hugetlbfs etc. It delivers 32-bit inos even on a 64-bit kernel for one reason: because if a 32-bit executable compiled without _FILE_OFFSET_BITS=64 tries to stat a file with an ino which won't fit in 32 bits, glibc fails that with EOVERFLOW. glibc is being correct, but unhelpful: so 2.6.22 commit 866b04fccbf1 ("inode numbering: make static counters in new_inode and iunique be 32 bits") forced get_next_ino() to unsigned int.

But whatever the upstream need to avoid surprising a mis-built 32-bit executable, Google production can be sure of the 64-bit environment, and any remaining 32-bit executables built with _FILE_OFFSET_BITS=64 (our files are sometimes bigger than 2G).

So, leave get_next_ino() as it is, but convert tmpfs to supply unsigned long inos, and let each superblock keep its own account:
it was weird to be sharing a pool with such disparate uses before.

shmem_reserve_inode() already provides a good place to do this; and normally it has to take stat_lock to update free_inodes, so no overhead to increment its next_ino under the same lock. But if it's the internal shm_mnt, or mounted with "nr_inodes=0" to increase scalability by avoiding that stat_lock, then use the same percpu batching technique as get_next_ino().

Take on board 4.2 commit 2adc376c5519 ("vfs: avoid creation of inode number 0 in get_next_ino"): for safety, skip any ino whose low 32 bits is 0.

Upstream? That's tougher: maybe try to upstream this as is, and see what falls out; maybe add ino32 or ino64 mount options before trying; or maybe upstream has to stick with the 32-bit ino, and a scheme more complicated than this be implemented for tmpfs.

Not-Yet-Signed-off-by Hugh Dickins <[email protected]>

1) Probably needs minor corrections for the 32-bit kernel: I wasn't worrying about that at the time, and expect some "unsigned long"s I didn't need to change for the 64-bit kernel actually need to be "u64"s or "ino_t"s now.
2) The "return 1" from shmem_encode_fh() would nowadays be written as "return FILEID_INO32_GEN" (and overlayfs takes particular interest in that fileid); yet it already put the high 32 bits of the ino into the fh: probably needs a different fileid once high 32 bits are set.
3) When this patch was written, a tmpfs could not be remounted from limited nr_inodes to unlimited nr_inodes=0; but that restriction was accidentally (though sensibly) lifted during v5.4's mount API mods; so would need to be taken into account (or reverted) here.
---

 include/linux/shmem_fs.h |    2 +
 mm/shmem.c               |   59 ++++++++++++++++++++++++++++++++++---
 2 files changed, 57 insertions(+), 4 deletions(-)
include/linux/shmem_fs.h +2 -0
@@ -30,6 +30,8 @@ struct shmem_sb_info {
 	struct percpu_counter used_blocks;  /* How many are allocated */
 	unsigned long max_inodes;   /* How many inodes are allowed */
 	unsigned long free_inodes;  /* How many are left for allocation */
+	unsigned long next_ino;	    /* Next inode number to be allocated */
+	unsigned long __percpu *ino_batch; /* Next per cpu, if unlimited */
 	spinlock_t stat_lock;	    /* Serialize shmem_sb_info changes */
 	umode_t mode;		    /* Mount mode for root directory */
 	unsigned char huge;	    /* Whether to try for hugepages */
mm/shmem.c +55 -4

103 lines not on this page · raw message

#5 lore raw

Re: [PATCH v5 1/2] tmpfs: Add per-superblock i_ino support

Quoted 10 lines

Chris, Amir, thank you both for all the work you have been putting into this over the holiday. I'm only now catching up, sorry.

It appears that what you are ending up with above is very close to the patch Google has been using for several years. I'm glad Chris has explored some interesting options, disappointed that you had no more success than I had in trying to solve it efficiently with 32-bit inos, agree with the way in which Amir cut it back. That we've come to the same conclusions independently is good confirmation of this approach.

Indeed :)

Quoted 6 lines

Only yesterday did I get to see that Amir had asked to see my patch on the 27th: rediffed against 5.5-rc5, appended now below. I'm showing it, though it's known deficient in three ways (not to mention lack of config or mount options, but I now see Dave Chinner has an interesting take on those) - better make it visible to you now, than me delay you further.

Quoted 6 lines

It does indicate a couple of improvements to Chris's current patch:
reducing use of stat_lock, as Amir suggested (in both nr_inodes limited and unlimited cases); and need to fix shmem_encode_fh(), which neither of us did yet. Where we should go from here, fix Chris's or fix mine, I've not decided.

I vote in favor or best of both patches to result in a simpler outcome:
1. use inop approach from Hugh's patch
2. use get_next_ino() instead of per-sb ino_batch for kern_mount

Hugh, do you have any evidence or suspect that shmem_file_setup() could be contributing to depleting the global get_next_ino pool? Do you have an objection to the combination above?

Quoted 46 lines

From: Hugh Dickins <[email protected]>
Date: Fri, 7 Aug 2015 20:08:53 -0700
Subject: [PATCH] tmpfs: provide 64-bit inode numbers

Some programs (including ld.so and clang) try to deduplicate opened files by comparing st_dev and st_ino, which breaks down when two files on the same tmpfs have the same inode number: we are now hitting this problem too often. J. R. Okajima has reported the same problem with backup tools.

tmpfs is currently sharing the same 32-bit get_next_ino() pool as sockets, pipes, ramfs, hugetlbfs etc. It delivers 32-bit inos even on a 64-bit kernel for one reason: because if a 32-bit executable compiled without _FILE_OFFSET_BITS=64 tries to stat a file with an ino which won't fit in 32 bits, glibc fails that with EOVERFLOW. glibc is being correct, but unhelpful: so 2.6.22 commit 866b04fccbf1 ("inode numbering: make static counters in new_inode and iunique be 32 bits") forced get_next_ino() to unsigned int.

But whatever the upstream need to avoid surprising a mis-built 32-bit executable, Google production can be sure of the 64-bit environment, and any remaining 32-bit executables built with _FILE_OFFSET_BITS=64 (our files are sometimes bigger than 2G).

So, leave get_next_ino() as it is, but convert tmpfs to supply unsigned long inos, and let each superblock keep its own account:
it was weird to be sharing a pool with such disparate uses before.

shmem_reserve_inode() already provides a good place to do this; and normally it has to take stat_lock to update free_inodes, so no overhead to increment its next_ino under the same lock. But if it's the internal shm_mnt, or mounted with "nr_inodes=0" to increase scalability by avoiding that stat_lock, then use the same percpu batching technique as get_next_ino().

Take on board 4.2 commit 2adc376c5519 ("vfs: avoid creation of inode number 0 in get_next_ino"): for safety, skip any ino whose low 32 bits is 0.

Upstream? That's tougher: maybe try to upstream this as is, and see what falls out; maybe add ino32 or ino64 mount options before trying; or maybe upstream has to stick with the 32-bit ino, and a scheme more complicated than this be implemented for tmpfs.

Not-Yet-Signed-off-by Hugh Dickins <[email protected]>
Quoted 8 lines

1) Probably needs minor corrections for the 32-bit kernel: I wasn't worrying about that at the time, and expect some "unsigned long"s I didn't need to change for the 64-bit kernel actually need to be "u64"s or "ino_t"s now.
2) The "return 1" from shmem_encode_fh() would nowadays be written as "return FILEID_INO32_GEN" (and overlayfs takes particular interest in that fileid); yet it already put the high 32 bits of the ino into the fh: probably needs a different fileid once high 32 bits are set.

Nice spotting, but this really isn't a problem for overlayfs. I agree that it would be nice to follow the same practice as xfs with XFS_FILEID_TYPE_64FLAG, but as one can see from the private flag, this is by no means a standard of any sort.

As the name_to_handle_at() man page says:
"Other than the use of the handle_bytes field, the caller should treat the
file_handle structure as an opaque data type: the handle_type and f_handle fields are needed only by a subsequent call to open_by_handle_at()."

It is true that one of my initial versions was checking value returned from encode_fh, but Miklos has pointed out to me that this value is arbitrary and we shouldn't rely on it.

In current overlayfs, the value FILEID_INO32_GEN is only used internally to indicate the case where filesystem has no encode_fh op (see comment above ovl_can_decode_fh()). IOW, only the special case of encoding by the default export_encode_fh() is considered a proof for 32bit inodes. So tmpfs has never been considered as a 32bit inodes filesystem by overlayfs.

Thanks,
Amir.

maintainer
#14 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Amir Goldstein
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Dave Chinner
Quoted 9 lines · Chris Down
Quoted 8 lines · Dave Chinner

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Interesting take on it. I'd all along imagined we would have to resort to a mount option for safety, but Dave is right that I was too focused on avoiding tmpfs regressions, without properly realizing that people were very unlikely to have written such tools for tmpfs in particular, but written them for all filesystems, and already encountered and fixed such EOVERFLOWs for other filesystems.

Hmm, though how readily does XFS actually reach the high inos on ordinary users' systems?

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 4 lines

I don't think we should be repeating past mistakes by trying to cater for broken 32 bit applications on 64 bit machines in this day and age.

I'm very glad to hear that. I strongly support moving to 64-bit inums in all cases if there is precedent that it's not a compatibility issue, but from the comments on my original[0] patch (especially that they strayed from the original patches' change to use ino_t directly into slab reuse), I'd been given the impression that it was known to be one.

From my perspective I have no evidence that inode32 is needed other than the comment from Jeff above get_next_ino. If that turns out not to be a problem, I am more than happy to just wholesale migrate 64-bit inodes per-sb in tmpfs.

Quoted 6 lines
Quoted 6 lines

Well, that's my comment above about 32 bit apps using non-LFS compliant interfaces in this day and age. It's essentially a legacy interface these days, and anyone trying to access a modern linux filesystem (btrfs, XFS, ext4, etc) ion 64 bit systems need to handle 64 bit inodes because they all can create >32bit inode numbers in their default configurations.

I thought ext4 still deals in 32-bit inos, so ext4-world would not necessarily have caught up? Though, arguing the other way, IIUC 64-bit ino support comes bundled with file sizes over 2GB (on all architectures?), and it's hard to imagine who gets by with a 2GB file size limit nowadays.

Quoted 9 lines
Quoted 1 line

Chris,

Following Dave's comment, let's keep the config option, but make it default to Y and remove the mount option for now.
If somebody shouts, mount option could be re-added later. This way at least we leave an option for workaround for an unlikely breakage.

Though I don't share Dave's strength of aversion to the inode32 and inode64 mount options, I do agree that it's preferable not to offer them if they're so very unlikely to be necessary.

Do we even need the config option? We certainly do need to hold the patch with config option and mount options "in our back pocket", so that if a regression does get reported, then upstream and stable can respond to fix it quickly; but do we need more than that?

My main concern is that a new EOVERFLOW might not be reported as such, and waste a lot of someone's time to track down.

Hugh

#15 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

Quoted 21 lines · Hugh Dickins
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Dave Chinner
Quoted 9 lines · Chris Down
Quoted 8 lines · Dave Chinner

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Interesting take on it. I'd all along imagined we would have to resort to a mount option for safety, but Dave is right that I was too focused on avoiding tmpfs regressions, without properly realizing that people were very unlikely to have written such tools for tmpfs in particular, but written them for all filesystems, and already encountered and fixed such EOVERFLOWs for other filesystems.

Quoted 3 lines

Hmm, though how readily does XFS actually reach the high inos on ordinary users' systems?

Define 'ordinary'
I my calculations are correct, with default mkfs.xfs any inode allocated from logical offset > 2TB on a volume has high ino bits set. Besides, a deployment with more than 4G inodes shouldn't be hard to find.

Thanks,
Amir.

#24 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Hugh Dickins
Quoted 20 lines · Hugh Dickins
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Dave Chinner
Quoted 9 lines · Chris Down
Quoted 8 lines · Dave Chinner

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Interesting take on it. I'd all along imagined we would have to resort to a mount option for safety, but Dave is right that I was too focused on avoiding tmpfs regressions, without properly realizing that people were very unlikely to have written such tools for tmpfs in particular, but written them for all filesystems, and already encountered and fixed such EOVERFLOWs for other filesystems.

Quoted 2 lines

Hmm, though how readily does XFS actually reach the high inos on ordinary users' systems?

Quite frequently these days - the threshold for exceeding 32 bits in the inode number is dependent on the inode size.

Old v4 filesystems use 256 byte inodes by default, so they overflow 32bits when the filesystem size is >1TB.

Current v5 filesystems use 512 byte inodes, so they overflow 32 bits on filesytsems >2TB.

Quoted 18 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

I'm very glad to hear that. I strongly support moving to 64-bit inums in all cases if there is precedent that it's not a compatibility issue, but from the comments on my original[0] patch (especially that they strayed from the original patches' change to use ino_t directly into slab reuse), I'd been given the impression that it was known to be one.

From my perspective I have no evidence that inode32 is needed other than the comment from Jeff above get_next_ino. If that turns out not to be a problem, I am more than happy to just wholesale migrate 64-bit inodes per-sb in tmpfs.

Quoted 6 lines
Quoted 6 lines

Well, that's my comment above about 32 bit apps using non-LFS compliant interfaces in this day and age. It's essentially a legacy interface these days, and anyone trying to access a modern linux filesystem (btrfs, XFS, ext4, etc) ion 64 bit systems need to handle 64 bit inodes because they all can create >32bit inode numbers in their default configurations.

Quoted 2 lines

I thought ext4 still deals in 32-bit inos, so ext4-world would not necessarily have caught up?

Hmmm - I might have got my wires crossed there - there *was* a project some time ago to increase the ext4 inode number size for large filesystems. Ah, yeah, there we go:

https://lore.kernel.org/linux-ext4/[email protected]/

I thought it had been rolled in with all the other "make stuff larger" features that ext4 has...

Quoted 3 lines

Though, arguing the other way, IIUC 64-bit
ino support comes bundled with file sizes over 2GB (on all architectures?), and it's hard to imagine who gets by with a 2GB file size limit nowadays.

Right, you need to define LFS support for >2GB file support and you get 64 bit inode support with that for free. It's only legacy binaries that haven't been rebuilt in the past 15 years that are an issue here, but there are so many other things that can go trivially wrong with such binaries I think that inode numbers are the least of the worries here...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#16 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Amir Goldstein
Quoted 22 lines · Amir Goldstein
Quoted 21 lines · Hugh Dickins
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Dave Chinner
Quoted 9 lines · Chris Down
Quoted 8 lines · Dave Chinner

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Interesting take on it. I'd all along imagined we would have to resort to a mount option for safety, but Dave is right that I was too focused on avoiding tmpfs regressions, without properly realizing that people were very unlikely to have written such tools for tmpfs in particular, but written them for all filesystems, and already encountered and fixed such EOVERFLOWs for other filesystems.

Quoted 8 lines
Quoted 3 lines

Hmm, though how readily does XFS actually reach the high inos on ordinary users' systems?

Define 'ordinary'
I my calculations are correct, with default mkfs.xfs any inode allocated from logical offset > 2TB on a volume has high ino bits set. Besides, a deployment with more than 4G inodes shouldn't be hard to find.

You don't need to allocate 4 billion inodes to get >32bit inodes in XFS - the inode number is an encoding of the physical location of the inode in the filesystem. Hence we just have to allocate the inode at a disk address higher than 2TB into the device and we overflow 32bits.

e.g. make a sparse fs image file of 10TB, mount it, create 50 subdirs, then start creating zero length files spread across the 50 separate subdirectories. You should see >32bit inode numbers almost immediately. (i.e. as soon as we allocate inodes in AG 2 or higher)

IOWs, there are *lots* of 64bit inode numbers out there on XFS filesystems....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#17 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

Quoted 2 lines · Dave Chinner

IOWs, there are *lots* of 64bit inode numbers out there on XFS filesystems....

It's less likely in btrfs but +1 to all of Dave's comments. I'm happy to run a scan on machines in the fleet and see how many have 64 bit inodes (either buttery or x-y), but it's going to be a lot.

-chris

maintainer
#6 lore raw

Re: [PATCH v5 1/2] tmpfs: Add per-superblock i_ino support

In reply to Amir Goldstein
Quoted 7 lines · Amir Goldstein

I vote in favor or best of both patches to result in a simpler outcome:
1. use inop approach from Hugh's patch
2. use get_next_ino() instead of per-sb ino_batch for kern_mount

Hugh, do you have any evidence or suspect that shmem_file_setup() could be contributing to depleting the global get_next_ino pool?

Depends on what the system is used for: on one system, it will make very little use of that pool, on another it will be one of the major depleters of the pool. Generally, it would be kinder to the other users of the pool (those that might also care about ino duplication) if shmem were to cede all use of it; but a bigger patch, yes.

Quoted 1 line

Do you have an objection to the combination above?

Objection would be too strong: I'm uncomfortable with it, and not tempted to replace our internal implementation by one reverting to use get_next_ino(); but not as uncomfortable as I am with holding up progress on the issue.

Uncomfortable because of the "depletion" you mention. Uncomfortable because half the reason for ever offering the unlimited "nr_inodes=0" mount option was to avoid stat_lock overhead (though, for all I know, maybe nobody anywhere uses that option now - and I'll be surprised if 0-day uses it and reports any slowdown).

Also uncomfortable because your (excellent, and I'd never thought about it that way) argument that the shm_mnt objects are internal and unstatable (that may not resemble how you expressed it, I've not gone back to search the mails to find where you made the point), is not entirely correct nowadays - memfd_create()d objects come from that same shm_mnt, and they can be fstat()ed. What is the likelihood that anything would care about duplicated inos of memfd_create()d objects? Fairly low, I think we'll agree; and we can probably also say that their inos are an odd implementation detail that no memfd_create() user should depend upon anyway. But I mention it in case it changes your own feeling about the shm_mnt.

Quoted 25 lines
Quoted 10 lines
Not-Yet-Signed-off-by Hugh Dickins <[email protected]>

1) Probably needs minor corrections for the 32-bit kernel: I wasn't worrying about that at the time, and expect some "unsigned long"s I didn't need to change for the 64-bit kernel actually need to be "u64"s or "ino_t"s now.
2) The "return 1" from shmem_encode_fh() would nowadays be written as "return FILEID_INO32_GEN" (and overlayfs takes particular interest in that fileid); yet it already put the high 32 bits of the ino into the fh: probably needs a different fileid once high 32 bits are set.

Nice spotting, but this really isn't a problem for overlayfs. I agree that it would be nice to follow the same practice as xfs with XFS_FILEID_TYPE_64FLAG, but as one can see from the private flag, this is by no means a standard of any sort.

As the name_to_handle_at() man page says:
"Other than the use of the handle_bytes field, the caller should treat the
file_handle structure as an opaque data type: the handle_type and f_handle fields are needed only by a subsequent call to open_by_handle_at()."

It is true that one of my initial versions was checking value returned from encode_fh, but Miklos has pointed out to me that this value is arbitrary and we shouldn't rely on it.

Quoted 6 lines

In current overlayfs, the value FILEID_INO32_GEN is only used internally to indicate the case where filesystem has no encode_fh op (see comment above ovl_can_decode_fh()). IOW, only the special case of encoding by the default export_encode_fh() is considered a proof for 32bit inodes. So tmpfs has never been considered as a 32bit inodes filesystem by overlayfs.

Thanks, you know far more about encode_fh() than I ever shall, so for now I'll take your word for it that we don't need to make any change there for this 64-bit ino support. One day I should look back, go through the encode_fh() callsites, and decide what that "return 1" really ought to say.

It's inconvenient, I'm sorry, but I shall have to go quiet again for a few days - I'm here, but cannot afford to split my attention.

Hugh

maintainer
#18 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Chris Mason
Quoted 8 lines · Chris Mason
Quoted 2 lines · Dave Chinner

IOWs, there are *lots* of 64bit inode numbers out there on XFS filesystems....

It's less likely in btrfs but +1 to all of Dave's comments. I'm happy to run a scan on machines in the fleet and see how many have 64 bit inodes (either buttery or x-y), but it's going to be a lot.

Dave, Amir, Chris, many thanks for the info you've filled in - and absolutely no need to run any scan on your fleet for this, I think we can be confident that even if fb had some 15-year-old tool in use on its fleet of 2GB-file filesystems, it would not be the one to insist on a kernel revert of 64-bit tmpfs inos.

The picture looks clear now: while ChrisD does need to hold on to his config option and inode32/inode64 mount option patch, it is much better left out of the kernel until (very unlikely) proved necessary.

Thanks,
Hugh

#7 lore raw

Re: [PATCH v5 1/2] tmpfs: Add per-superblock i_ino support

In reply to Hugh Dickins
Quoted 29 lines · Hugh Dickins
Quoted 7 lines · Amir Goldstein

I vote in favor or best of both patches to result in a simpler outcome:
1. use inop approach from Hugh's patch
2. use get_next_ino() instead of per-sb ino_batch for kern_mount

Hugh, do you have any evidence or suspect that shmem_file_setup() could be contributing to depleting the global get_next_ino pool?

Depends on what the system is used for: on one system, it will make very little use of that pool, on another it will be one of the major depleters of the pool. Generally, it would be kinder to the other users of the pool (those that might also care about ino duplication) if shmem were to cede all use of it; but a bigger patch, yes.

Quoted 1 line

Do you have an objection to the combination above?

Objection would be too strong: I'm uncomfortable with it, and not tempted to replace our internal implementation by one reverting to use get_next_ino(); but not as uncomfortable as I am with holding up progress on the issue.

Uncomfortable because of the "depletion" you mention. Uncomfortable because half the reason for ever offering the unlimited "nr_inodes=0" mount option was to avoid stat_lock overhead (though, for all I know, maybe nobody anywhere uses that option now - and I'll be surprised if 0-day uses it and reports any slowdown).

Quoted 12 lines

Also uncomfortable because your (excellent, and I'd never thought about it that way) argument that the shm_mnt objects are internal and unstatable (that may not resemble how you expressed it, I've not gone back to search the mails to find where you made the point), is not entirely correct nowadays - memfd_create()d objects come from that same shm_mnt, and they can be fstat()ed. What is the likelihood that anything would care about duplicated inos of memfd_create()d objects? Fairly low, I think we'll agree; and we can probably also say that their inos are an odd implementation detail that no memfd_create() user should depend upon anyway. But I mention it in case it changes your own feeling about the shm_mnt.

I have no strong feeling either. I just didn't know how intensive its use is. You have provided sufficient arguments IMO to go with your version of the patch.

Quoted 32 lines
Quoted 25 lines
Quoted 10 lines
Not-Yet-Signed-off-by Hugh Dickins <[email protected]>

1) Probably needs minor corrections for the 32-bit kernel: I wasn't worrying about that at the time, and expect some "unsigned long"s I didn't need to change for the 64-bit kernel actually need to be "u64"s or "ino_t"s now.
2) The "return 1" from shmem_encode_fh() would nowadays be written as "return FILEID_INO32_GEN" (and overlayfs takes particular interest in that fileid); yet it already put the high 32 bits of the ino into the fh: probably needs a different fileid once high 32 bits are set.

Nice spotting, but this really isn't a problem for overlayfs. I agree that it would be nice to follow the same practice as xfs with XFS_FILEID_TYPE_64FLAG, but as one can see from the private flag, this is by no means a standard of any sort.

As the name_to_handle_at() man page says:
"Other than the use of the handle_bytes field, the caller should treat the
file_handle structure as an opaque data type: the handle_type and f_handle fields are needed only by a subsequent call to open_by_handle_at()."

It is true that one of my initial versions was checking value returned from encode_fh, but Miklos has pointed out to me that this value is arbitrary and we shouldn't rely on it.

Quoted 6 lines

In current overlayfs, the value FILEID_INO32_GEN is only used internally to indicate the case where filesystem has no encode_fh op (see comment above ovl_can_decode_fh()). IOW, only the special case of encoding by the default export_encode_fh() is considered a proof for 32bit inodes. So tmpfs has never been considered as a 32bit inodes filesystem by overlayfs.

Quoted 6 lines

Thanks, you know far more about encode_fh() than I ever shall, so for now I'll take your word for it that we don't need to make any change there for this 64-bit ino support. One day I should look back, go through the encode_fh() callsites, and decide what that "return 1" really ought to say.

TBH, I meant to say that return 1 shouldn't matter functionally, but it would be much nicer to change it to FILEID_INO64_GEN and define that as 0x81 in include/linux/exportfs.h and actually order the gen word after the inode64 words.

But that is independent of the per-sb ino change, because the layout of the file handle has always been [gen,inode64] and never really matched that standard of FILEID_INO32_GEN.

I may send a patch to later on to change that.

Thanks,
Amir.

#25 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Dave Chinner
Quoted 27 lines · Dave Chinner
Quoted 9 lines · Chris Down

The default is still set to inode32 for backwards compatibility, but system administrators can opt in to the new 64-bit inode numbers by either:

1. Passing inode64 on the command line when mounting, or
2. Configuring the kernel with CONFIG_TMPFS_INODE64=y

The inode64 and inode32 names are used based on existing precedent from XFS.

Please don't copy this misfeature of XFS.

The inode32/inode64 XFS options were a horrible hack made more than 20 years ago when NFSv2 was still in use and 64 bit inodes could not be used for NFSv2 exports. It was then continued to be used because 32bit NFSv3 clients were unable to handle 64 bit inodes.

It took 15 years for us to be able to essentially deprecate inode32 (inode64 is the default behaviour), and we were very happy to get that albatross off our necks. In reality, almost everything out there in the world handles 64 bit inodes correctly including 32 bit machines and 32bit binaries on 64 bit machines. And, IMNSHO, there no excuse these days for 32 bit binaries that don't using the *64() syscall variants directly and hence support 64 bit inodes correctlyi out of the box on all platforms.

Quoted 3 lines

I don't think we should be repeating past mistakes by trying to cater for broken 32 bit applications on 64 bit machines in this day and age.

Hi,

It's unfortunately not true that everything handles this correctly. 32-bit binaries for games on Steam that use stat() without the 64 is so prevalent that I got tired of adding the LD_PRELOAD wrapper script and just patched out the EOVERFLOW return from glibc instead. (They obviously don't care about the inode value at all, and I don't use any other 32-bit binaries that do). This is probably a class of binaries you don't care very much about, and not very likely to be installed on a tmpfs that has wrapped around, but I thought it was worth mentioning that they do exist anyway.

Signature · 1 line
Mikael Magnusson
#19 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Hugh Dickins
Quoted 16 lines · Hugh Dickins
Quoted 8 lines · Chris Mason
Quoted 2 lines · Dave Chinner

IOWs, there are *lots* of 64bit inode numbers out there on XFS filesystems....

It's less likely in btrfs but +1 to all of Dave's comments. I'm happy to run a scan on machines in the fleet and see how many have 64 bit inodes (either buttery or x-y), but it's going to be a lot.

Dave, Amir, Chris, many thanks for the info you've filled in - and absolutely no need to run any scan on your fleet for this, I think we can be confident that even if fb had some 15-year-old tool in use on its fleet of 2GB-file filesystems, it would not be the one to insist on a kernel revert of 64-bit tmpfs inos.

Quoted 3 lines

The picture looks clear now: while ChrisD does need to hold on to his config option and inode32/inode64 mount option patch, it is much better left out of the kernel until (very unlikely) proved necessary.

This approach seems like the best course to me.

FWIW, at the time we capped this at 32-bits (2007), 64-bit machines were really just becoming widely available, and it was quite common to run 32-bit, non-LFS apps on a 64-bit kernel. Users were hitting spurious EOVERFLOW errors all over the place so this seemed like the best way to address it.

The world has changed a lot since then though, and one would hope that almost everything these days is compiled with FILE_OFFSET_BITS=64.

Fingers crossed!

Signature · 1 line
Jeff Layton <[email protected]>
author
#20 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Hugh Dickins

Hi Hugh, Dave,

Quoted 9 lines · Hugh Dickins

Dave, Amir, Chris, many thanks for the info you've filled in - and absolutely no need to run any scan on your fleet for this, I think we can be confident that even if fb had some 15-year-old tool in use on its fleet of 2GB-file filesystems, it would not be the one to insist on a kernel revert of 64-bit tmpfs inos.

The picture looks clear now: while ChrisD does need to hold on to his config option and inode32/inode64 mount option patch, it is much better left out of the kernel until (very unlikely) proved necessary.

Based on Mikael's comment above about Steam binaries, and the lack of likelihood that they can be rebuilt, I'm inclined to still keep inode{64,32}, but make legacy behaviour require explicit opt-in. That is:

- Default it to inode64
- Remove the Kconfig option
- Only print it as an option if tmpfs was explicitly mounted with inode32

The reason I suggest keeping this is that I'm mildly concerned that the kind of users who might be impacted by this change due to 32-bit _FILE_OFFSET_BITS -- like the not-too-uncommon case that Mikael brings up -- seem unlikely to be the kind of people that would find it in an rc.

Other than that, the first patch could be similar to how it is now, incorporating Hugh's improvements to the first patch to put everything under the same stat_lock in shmem_reserve_inode.

What do you folks think?

Thanks,

Chris

maintainer
#26 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Mikael Magnusson
Quoted 10 lines · Mikael Magnusson

It's unfortunately not true that everything handles this correctly. 32-bit binaries for games on Steam that use stat() without the 64 is so prevalent that I got tired of adding the LD_PRELOAD wrapper script and just patched out the EOVERFLOW return from glibc instead. (They obviously don't care about the inode value at all, and I don't use any other 32-bit binaries that do). This is probably a class of binaries you don't care very much about, and not very likely to be installed on a tmpfs that has wrapped around, but I thought it was worth mentioning that they do exist anyway.

Thank you for alerting us to reality, Mikael: not what any of us wanted to hear, but we do care about them, and it was well worth mentioning.

Hugh

maintainer
#21 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

In reply to Chris Down
Quoted 15 lines · Chris Down
Quoted 9 lines · Hugh Dickins

Dave, Amir, Chris, many thanks for the info you've filled in - and absolutely no need to run any scan on your fleet for this, I think we can be confident that even if fb had some 15-year-old tool in use on its fleet of 2GB-file filesystems, it would not be the one to insist on a kernel revert of 64-bit tmpfs inos.

The picture looks clear now: while ChrisD does need to hold on to his config option and inode32/inode64 mount option patch, it is much better left out of the kernel until (very unlikely) proved necessary.

Based on Mikael's comment above about Steam binaries, and the lack of likelihood that they can be rebuilt, I'm inclined to still keep inode{64,32}, but make legacy behaviour require explicit opt-in. That is:

Quoted 8 lines

- Default it to inode64
- Remove the Kconfig option
- Only print it as an option if tmpfs was explicitly mounted with inode32

The reason I suggest keeping this is that I'm mildly concerned that the kind of users who might be impacted by this change due to 32-bit _FILE_OFFSET_BITS -- like the not-too-uncommon case that Mikael brings up -- seem unlikely to be the kind of people that would find it in an rc.

Okay. None of us are thrilled with it, but I agree that Mikael's observation should override our developer's preference.

So the "inode64" option will be accepted but redundant on mounting, but exists for use as a remount option after mounting or remounting with "inode32": allowing the admin to switch temporarily to mask off the high ino bits with "inode32" when needing to run a limited binary.

Documentation and commit message to alert Andrew and Linus and distros that we are risking some breakage with this, but supplying the antidote (not breakage of any distros themselves, no doubt they're all good; but breakage of what some users might run on them).

Quoted 4 lines

Other than that, the first patch could be similar to how it is now, incorporating Hugh's improvements to the first patch to put everything under the same stat_lock in shmem_reserve_inode.

So, I persuaded Amir to the other aspects my version, but did not persuade you? Well, I can live with that (or if not, can send mods on top of yours): but please read again why I was uncomfortable with yours, to check that you still prefer it (I agree that your patch is simpler, and none of my discomfort decisive).

Thanks,
Hugh

author
#22 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

Hi Hugh,

Sorry this response took so long, I had some non-work issues that took a lot of time last week.

Quoted 33 lines · Hugh Dickins
Quoted 15 lines · Chris Down
Quoted 9 lines · Hugh Dickins

Dave, Amir, Chris, many thanks for the info you've filled in - and absolutely no need to run any scan on your fleet for this, I think we can be confident that even if fb had some 15-year-old tool in use on its fleet of 2GB-file filesystems, it would not be the one to insist on a kernel revert of 64-bit tmpfs inos.

The picture looks clear now: while ChrisD does need to hold on to his config option and inode32/inode64 mount option patch, it is much better left out of the kernel until (very unlikely) proved necessary.

Based on Mikael's comment above about Steam binaries, and the lack of likelihood that they can be rebuilt, I'm inclined to still keep inode{64,32}, but make legacy behaviour require explicit opt-in. That is:

Quoted 8 lines

- Default it to inode64
- Remove the Kconfig option
- Only print it as an option if tmpfs was explicitly mounted with inode32

The reason I suggest keeping this is that I'm mildly concerned that the kind of users who might be impacted by this change due to 32-bit _FILE_OFFSET_BITS -- like the not-too-uncommon case that Mikael brings up -- seem unlikely to be the kind of people that would find it in an rc.

Okay. None of us are thrilled with it, but I agree that Mikael's observation should override our developer's preference.

So the "inode64" option will be accepted but redundant on mounting, but exists for use as a remount option after mounting or remounting with "inode32": allowing the admin to switch temporarily to mask off the high ino bits with "inode32" when needing to run a limited binary.

Quoted 4 lines

Documentation and commit message to alert Andrew and Linus and distros that we are risking some breakage with this, but supplying the antidote (not breakage of any distros themselves, no doubt they're all good; but breakage of what some users might run on them).

Sounds good.

Quoted 10 lines
Quoted 4 lines

Other than that, the first patch could be similar to how it is now, incorporating Hugh's improvements to the first patch to put everything under the same stat_lock in shmem_reserve_inode.

So, I persuaded Amir to the other aspects my version, but did not persuade you? Well, I can live with that (or if not, can send mods on top of yours): but please read again why I was uncomfortable with yours, to check that you still prefer it (I agree that your patch is simpler, and none of my discomfort decisive).

Hmm, which bit were you thinking of? The lack of batching, shmem_encode_fh(), or the fact that nr_inodes can now be 0 on non-internal mounts?

For batching, I'm neutral. I'm happy to use the approach from your patch and integrate it (and credit you, of course).

For shmem_encode_fh, I'm not totally sure I understand the concern, if that's what you mean.

For nr_inodes, I agree that intentional or unintentional, we should at least handle this case for now and can adjust later if the behaviour changes.

Thanks again,

Chris

maintainer
#23 lore raw

Re: [PATCH v5 2/2] tmpfs: Support 64-bit inums per-sb

Quoted 4 lines · Chris Down

Hi Hugh,

Sorry this response took so long, I had some non-work issues that took a lot of time last week.

No, clearly it's I who must apologize to you for very slow response.

Quoted 21 lines
Quoted 10 lines · Hugh Dickins

So the "inode64" option will be accepted but redundant on mounting, but exists for use as a remount option after mounting or remounting with "inode32": allowing the admin to switch temporarily to mask off the high ino bits with "inode32" when needing to run a limited binary.

Documentation and commit message to alert Andrew and Linus and distros that we are risking some breakage with this, but supplying the antidote (not breakage of any distros themselves, no doubt they're all good; but breakage of what some users might run on them).

Sounds good.

Quoted 6 lines
Quoted 5 lines

Other than that, the first patch could be similar to how it is now, incorporating Hugh's improvements to the first patch to put everything under
the same stat_lock in shmem_reserve_inode.

Quoted 8 lines
Quoted 5 lines

So, I persuaded Amir to the other aspects my version, but did not persuade you? Well, I can live with that (or if not, can send mods on top of yours): but please read again why I was uncomfortable with yours, to check that you still prefer it (I agree that your patch is simpler, and none of my discomfort decisive).

Hmm, which bit were you thinking of? The lack of batching, shmem_encode_fh(), or the fact that nr_inodes can now be 0 on non-internal mounts?

I was uncomfortable with tmpfs depleting get_next_ino()'s pool in some configurations, and wanted the (get_next_ino-like) per-cpu but per-sb batching for nr_inodes=0, to minimize its stat_lock contention.

I did not have a patch to shmem_encode_fh(), had gone through thinking that 64-bit inos made an additional fix there necessary; but Amir then educated us that it is safe as is, though could be cleaned up later.

nr_inodes can be 0 on non-internal mounts, for many years.

Quoted 3 lines

For batching, I'm neutral. I'm happy to use the approach from your patch and integrate it (and credit you, of course).

Credit not important, but you may well want to blame me for that complication :)

Quoted 3 lines

For shmem_encode_fh, I'm not totally sure I understand the concern, if that's what you mean.

My concern had been that shmem_encode_fh() builds up an fh from i_ino and more, looks well prepared for a 64-bit ino, but appeared to be announcing a 32-bit ino in its return value: Amir reassures us that that return value does not matter.

Quoted 3 lines

For nr_inodes, I agree that intentional or unintentional, we should at least handle this case for now and can adjust later if the behaviour changes.

nr_inodes=0 is an intentional configuration (but 0 denoting infinity:
not very clean, and I've sometimes regretted that choice).

If there's any behavior change, that's a separate matter from these 64-bit ino patches; maybe I mentioned it in passing and confused us - that we seem to have recently allowed a remounting limited<->unlimited that was not permitted before, and might or might not need a fix patch.

Sorry again for delaying you, Chris: not at all what I'd wanted to do. Hugh