Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


❑ d_parentis a pointer to the parent directory in whosed_subdirslist thedentryinstance is
located. In the root directory (which has no parent directory),d_parentpoints to its owndentry
instance.
❑ d_mountedis set to 1 if thedentryobject represents a mount point; otherwise, its value is 0.
❑ d_aliaslinks thedentryobjects of identical files. This situation arises when links are used to
make the file available under two different names. This list is linked from the corresponding
inode by using itsi_dentryelement as a list head. The individualdentryobjects are linked by
d_alias.
❑ d_oppoints to a structure with function pointers to provide various operations fordentry
objects. The operations must be implemented by the underlying filesystems. I discuss the
structure contents below.
❑ s_sbis a pointer to the filesystem superblock instance to which thedentryobject belongs.
The pointer enables the individualdentryinstances to be distributed over the available (and
mounted) filesystems. The dentry tree can be splitinto several subtrees because each superblock
structure contains a pointer to thedentryelement of the directory on which the filesystem is
mounted.

All active instances ofdentryin memory are held in a hash table implemented using the global variable
dentry_hashtablefromfs/dcache.c.Anoverflowchainimplementedwithd_hashis used to resolve
hash collisions. I refer to this hash table as theglobal dentry hash tablein the following.

The kernel also has a second dentry list headed by the global variabledentry_unused(also initialized in
fs/dcache.c). Which entries does this list contain? All dentry instances whose usage counter (d_count)
has reached 0 (and are therefore no longer used by any process) are automatically placed on this list. You
will see how the list is managed in the next section, which deals with the structure of the dentry cache.

Dentry objects are very convenient when the kernel needs to obtain information on
files, but they are not the principal object for representing files and their
contents — this role is assigned to inodes. For example, there is no way of
ascertaining whether a file wasmodified or not by reference to adentryobject. It is
essential to look at the corresponding inode instance to find out — and this instance
is easy to find using thedentryobject.

Cache Organization


The dentry structures not only make working with filesystem structures easier, but are also crucial to
system performance. They accelerate work with the VFS by keeping communication with the underlying
filesystem implementations to a minimum.

Each request forwarded to the underlying implementations by the VFS leads to the creation of a new
dentryobject to hold the request results. These objects are held in a cache so that they can be accessed
faster the next time they are needed and operations can be performed more quickly. How is the cache
organized? It comprises the following two components to organizedentryobjects in memory:


  1. A hash table (dentry_hashtable) containing all dentry objects.

  2. An LRU (least recently used) list in which objects no longer used are granted a last period of
    grace before they are removed from memory.

Free download pdf