歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux虛擬文件系統(內核初始化<一>)

Linux虛擬文件系統(內核初始化<一>)

日期:2017/2/28 15:57:11   编辑: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()實現,主要負責dentry和inode的hashtable的初始化工作。

[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. /* If hashes are distributed across NUMA nodes, defer
  5. * hash allocation until vmalloc space is available.
  6. */
  7. if (hashdist)
  8. return;
  9. /*dentry hashtable的空間分配*/
  10. dentry_hashtable =
  11. alloc_large_system_hash("Dentry cache",
  12. sizeof(struct hlist_head),
  13. dhash_entries,
  14. 13,
  15. HASH_EARLY,
  16. &d_hash_shift,
  17. &d_hash_mask,
  18. 0);
  19. /*hashtable的各個鏈表初始化*/
  20. for (loop = 0; loop < (1 << d_hash_shift); loop++)
  21. INIT_HLIST_HEAD(&dentry_hashtable[loop]);
  22. }

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. /* If hashes are distributed across NUMA nodes, defer
  8. * hash allocation until vmalloc space is available.
  9. */
  10. if (hashdist)
  11. return;
  12. /*從cache中分配inode hashtable的內存空間*/
  13. inode_hashtable =
  14. alloc_large_system_hash("Inode-cache",
  15. sizeof(struct hlist_head),
  16. ihash_entries,
  17. 14,
  18. HASH_EARLY,
  19. &i_hash_shift,
  20. &i_hash_mask,
  21. 0);
  22. /*初始化hashtable 的各個鏈表*/
  23. for (loop = 0; loop < (1 << i_hash_shift); loop++)
  24. INIT_HLIST_HEAD(&inode_hashtable[loop]);
  25. }
Copyright © Linux教程網 All Rights Reserved