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

字体大小: 中小 标准 ->行高大小: 标准
Linux虚拟文件系统在内核初始化的start_kernel()函数中主要调用两个函数来实现。 [cpp]
  1. asmlinkage void __init start_kernel(void)   {  
  2.     ……       vfs_caches_init_early();  
  3.     ……       vfs_caches_init(totalram_pages);  
  4.     ……   }  

一、早期初始化

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

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

1.1 dcache

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

1.2  inode

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

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/57833.html