How are inode numbers generated in linux tmpfs?

It seems to me that tmpfs does not reuse inode numbers, but instead creates a new inode number using the +1 sequence every time it needs a free index.

Do you know how this is implemented / can you point me to some source code where I can check the algorithm used in tmpfs?

I need to understand this to get around the limitation in the caching system, which uses the inode number as the cache key (therefore, it leads to rare but occurring collisions when inodes are reused too often). tmpfs can save my day if I can prove that it continues to create unique inode numbers.

Thank you for your help.

Jerome Wagner

+5
source share
2 answers

The bulk of tmpfs code is in mm/shmem.c. New inodes are created

static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
                                 int mode, dev_t dev, unsigned long flags)

but he delegates almost everything to the common file system code.

In particular, the field is i_inofilled in fs/inode.c:

/**
 *      new_inode       - obtain an inode
 *      @sb: superblock
 *
 *      Allocates a new inode for given superblock. The default gfp_mask
 *      for allocations related to inode->i_mapping is GFP_HIGHUSER_MOVABLE.
 *      If HIGHMEM pages are unsuitable or it is known that pages allocated
 *      for the page cache are not reclaimable or migratable,
 *      mapping_set_gfp_mask() must be called with suitable flags on the
 *      newly created inode mapping
 *
 */
struct inode *new_inode(struct super_block *sb)
{
        /*
         * On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW
         * error if st_ino won't fit in target struct field. Use 32bit counter
         * here to attempt to avoid that.
         */
        static unsigned int last_ino;
        struct inode *inode;

        spin_lock_prefetch(&inode_lock);

        inode = alloc_inode(sb);
        if (inode) {
                spin_lock(&inode_lock);
                __inode_add_to_lists(sb, NULL, inode);
                inode->i_ino = ++last_ino;
                inode->i_state = 0;
                spin_unlock(&inode_lock);
        }
        return inode;
}

And it really only uses a counter (last_ino).

Most other file systems use information from files on disk to redefine the field later i_ino.

Please note that this is entirely possible for this. The kernel also has a “generation” field, which is populated in various ways. mm/shmem.cuses current time.

+3
source

I will not directly answer your question, so I apologize in advance for this.

tmpfs , . , , inode ? , : , inode , .

!

+7

All Articles