vfs_caches_init函数解析

vfs_caches_init函数初始化VFS,下面梳理函数调用流程

start_kernel()
    -->vfs_caches_init_early();
        -->dcache_init_early();
            -->static struct hlist_head *dentry_hashtabl = alloc_large_system_hash("Dentry cache",
                                                sizeof(struct hlist_head),
                                                dhash_entries,
                                                13,
                                                HASH_EARLY,
                                                &d_hash_shift,
                                                &d_hash_mask,
                                                0);
        -->inode_init_early();
            -->static struct hlist_head *inode_hashtable = alloc_large_system_hash("Inode-cache",
                                                sizeof(struct hlist_head),
                                                ihash_entries,
                                                14,
                                                HASH_EARLY,
                                                &i_hash_shift,
                                                &i_hash_mask,
                                                0);
    -->vfs_caches_init(num_physpages);
        /*1.kmem_cache用于名字*/
        -->struct kmem_cache *names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
            SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
        -->dcache_init();
            /*2.kmem_cache用于缓存dentry目录项*/
            -->struct kmem_cache *dentry_cache = KMEM_CACHE(dentry,
                SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
        -->inode_init();
            /*3.kmem_cache用于缓存inode*/
            -->struct kmem_cache *inode_cachep = kmem_cache_create("inode_cache",
                                         sizeof(struct inode),
                                         0,
                                         (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
                                         SLAB_MEM_SPREAD),
                                         init_once);
        -->files_init(mempages);
            /*4.kmem_cache用于缓存file结构体*/
            -->struct kmem_cache *filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0,
                    SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
        -->mnt_init();
            /*5.kmem_cache用于缓存vfsmount结构体*/
            -->struct kmem_cache *mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount),
                    0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
            -->static struct list_head *mount_hashtable =(struct list_head *)__get_free_page(GFP_ATOMIC);
            /*注册&挂载sysfs虚拟文件系统*/
            -->sysfs_init()
                /*6.kmem_cache用于缓存sysfs_dirent结构体*/
                -->struct kmem_cache *sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache",
            /*对应的应该就是"/fs/"跟目录*/                      sizeof(struct sysfs_dirent),0, 0, NULL);
            -->fs_kobj = kobject_create_and_add("fs", NULL);
            /*注册rootfs虚拟文件系统*/
            -->init_rootfs();
            /*挂载rootfs虚拟文件系统*/
            -->init_mount_tree();
        -->bdev_cache_init();
            /*7.kmem_cache用于缓存bdev_inode结构体*/
            -->struct kmem_cache *bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
                    0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_PANIC),init_once);
            /*注册的这是啥文件系统啊?*/
            -->register_filesystem(&bd_type);
            /*挂载*/
            -->struct vfsmount *bd_mnt = kern_mount(&bd_type);
            -->struct super_block *blockdev_superblock = bd_mnt->mnt_sb;    /* For writeback */
            /*字符设备相关的初始化*/
            -->chrdev_init();
原文地址:https://www.cnblogs.com/yangjiguang/p/8445357.html