Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


int d_mounted;
unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
};

Thedentryinstances form a network to map the structure of the filesystem. All files and subdirectories
associated with adentryinstance for a given directory are included in thed_subdirslist (also asdentry
instances);d_childin the child elements links the instances.^11


However, the topology of the filesystem is not mapped in full because the dentry cache only ever contains
a small extract of it. The most frequently used files and directories are held in memory. In principle, it
wouldbepossibletogeneratedentryentries forallfilesystem objects, but RAM space and performance
reasons militate against this.


As frequently noted, the main purpose of thedentrystructure is to establish a link between a filename
and its associated inode. Three elements are used to do this:



  1. d_inodeis a pointer to the relevant inode instance.


A null pointer is used ford_inodeif adentryobject is created for a nonexistent
filename. This helps speed lookup for nonexistent filenames which takes just as
long as lookup for files that actually exist.


  1. d_namespecifies the name of the file.qstris a kernel string wrapper. It stores the actual
    char*string as well as its length and hash sum; this makes it easier to handle.


No absolute filenames are stored, only the last component — for example, only
emacsfor/usr/bin/emacs— the reason being that the directory hierarchy is already
mapped by the above list structure.


  1. If a filename consists of only a few characters, it is held ind_inameinstead of indnameto
    speed up access.
    Theminimumlength up to which a filename is still regarded as ‘‘short‘‘ is specified by
    DNAME_INLINE_NAME_LENand is (at least) 16 characters. However, the kernel can sometimes
    accommodate longer filenames because the element is at the end of the structure and the
    cache line with the data may still have space available (this depends on the architecture and
    the processor type).


The remaining elements have the following meanings:


❑ d_flagscan contain several flags defined ininclude/linux/dcache.h. However, only two of
them are relevant for our purposes:DCACHE_DISCONNECTEDspecifies that a dentry is currently not
connected to the dentry tree of the superblock.DCACHE_UNHASHEDstates that thedentryinstance
is not contained in the hash table of any inode. Note that both flags are completely independent
of each other.

(^11) The RCU element that shares a union with the list head comes intoplay when list elements are deleted, but is not interesting for
our purposes.

Free download pdf