Saturday, November 27, 2010

Linux file system metadata use count of mechanism

(2) create a directory to create the directory and create a file that is similar, here we take a quick look at the path is invoked.

Create a directory via system calls sys_mkdir (). The path on the dentry is as follows: sys_mkdir () > sys_mkdirat () > lookup_create () > lookup_hash () > __lookup_has () can be seen, this is not the same as previous "create file" is the same as described. About inodes path: sys_mkdir () > sys_mkdirat () > vfs_mkdir () > i_op-> mkdir () will eventually call the specific file system mkdir function. Here to Ext2, for example, the calling process is as follows: sys_mkdir () > sys_mkdirat () > vfs_mkdir () > i_op-> mkdir () can be seen, this is not the same as previous "create files" in the same. From here you can see that from the in-memory metadata structure, Linux on the management of files and directories are the same. Lookup operations to create an object (file or directory), you want to use this object, you must first find. Find operations is the key meta-data use, basically all metadata operations will find operation as start, because only found the metadata to further manipulate it. Even for the create operation, a start is to find, just because you want to create the object does not yet exist, it will find failed before. Find the entry point function is operated __link_path_walk (), the calling process is as follows: __link_path_walk () > do_lookup () here, you want to do is find the memory of the appropriate files dentry structure. This will be divided into two conditions: (1) the dentry structure in memory, by hash can obtain the dentry structure, and use count incremented. Do_lookup () > __d_lookup () > atomic_inc (& dentry-> d_count) (2) the dentry structure is not in the memory at this point, the dentry structure might never built in memory, or memory existed, but already in the queue from the LRU dentry_unused is swapped out of memory. In any case, you need to read metadata from a disk, set up in memory and the inode structure dentry. When the step is: first in memory is assigned a dentry structure: do_lookup () > __d_lookup () > atomic_inc (& dentry-> d_count) d_alloc here () and in front of the "creation", the use of the dentry is initialized to 1, the count and its parent directory, use the count incremented by dget (). Assigned a dentry structure, it is necessary to identify from the disk corresponding to the element data. This process may vary due to file system, so by the parent node of the inode-> i_op in function. Do_lookup () > __d_lookup () > atomic_inc (& dentry-> d_count) here to Ext2, for example, the call is ext2_create (), the process is as follows: (1) ext2_lookup () > iget (dir-> i_sb, ino); (2) ext2_lookup () > d_splice_alias () > __d_find_alias () > __dget_locked () > atomic_inc (& dentry-> d_count); the former call iget (), first by looking at ino inodecache inode, if found, returns and increase its reference count; if not found, it allocates a new (call alloc_inode (), use the count will be initialized to 1, the reference to the previous "create operation"), and from the disk into the appropriate index node, set up in memory in the inode structure. The latter is the dentry and inode structure bound, and increments the count of the dentry. To sum up, the find operation of the main process is the in-memory lookup dentry structure, if found to increase its usage count; if you don't find it to disk to get and set up in memory and the inode structure dentry, at the same time they use count initialized to 1. So a find operation will increase the dentry usage counts, or increment, or initialized to 1.

No comments:

Post a Comment