Linux虚拟文件系统在内核初始化的start_kernel()函数中主要调用两个函数来实现。
[cpp]
- asmlinkage void __init start_kernel(void) {
- …… vfs_caches_init_early();
- …… vfs_caches_init(totalram_pages);
- …… }
一、早期初始化
虚拟文件系统的早期初始化有函数vfs_caches_init_early()实现,主要负责dentry和inode的hashtable的初始化工作。
[cpp]- /*在start_kernel中调用,用于文件系统中早期的初始化*/ void __init vfs_caches_init_early(void)
- { /*初始化两个hashtable*/
- dcache_init_early(); inode_init_early();
- }
1.1 dcache
[cpp]- static void __init dcache_init_early(void) {
- int loop;
- /* If hashes are distributed across NUMA nodes, defer * hash allocation until vmalloc space is available.
- */ if (hashdist)
- return; /*dentry hashtable的空间分配*/
- dentry_hashtable = alloc_large_system_hash("Dentry cache",
- sizeof(struct hlist_head), dhash_entries,
- 13, HASH_EARLY,
- &d_hash_shift, &d_hash_mask,
- 0); /*hashtable的各个链表初始化*/
- for (loop = 0; loop < (1 << d_hash_shift); loop++) INIT_HLIST_HEAD(&dentry_hashtable[loop]);
- }
1.2 inode
[cpp]- /* * Initialize the waitqueues and inode hash table.
- */ void __init inode_init_early(void)
- { int loop;
- /* If hashes are distributed across NUMA nodes, defer
- * hash allocation until vmalloc space is available. */
- if (hashdist) return;
- /*从cache中分配inode hashtable的内存空间*/ inode_hashtable =
- alloc_large_system_hash("Inode-cache", sizeof(struct hlist_head),
- ihash_entries, 14,
- HASH_EARLY, &i_hash_shift,
- &i_hash_mask, 0);
- /*初始化hashtable 的各个链表*/ for (loop = 0; loop < (1 << i_hash_shift); loop++)
- INIT_HLIST_HEAD(&inode_hashtable[loop]); }