触碰虚拟文件系统

5.6 触碰虚拟文件系统

回到start_kernel中,下面我们该第一次接触文件系统了,582行执行vfs_caches_init_early

 

void __init vfs_caches_init_early(void)

{

       dcache_init_early();

       inode_init_early();

}

 

vfs_caches_init_early调用两个函数dcache_init_earlyinode_init_early。内核第一次触碰文件系统的主要目的就是初始化VFS的两个重要数据结构dcacheinode的缓存。

dcache_init_early来自fs/dcache.c

 

2287static void __init dcache_init_early(void)

2288{

2289        int loop;

2290

2291        /* If hashes are distributed across NUMA nodes, defer

2292         * hash allocation until vmalloc space is available.

2293         */

2294        if (hashdist)

2295                return;

2296

2297        dentry_hashtable =

2298                alloc_large_system_hash("Dentry cache",

2299                                        sizeof(struct hlist_head),

2300                                        dhash_entries,

2301                                        13,

2302                                        HASH_EARLY,

2303                                        &d_hash_shift,

2304                                        &d_hash_mask,

2305                                        0);

2306

2307        for (loop = 0; loop < (1 << d_hash_shift); loop++)

2308                INIT_HLIST_HEAD(&dentry_hashtable[loop]);

2309}

 

inode_init_early来自fs/inode.c

 

1539void __init inode_init_early(void)

1540{

1541        int loop;

1542

1543        /* If hashes are distributed across NUMA nodes, defer

1544         * hash allocation until vmalloc space is available.

1545         */

1546        if (hashdist)

1547                return;

1548

1549        inode_hashtable =

1550                alloc_large_system_hash("Inode-cache",

1551                                        sizeof(struct hlist_head),

1552                                        ihash_entries,

1553                                        14,

1554                                        HASH_EARLY,

1555                                        &i_hash_shift,

1556                                        &i_hash_mask,

1557                                        0);

1558

1559        for (loop = 0; loop < (1 << i_hash_shift); loop++)

1560                INIT_HLIST_HEAD(&inode_hashtable[loop]);

1561}

 

两个函数都是调用alloc_large_system_hash函数分别为dentry_hashtableinode_hashtable分配空间。至于这两个散列的用途,请参考博客“把Linux中的VFS对象串联起来”http://blog.csdn.net/yunsongice/archive/2010/06/21/5683859.aspx

你可能感兴趣的:(数据结构,linux,cache,struct,System,Allocation)