The name lookup cache is the mechanism to allow the file system type dependent algorithms to quickly resolve a file's vnode from its pathname. The name lookup cache is generally accessed through the higher-level
namei(9) interface.
The name of the file is used to lookup an entry associated with the file in the name lookup cache. If no entry is found, one is created for it. If an entry is found, the information obtained from the cache lookup contains information about the file which is useful to the file system type dependent functions.
The name lookup cache is managed by a least recently used (LRU) algorithm so frequently used names will hang around. The cache itself is a hash table called
nchashtbl, containing
namecache entries that are allocated dynamically from a kernel memory pool. Each entry has the following structure:
#define NCHNAMLEN 31 /* maximum name segment length */
struct namecache {
LIST_ENTRY(namecache) nc_hash; /* hash chain */
TAILQ_ENTRY(namecache) nc_lru; /* LRU chain */
LIST_ENTRY(namecache) nc_vhash; /* directory hash chain */
LIST_ENTRY(namecache) nc_dvlist;
struct vnode *nc_dvp; /* vnode of parent of name */
LIST_ENTRY(namecache) nc_vlist;
struct vnode *nc_vp; /* vnode the name refers to */
int nc_flags; /* copy of componentname's ISWHITEOUT */
char nc_nlen; /* length of name */
char nc_name[NCHNAMLEN]; /* segment name */
};
For simplicity (and economy of storage), names longer than a maximum length of NCHNAMLEN are not cached; they occur infrequently in any case, and are almost never of interest.
Each
namecache entry can appear on two hash chains in addition to
nshashtbl:
ncvhashtbl (the name cache directory hash chain), and
nclruhead (the name cache LRU chain). The hash chains are indexed by a hash value obtained from the file's name and the address of its parent directory vnode.
Functions which access to the name cache pass arguments in the partially initialised
componentname structure. See
vnodeops(9) for details on this structure.