Linux虚拟文件系统(内核初始化<一>)


Linux虚拟文件系统在内核初始化的start_kernel()函数中主要调用两个函数来实现。 [cpp]
  1. asmlinkage void __init start_kernel(void)  
  2. {  
  3.     ……  
  4.     vfs_caches_init_early();  
  5.     ……  
  6.     vfs_caches_init(totalram_pages);  
  7.     ……  
  8. }  

一、早期初始化

虚拟文件系统的早期初始化有函数vfs_caches_init_early()实现,主要负责dentryinodehashtable的初始化工作。

[cpp]
  1. /*在start_kernel中调用,用于文件系统中早期的初始化*/  
  2. void __init vfs_caches_init_early(void)  
  3. {  
  4.     /*初始化两个hashtable*/  
  5.     dcache_init_early();  
  6.     inode_init_early();  
  7. }  

1.1 dcache

[cpp]
  1. static void __init dcache_init_early(void)  
  2. {  
  3.     int loop;  
  4.   
  5.     /* If hashes are distributed across NUMA nodes, defer 
  6.      * hash allocation until vmalloc space is available. 
  7.      */  
  8.     if (hashdist)  
  9.         return;  
  10.     /*dentry hashtable的空间分配*/  
  11.     dentry_hashtable =  
  12.         alloc_large_system_hash("Dentry cache",  
  13.                     sizeof(struct hlist_head),  
  14.                     dhash_entries,  
  15.                     13,  
  16.                     HASH_EARLY,  
  17.                     &d_hash_shift,  
  18.                     &d_hash_mask,  
  19.                     0);  
  20.     /*hashtable的各个链表初始化*/  
  21.     for (loop = 0; loop < (1 << d_hash_shift); loop++)  
  22.         INIT_HLIST_HEAD(&dentry_hashtable[loop]);  
  23. }  

1.2  inode

[cpp]
  1. /* 
  2.  * Initialize the waitqueues and inode hash table. 
  3.  */  
  4. void __init inode_init_early(void)  
  5. {  
  6.     int loop;  
  7.   
  8.     /* If hashes are distributed across NUMA nodes, defer 
  9.      * hash allocation until vmalloc space is available. 
  10.      */  
  11.     if (hashdist)  
  12.         return;  
  13.     /*从cache中分配inode hashtable的内存空间*/  
  14.     inode_hashtable =  
  15.         alloc_large_system_hash("Inode-cache",  
  16.                     sizeof(struct hlist_head),  
  17.                     ihash_entries,  
  18.                     14,  
  19.                     HASH_EARLY,  
  20.                     &i_hash_shift,  
  21.                     &i_hash_mask,  
  22.                     0);  
  23.     /*初始化hashtable 的各个链表*/  
  24.     for (loop = 0; loop < (1 << i_hash_shift); loop++)  
  25.         INIT_HLIST_HEAD(&inode_hashtable[loop]);  
  26. }  
  • 1
  • 2
  • 3
  • 下一页

相关内容