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]);
- }