@@ -732,7 +732,9 @@ static struct inode *hugetlbfs_get_root(struct super_block *sb,
inode = new_inode(sb);
if (inode) {
- inode->i_ino = get_next_ino();
+ /* Recycle to avoid 32-bit wraparound where possible */
+ if (!inode->i_ino)
+ inode->i_ino = get_next_ino();
inode->i_mode = S_IFDIR | ctx->mode;
inode->i_uid = ctx->uid;
inode->i_gid = ctx->gid;
@@ -880,6 +880,11 @@ static struct inode *find_inode_fast(struct super_block *sb,
#define LAST_INO_BATCH 1024
static DEFINE_PER_CPU(unsigned int, last_ino);
+/*
+ * As get_next_ino returns a type with a small width (typically 32 bits),
+ * consider reusing inode numbers in your filesystem if you have a private inode
+ * cache in order to reduce the risk of wraparound.
+ */
unsigned int get_next_ino(void)
{
unsigned int *p = &get_cpu_var(last_ino);
@@ -2247,7 +2247,9 @@ 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();
+ /* Recycle to avoid 32-bit wraparound where possible */
+ if (!inode->i_ino)
+ inode->i_ino = get_next_ino();
inode_init_owner(inode, dir, mode);
inode->i_blocks = 0;
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
One limitation to this approach is that slab recycling is currently only per-memcg. This means workloads which heavily exercise get_next_ino with the same memcg are most likely to benefit, rather than those with a wide range of cgroups thrashing it. Depending on the workload, I've seen from 10%-50% recycle rate, which seems like a reasonable win with no significant increase in code complexity, although it of course doesn't fix the problem entirely. Signed-off-by: Chris Down <chris@chrisdown.name> Reported-by: Phyllipe Medeiros <phyllipe@fb.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Matthew Wilcox <willy@infradead.org> Cc: Amir Goldstein <amir73il@gmail.com> Cc: Jeff Layton <jlayton@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Tejun Heo <tj@kernel.org> Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com --- fs/hugetlbfs/inode.c | 4 +++- fs/inode.c | 5 +++++ mm/shmem.c | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-)