Directory Item Caching---dentry
Linux uses directory item caching (Dentry caching) to quickly access the results of previous lookup operations,
struct Dentry {
atomic_t d_count;//directory Entry Object reference counter, D_count value plus 1 when a process occupies the file. The size of the value is judged when the file is deleted by a procedure.
unsigned int d_flags/* protected by D_lock * *
spinlock_t d_lock/* per dentry lock/
struct inode *d_inod E /* Where the name belongs to-null
is struct hlist_node d_hash;/* link to dentry cache hash list * * struct dentry *d_par
Ent /* Pointer to Parent dentry structure
/struct qstr d_name;//file name struct list_head d_lru
;/* LRU List/
Union {
struct LIST_H EAD D_child; /* Child of Parent list */
struct rcu_head d_rcu;
} D_u;
struct List_head d_subdirs; /* is the link header of the subkey, the subkey may be a directory or a file, all the subkeys will be linked to this list, * *
struct list_head d_alias; * inode alias list/
unsigned long D_tim E /* Used by d_revalidate * *
struct dentry_operations *d_op;
struct Super_block *d_sb; /* The root of the dentry tree
/void *d_fsdata/* fs-specific data/
int d_mounted/* Indicates whether the dentry is a mount point and if it is mounted Point, the member is not 0
unsigned char d_iname[dname_inline_len_min];/* Small names/
};
Each directory item object has four states, respectively:
Idle state: The state Directory item object does not contain valid information and is not used by the VFS
Unused status: Not currently in use by the kernel, D_count value is 0,d_inode still point to the associated index node
Using state: Is being used, the value of D_count is greater than 0,d_inode still pointing to the associated index node
Negative state: The index node associated with the directory entry 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 filename and the associated inode node, which three members of the DENTRY structure use for that purpose.
D_inode is a pointer to the associated Inode instance
D_NAME Specifies the name of the file
If the filename is composed of only a small number of characters, it is saved in d_iname to facilitate faster access, and the short file name generally does not operate 16 characters
dentry Caching organization:
Each request sent by the VFS to the underlying implementation will result in the creation of a new Dentry object, which is saved in a cache and can be accessed more quickly the next time it is needed, dentery in memory to organize mainly the following two parts
(1) A hash table contains many Dentry objects, which are implemented by the dentry_hashtable array, and each array element is a pointer to a linked list that hashes the entries with the same hash value.
(2) A LRU (least recently used) linked list,
analysis of the function 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, which is the D_child member of the dentry of USR that is linked to the D_subdirs member of the root directory/Dentry. Subdirectories located through the parent directory lookup directory are found through a hash table.
b, all the dentry are pointing to a dentry_hashtable. Dentry_hashtable is an array whose members are the data structures of a hash list, and if a file has been opened, there should be a dentry structure of the file in memory, and the dentry is linked to Dentry_ Hashtable a hash-linked header of an array.