Date: Mon, 5 May 1997 13:59:15 -0700 (MST) From: Terry Lambert <terry@lambert.org> To: current@freebsd.org Subject: DOC: NAME CACHE USAGE Message-ID: <199705052059.NAA16562@phaeton.artisoft.com>
next in thread | raw e-mail | index | archive | help
With all of Poul's puttering around in the name cache code (I still think the cache data should be a pointer into the directory vnode page where the actual name is, instead of making a copy of the name in another buffer, considering the directory vnode must be in core for there to be a cache reference, especially after his changes), I thought it would be the right time to post this. This is a document that I made prepatory to doing some work to move the cache lookup and entry out of the FS specific code and into common code, so that you wouldn't even have to make VOP calls if you got cache hits. This design offers the bonus of making the FS code itself smaller for each FS, and by making the code more bullet proof by making the usage entirely uniform across all FS's. I haven't really been able to pursue this work because it's all I can do to track current and repair conflicts on my existing changes 8-(. In any case, this information should be useful to anyone wanting to call the name cache from their FS code (even though it shouldn't be called from FS code at all, in an ideal world). It should also provide some usage information to Poul so that he can better direct his efforts to optimize common cases. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. ============================================================================= HOW THE BSD DIRECTORY NAME CACHE CURRENTLY WORKS Note1: This diagram refers to the ufs/cache interaction only. Other File Systems which are cache users are not described (two are known to be erroneous in certain cases). Note2: The cache_purge() and cache_purgevfs() calls on mount/unmount operations are not described in detail. In general, mount point vnodes that are covered are purged with cache_purge(), and file systems that are unmounted are purged with cache_purgevfs(). Note3: All vnodes allocated or recovered from the freelist by the getnewvnode() are purged as part of initialization. ,----------,----------,----------,-----------------------------------. VOP_ | RECLAIM | RENAME | RMDIR | LOOKUP | nameiop | | | |LOOKUP |CREATE |RENAME |DELETE | `----------`----------`----------`--------`--------`--------`--------' cache_lookup() ---------,----------,----------,----------,--------,--------,--------,--------. NO ENTRY | | | | cache | cache | cache | cache | NO EXIST | | | | miss | miss | miss | miss | ---------+----------+----------+----------+--------+--------+--------+--------. NO ENTRY | | | | cache | cache | cache | cache | EXIST | | | | miss | miss | miss | miss | ---------+----------+----------+----------+--------+--------+--------+--------. NEG ENTRY| | | | cache | PURGE3 | PURGE2 |PURGE2 | VALID | | | | hit(-) | | | | ---------+----------+----------+----------+--------+--------+--------+--------. ENTRY | | | | cache | cache | PURGE2 |PURGE2 | VALID | | | | hit | hit | | | ---------+----------+----------+----------+--------+--------+--------+--------. NEG ENTRY| | | | PURGE1 | PURGE1 | PURGE1 | PURGE1 | INVALID | | | | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. ENTRY | | | | PURGE1 | PURGE1 | PURGE1 | PURGE1 | INVALID | | | | | | | | ---------`----------`----------`----------`--------`--------`--------`--------. cache_enter() ---------,----------,----------,----------,--------,--------,--------,--------. NO ENTRY | | | | make | skip | skip | skip | NO EXIST | | | | entry | entry | entry | entry | ---------+----------+----------+----------+--------+--------+--------+--------. NO ENTRY | | | | make | make | skip | skip | EXIST | | | | entry | entry | entry | entry | ---------+----------+----------+----------+--------+--------+--------+--------. NEG ENTRY| | | | | | | | VALID | | | | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. ENTRY | | | | | | | | VALID | | | | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. NEG ENTRY| | | | | | | | INVALID | | | | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. ENTRY | | | | | | | | INVALID | | | | | | | | ---------`----------`----------`----------`--------`--------`--------`--------. cache_purge() ---------,----------,----------,----------,--------,--------,--------,--------. NO ENTRY | cache | cache | cache | | | | | NO EXIST | purge1 | purge2 | purge3 | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. NO ENTRY | cache | cache | cache | | | | | EXIST | purge1 | purge2 | purge3 | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. NEG ENTRY| cache | cache | cache | | | | | VALID | purge1 | purge2 | purge3 | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. ENTRY | cache | cache | cache | | | | | VALID | purge1 | purge2 | purge3 | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. NEG ENTRY| cache | cache | cache | | | | | INVALID | purge1 | purge2 | purge3 | | | | | ---------+----------+----------+----------+--------+--------+--------+--------. ENTRY | cache | cache | cache | | | | | INVALID | purge1 | purge2 | purge3 | | | | | ---------`----------`----------`----------`--------`--------`--------`--------. ============================================================================= KEY ============================================================================= cache Entry not present in cache; cache Entry present in cache; miss lookup returns 0 hit entry returned (may be neg) PURGE1 cache_purge has been called PURGE2 The MAKEENTRY flag(1) is to invalidate the entry not set; delete the entry PURGE3 Negative entries are purged skip The negative cache_enter() if nameiop is CREATE(2) entry won't happen for CREATE(3) make An entry, positive or cache Unconditionally invalidate entry negative, is made purge1 the vnode cache Conditionally invalidate cache The dir being rmdir'ed and purge2 the vnode(4) purge3 its parent are invalidated (1) The MAKEENTRY flag is set by default. It is unset by lookup() before VOP_LOOKUP is called IFF the component being looked up is the last component AND 'docache' is zero. 'docache' will be zero IFF: the NOCACHE flag is set on NDINIT(), OR the nameiop is DELETE, OR: IFF the nameiop *isn't* CREATE and either the WANTPARENT or LOCKPARENT flag is set on NDINIT(). The RENAME nameiop is only ever used with the LOCKPARENT flag set. The DELETE nameiop is called with WANTPARENT in the general case and LOCKPARENT in the VOP_RENAME case. (2) The CREATE nameiop will not unset the MAKEENTRY flag. This is somewhat bogus in implementation, but the purpose is to use the CREATE nameiop as an intention mode to get a directory slot to be used in the actual VOP_CREATE() later. (3) Or if the MAKEENTRY flag is not set. Which it never is in the RENAME/DELETE nameiop case in the current code. (4) The "to" vnode is invalidated if it is a directory. This is not the right thing to do in several cases, but it happens anyway: if the ufs_dirrewrite() fails or if the target directory and the source directory are the same vnode. The "from" directory is invalidated in the case of a successful rename of the directory (again, even in the case that the subsequent entry removal fails (and therefore the source directory is not changed). =============================================================================
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199705052059.NAA16562>