加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何在linux tmpfs中生成inode编号?

发布时间:2020-12-13 19:00:24 所属栏目:Linux 来源:网络整理
导读:在我看来,tmpfs不会重复使用inode数字,而是每次需要一个空闲的inode时通过1个序列创建一个新的inode号码. 你知道这是如何实现的/你能指点我一些源代码,我可以检查tmpfs中使用的算法吗? 我需要理解这一点,以便绕过使用inode号作为其缓存键的缓存系统的限制(

在我看来,tmpfs不会重复使用inode数字,而是每次需要一个空闲的inode时通过1个序列创建一个新的inode号码.

你知道这是如何实现的/你能指点我一些源代码,我可以检查tmpfs中使用的算法吗?

我需要理解这一点,以便绕过使用inode号作为其缓存键的缓存系统的限制(因此,当过度重复使用inode时,会导致罕见但发生的冲突).如果我能证明它不断创建唯一的inode数字,那么tmpfs可以节省我的一天.

谢谢您的帮助,

杰罗姆瓦格纳

最佳答案
大部分tmpfs代码都是mm / shmem.c.新的inode是由创建的

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

但它几乎将所有内容委托给通用文件系统代码.

特别是,字段i_ino填入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's 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;
}

它确实只使用递增计数器(last_ino).

大多数其他文件系统使用来自磁盘文件的信息稍后覆盖i_ino字段.

请注意,它完全可以包裹所有方式.内核还有一个“生成”字段,可以通过各种方式填充. mm / shmem.c使用当前时间.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读