[File System] File System Study Notes (3) --- directory item cache dentry

Source: Internet
Author: User

Directory item cache --- dentry
Linux uses the directory item cache (dentry cache) to quickly access the results of previous search operations,

[CPP]View plaincopy
  1. Struct dentry {
  2. Atomic_t d_count; // directory item object reference counter
  3. Unsigned int d_flags;/* protected by d_lock */
  4. Spinlock_t d_lock;/* per dentry lock */
  5. Struct inode * d_inode;/* Where the name belongs to-null is
  6. Struct hlist_node d_hash;/* link to the hash linked list of dentry cache */
  7. Struct dentry * d_parent;/* pointer to the parent dentry structure */
  8. Struct qstr d_name; // file name
  9. Struct list_head d_lru;/* LRU list */
  10. Union {
  11. Struct list_head d_child;/* child of parent list */
  12. Struct rcu_head d_rcu;
  13. } D_u;
  14. Struct list_head d_subdirs;/* is the head of the subitem linked list. The subitem may be a directory or a file. All subitems must be linked to this linked list ,*/
  15. Struct list_head d_alias;/* inode alias list */
  16. Unsigned long d_time;/* used by d_revalidate */
  17. Struct dentry_operations * d_op;
  18. Struct super_block * d_sb;/* the root of the dentry tree */
  19. Void * d_fsdata;/* FS-specific data */
  20. Int d_mounted;/* Indicates whether dentry is a mount point. If it is a mount point, this member is not 0.
  21. Unsigned char d_iname [dname_inline_len_min];/* Small names */
  22. };

Each directory item object has four states:
Idle status: the directory item object does not contain valid information and is not used by VFS.
Unused Status: Not used by the kernel. The value of d_count is 0, and the value of d_inode is still directed to the relevant index node.
Active Status: in use, the value of d_count is greater than 0, and the value of d_inode is directed to the relevant index node.
Negative status: The index node associated with the directory item does not exist, and the corresponding disk index node has been deleted.

The main purpose of the dentry structure is to establish an association between the file name and the relevant inode node. The three members of the dentry structure are used for this purpose.
D_inode is a pointer to the relevant inode instance.
D_name specifies the file name.
If the file name contains only a small number of characters, it is saved in d_iname to facilitate accelerated access. The short file name generally does not contain 16 characters.


Dentry Cache Organization:
Every request sent by VFS to the underlying implementation will lead to the creation of a new dentry object. These objects are stored in a cache and can be accessed more quickly as needed, the dentery in the memory mainly involves the following two parts:
(1) A hash contains multiple dentry objects, which are implemented by the dentry_hashtable array. Each array element is a pointer to a linked list, this kind of linked list is to form a hash of directory items with the same hash value.

(2) a lru (least recently used) linked list,

 

Role Analysis of dentry

A. The dentry of each file is linked to the dentry of the parent directory, forming the structure tree of the file system. For example, there is a directory/usr, that is, the d_child member of USR dentry is linked to the d_subdirs Member of the root directory/dentry. The sub-directories under the parent directory are searched through the hash table.
B. All dentry points to a dentry_hashtable. Dentry_hashtable is an array and the array members are the data structure of the hash linked list. If a file has been opened, the dentry structure of the file should exist in the memory, the dentry is linked to a hash linked list header in the dentry_hashtable array.

[File System] File System Study Notes (3) --- directory item cache dentry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.