2005-01-06 23:35:40 +00:00
|
|
|
/*-
|
1997-02-10 02:22:35 +00:00
|
|
|
* Copyright (c) 1989, 1993, 1995
|
1994-05-24 10:09:53 +00:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1997-02-10 02:22:35 +00:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Poul-Henning Kamp of the FreeBSD Project.
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1997-03-08 15:22:14 +00:00
|
|
|
* @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
#include "opt_kdtrace.h"
|
2009-03-20 10:47:16 +00:00
|
|
|
#include "opt_ktrace.h"
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
2008-09-18 20:04:22 +00:00
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/fnv_hash.h>
|
1995-12-14 09:55:16 +00:00
|
|
|
#include <sys/kernel.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
2008-09-18 20:04:22 +00:00
|
|
|
#include <sys/malloc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
2008-09-18 20:04:22 +00:00
|
|
|
#include <sys/proc.h>
|
2009-01-28 19:05:18 +00:00
|
|
|
#include <sys/rwlock.h>
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
#include <sys/sdt.h>
|
2002-09-02 22:40:30 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
2008-09-18 20:04:22 +00:00
|
|
|
#include <sys/sysctl.h>
|
1999-10-03 12:18:29 +00:00
|
|
|
#include <sys/sysproto.h>
|
2008-09-18 20:04:22 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/vnode.h>
|
2009-03-20 10:47:16 +00:00
|
|
|
#ifdef KTRACE
|
|
|
|
#include <sys/ktrace.h>
|
|
|
|
#endif
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2003-06-13 08:46:13 +00:00
|
|
|
#include <vm/uma.h>
|
|
|
|
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROVIDER_DECLARE(vfs);
|
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, enter, done, "struct vnode *", "char *",
|
|
|
|
"struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, enter_negative, done, "struct vnode *",
|
|
|
|
"char *");
|
|
|
|
SDT_PROBE_DEFINE1(vfs, namecache, fullpath, entry, "struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, fullpath, hit, "struct vnode *",
|
|
|
|
"struct char *", "struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE1(vfs, namecache, fullpath, miss, "struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, fullpath, return, "int", "struct vnode *",
|
|
|
|
"struct char *");
|
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, lookup, hit, "struct vnode *", "char *",
|
|
|
|
"struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, lookup, hit_negative, "struct vnode *",
|
|
|
|
"char *");
|
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, lookup, miss, "struct vnode *",
|
|
|
|
"char *");
|
|
|
|
SDT_PROBE_DEFINE1(vfs, namecache, purge, done, "struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE1(vfs, namecache, purge_negative, done, "struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE1(vfs, namecache, purgevfs, done, "struct mount *");
|
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, zap, done, "struct vnode *", "char *",
|
|
|
|
"struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, zap_negative, done, "struct vnode *",
|
|
|
|
"char *");
|
|
|
|
|
2000-04-26 11:57:45 +00:00
|
|
|
/*
|
|
|
|
* This structure describes the elements in the cache of recent
|
|
|
|
* names looked up by namei.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct namecache {
|
2000-05-26 02:09:24 +00:00
|
|
|
LIST_ENTRY(namecache) nc_hash; /* hash chain */
|
|
|
|
LIST_ENTRY(namecache) nc_src; /* source vnode list */
|
|
|
|
TAILQ_ENTRY(namecache) nc_dst; /* destination vnode list */
|
2000-04-26 11:57:45 +00:00
|
|
|
struct vnode *nc_dvp; /* vnode of parent of name */
|
|
|
|
struct vnode *nc_vp; /* vnode the name refers to */
|
|
|
|
u_char nc_flag; /* flag bits */
|
|
|
|
u_char nc_nlen; /* length of name */
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
char nc_name[0]; /* segment name + nul */
|
2000-04-26 11:57:45 +00:00
|
|
|
};
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Name caching works as follows:
|
|
|
|
*
|
|
|
|
* Names found by directory scans are retained in a cache
|
|
|
|
* for future reference. It is managed LRU, so frequently
|
|
|
|
* used names will hang around. Cache is indexed by hash value
|
|
|
|
* obtained from (vp, name) where vp refers to the directory
|
|
|
|
* containing name.
|
|
|
|
*
|
1997-02-10 02:22:35 +00:00
|
|
|
* If it is a "negative" entry, (i.e. for a name that is known NOT to
|
|
|
|
* exist) the vnode pointer will be NULL.
|
1995-03-09 20:23:45 +00:00
|
|
|
*
|
1994-05-24 10:09:53 +00:00
|
|
|
* Upon reaching the last segment of a path, if the reference
|
|
|
|
* is for DELETE, or NOCACHE is set (rewrite), and the
|
|
|
|
* name is located in the cache, it will be dropped.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structures associated with name cacheing.
|
|
|
|
*/
|
2001-03-20 02:10:18 +00:00
|
|
|
#define NCHHASH(hash) \
|
|
|
|
(&nchashtbl[(hash) & nchash])
|
2000-05-26 02:09:24 +00:00
|
|
|
static LIST_HEAD(nchashhead, namecache) *nchashtbl; /* Hash Table */
|
|
|
|
static TAILQ_HEAD(, namecache) ncneg; /* Hash Table */
|
1997-03-08 15:22:14 +00:00
|
|
|
static u_long nchash; /* size of hash table */
|
2000-07-05 07:46:41 +00:00
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, 0, "");
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
static u_long ncnegfactor = 16; /* ratio of negative entries */
|
2000-07-05 07:46:41 +00:00
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, ncnegfactor, CTLFLAG_RW, &ncnegfactor, 0, "");
|
2002-03-05 15:38:49 +00:00
|
|
|
static u_long numneg; /* number of cache entries allocated */
|
2000-07-05 07:46:41 +00:00
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, numneg, CTLFLAG_RD, &numneg, 0, "");
|
1997-03-08 15:22:14 +00:00
|
|
|
static u_long numcache; /* number of cache entries allocated */
|
2000-07-05 07:46:41 +00:00
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, numcache, CTLFLAG_RD, &numcache, 0, "");
|
2001-04-18 11:19:50 +00:00
|
|
|
static u_long numcachehv; /* number of cache entries with vnodes held */
|
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, numcachehv, CTLFLAG_RD, &numcachehv, 0, "");
|
2001-10-01 04:33:35 +00:00
|
|
|
#if 0
|
2001-04-18 11:19:50 +00:00
|
|
|
static u_long numcachepl; /* number of cache purge for leaf entries */
|
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, numcachepl, CTLFLAG_RD, &numcachepl, 0, "");
|
2001-10-01 04:33:35 +00:00
|
|
|
#endif
|
1997-02-10 02:22:35 +00:00
|
|
|
struct nchstats nchstats; /* cache effectiveness statistics */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
static struct rwlock cache_lock;
|
|
|
|
RW_SYSINIT(vfscache, &cache_lock, "Name Cache");
|
2003-10-05 07:13:50 +00:00
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
#define CACHE_UPGRADE_LOCK() rw_try_upgrade(&cache_lock)
|
|
|
|
#define CACHE_RLOCK() rw_rlock(&cache_lock)
|
|
|
|
#define CACHE_RUNLOCK() rw_runlock(&cache_lock)
|
|
|
|
#define CACHE_WLOCK() rw_wlock(&cache_lock)
|
|
|
|
#define CACHE_WUNLOCK() rw_wunlock(&cache_lock)
|
2003-10-05 07:13:50 +00:00
|
|
|
|
2003-06-13 08:46:13 +00:00
|
|
|
/*
|
|
|
|
* UMA zones for the VFS cache.
|
|
|
|
*
|
|
|
|
* The small cache is used for entries with short names, which are the
|
|
|
|
* most common. The large cache is used for entries which are too big to
|
|
|
|
* fit in the small cache.
|
|
|
|
*/
|
|
|
|
static uma_zone_t cache_zone_small;
|
|
|
|
static uma_zone_t cache_zone_large;
|
|
|
|
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
#define CACHE_PATH_CUTOFF 35
|
|
|
|
#define CACHE_ZONE_SMALL (sizeof(struct namecache) + CACHE_PATH_CUTOFF \
|
|
|
|
+ 1)
|
|
|
|
#define CACHE_ZONE_LARGE (sizeof(struct namecache) + NAME_MAX + 1)
|
2003-06-13 08:46:13 +00:00
|
|
|
|
|
|
|
#define cache_alloc(len) uma_zalloc(((len) <= CACHE_PATH_CUTOFF) ? \
|
|
|
|
cache_zone_small : cache_zone_large, M_WAITOK)
|
|
|
|
#define cache_free(ncp) do { \
|
|
|
|
if (ncp != NULL) \
|
|
|
|
uma_zfree(((ncp)->nc_nlen <= CACHE_PATH_CUTOFF) ? \
|
|
|
|
cache_zone_small : cache_zone_large, (ncp)); \
|
|
|
|
} while (0)
|
|
|
|
|
1997-03-08 15:22:14 +00:00
|
|
|
static int doingcache = 1; /* 1 => enable the cache */
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0, "");
|
2002-03-05 15:38:49 +00:00
|
|
|
|
|
|
|
/* Export size information to userland */
|
2006-04-16 18:38:30 +00:00
|
|
|
SYSCTL_INT(_debug_sizeof, OID_AUTO, namecache, CTLFLAG_RD, 0,
|
|
|
|
sizeof(struct namecache), "");
|
1997-03-08 15:22:14 +00:00
|
|
|
|
1997-09-24 07:46:54 +00:00
|
|
|
/*
|
|
|
|
* The new name cache statistics
|
|
|
|
*/
|
2005-02-10 12:16:42 +00:00
|
|
|
static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, 0, "Name cache statistics");
|
1997-09-24 07:46:54 +00:00
|
|
|
#define STATNODE(mode, name, var) \
|
2000-07-05 07:46:41 +00:00
|
|
|
SYSCTL_ULONG(_vfs_cache, OID_AUTO, name, mode, var, 0, "");
|
1997-09-24 07:46:54 +00:00
|
|
|
STATNODE(CTLFLAG_RD, numneg, &numneg);
|
|
|
|
STATNODE(CTLFLAG_RD, numcache, &numcache);
|
|
|
|
static u_long numcalls; STATNODE(CTLFLAG_RD, numcalls, &numcalls);
|
|
|
|
static u_long dothits; STATNODE(CTLFLAG_RD, dothits, &dothits);
|
|
|
|
static u_long dotdothits; STATNODE(CTLFLAG_RD, dotdothits, &dotdothits);
|
|
|
|
static u_long numchecks; STATNODE(CTLFLAG_RD, numchecks, &numchecks);
|
|
|
|
static u_long nummiss; STATNODE(CTLFLAG_RD, nummiss, &nummiss);
|
1997-09-24 15:54:10 +00:00
|
|
|
static u_long nummisszap; STATNODE(CTLFLAG_RD, nummisszap, &nummisszap);
|
1997-09-24 07:46:54 +00:00
|
|
|
static u_long numposzaps; STATNODE(CTLFLAG_RD, numposzaps, &numposzaps);
|
|
|
|
static u_long numposhits; STATNODE(CTLFLAG_RD, numposhits, &numposhits);
|
|
|
|
static u_long numnegzaps; STATNODE(CTLFLAG_RD, numnegzaps, &numnegzaps);
|
|
|
|
static u_long numneghits; STATNODE(CTLFLAG_RD, numneghits, &numneghits);
|
2009-01-28 19:05:18 +00:00
|
|
|
static u_long numupgrades; STATNODE(CTLFLAG_RD, numupgrades, &numupgrades);
|
1997-09-24 07:46:54 +00:00
|
|
|
|
2009-01-23 22:49:23 +00:00
|
|
|
SYSCTL_OPAQUE(_vfs_cache, OID_AUTO, nchstats, CTLFLAG_RD | CTLFLAG_MPSAFE,
|
|
|
|
&nchstats, sizeof(nchstats), "LU", "VFS cache effectiveness statistics");
|
2000-11-20 00:41:11 +00:00
|
|
|
|
|
|
|
|
1997-09-24 07:46:54 +00:00
|
|
|
|
2005-01-24 10:24:12 +00:00
|
|
|
static void cache_zap(struct namecache *ncp);
|
2009-05-31 14:57:43 +00:00
|
|
|
static int vn_vptocnp_locked(struct vnode **vp, char *buf, u_int *buflen);
|
2005-03-30 02:59:32 +00:00
|
|
|
static int vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir,
|
|
|
|
char *buf, char **retbuf, u_int buflen);
|
1995-03-09 20:23:45 +00:00
|
|
|
|
2000-12-08 20:09:00 +00:00
|
|
|
static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries");
|
1999-10-03 12:18:29 +00:00
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
* Flags in namecache.nc_flag
|
1997-02-10 02:22:35 +00:00
|
|
|
*/
|
2009-03-29 21:25:40 +00:00
|
|
|
#define NCF_WHITE 0x01
|
|
|
|
#define NCF_ISDOTDOT 0x02
|
2001-04-11 00:39:20 +00:00
|
|
|
|
2009-03-09 19:04:53 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
2001-04-11 00:39:20 +00:00
|
|
|
/*
|
|
|
|
* Grab an atomic snapshot of the name cache hash chain lengths
|
|
|
|
*/
|
|
|
|
SYSCTL_NODE(_debug, OID_AUTO, hashstat, CTLFLAG_RW, NULL, "hash table stats");
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_debug_hashstat_rawnchash(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct nchashhead *ncpp;
|
|
|
|
struct namecache *ncp;
|
|
|
|
int n_nchash;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
n_nchash = nchash + 1; /* nchash is max index, not count */
|
|
|
|
if (!req->oldptr)
|
|
|
|
return SYSCTL_OUT(req, 0, n_nchash * sizeof(int));
|
|
|
|
|
|
|
|
/* Scan hash tables for applicable entries */
|
|
|
|
for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RLOCK();
|
2001-04-11 00:39:20 +00:00
|
|
|
count = 0;
|
|
|
|
LIST_FOREACH(ncp, ncpp, nc_hash) {
|
|
|
|
count++;
|
|
|
|
}
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2002-06-28 23:17:36 +00:00
|
|
|
error = SYSCTL_OUT(req, &count, sizeof(count));
|
2001-04-11 00:39:20 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
2009-01-23 22:49:23 +00:00
|
|
|
SYSCTL_PROC(_debug_hashstat, OID_AUTO, rawnchash, CTLTYPE_INT|CTLFLAG_RD|
|
|
|
|
CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_rawnchash, "S,int",
|
|
|
|
"nchash chain lengths");
|
2001-04-11 00:39:20 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_debug_hashstat_nchash(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct nchashhead *ncpp;
|
|
|
|
struct namecache *ncp;
|
|
|
|
int n_nchash;
|
|
|
|
int count, maxlength, used, pct;
|
|
|
|
|
|
|
|
if (!req->oldptr)
|
|
|
|
return SYSCTL_OUT(req, 0, 4 * sizeof(int));
|
|
|
|
|
|
|
|
n_nchash = nchash + 1; /* nchash is max index, not count */
|
|
|
|
used = 0;
|
|
|
|
maxlength = 0;
|
|
|
|
|
|
|
|
/* Scan hash tables for applicable entries */
|
|
|
|
for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
|
|
|
|
count = 0;
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RLOCK();
|
2001-04-11 00:39:20 +00:00
|
|
|
LIST_FOREACH(ncp, ncpp, nc_hash) {
|
|
|
|
count++;
|
|
|
|
}
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2001-04-11 00:39:20 +00:00
|
|
|
if (count)
|
|
|
|
used++;
|
|
|
|
if (maxlength < count)
|
|
|
|
maxlength = count;
|
|
|
|
}
|
|
|
|
n_nchash = nchash + 1;
|
|
|
|
pct = (used * 100 * 100) / n_nchash;
|
2002-06-28 23:17:36 +00:00
|
|
|
error = SYSCTL_OUT(req, &n_nchash, sizeof(n_nchash));
|
2001-04-11 00:39:20 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-06-28 23:17:36 +00:00
|
|
|
error = SYSCTL_OUT(req, &used, sizeof(used));
|
2001-04-11 00:39:20 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-06-28 23:17:36 +00:00
|
|
|
error = SYSCTL_OUT(req, &maxlength, sizeof(maxlength));
|
2001-04-11 00:39:20 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-06-28 23:17:36 +00:00
|
|
|
error = SYSCTL_OUT(req, &pct, sizeof(pct));
|
2001-04-11 00:39:20 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
return (0);
|
|
|
|
}
|
2009-01-23 22:49:23 +00:00
|
|
|
SYSCTL_PROC(_debug_hashstat, OID_AUTO, nchash, CTLTYPE_INT|CTLFLAG_RD|
|
|
|
|
CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_nchash, "I",
|
|
|
|
"nchash chain lengths");
|
2009-03-09 19:04:53 +00:00
|
|
|
#endif
|
2001-04-11 00:39:20 +00:00
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
2003-02-15 18:58:06 +00:00
|
|
|
* cache_zap():
|
|
|
|
*
|
|
|
|
* Removes a namecache entry from cache, whether it contains an actual
|
|
|
|
* pointer to a vnode or if it is just a negative cache entry.
|
1997-02-10 02:22:35 +00:00
|
|
|
*/
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
static void
|
2005-01-24 10:24:12 +00:00
|
|
|
cache_zap(ncp)
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
struct namecache *ncp;
|
|
|
|
{
|
2003-10-05 07:13:50 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
rw_assert(&cache_lock, RA_WLOCKED);
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR2(KTR_VFS, "cache_zap(%p) vp %p", ncp, ncp->nc_vp);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
#ifdef KDTRACE_HOOKS
|
|
|
|
if (ncp->nc_vp != NULL) {
|
|
|
|
SDT_PROBE(vfs, namecache, zap, done, ncp->nc_dvp,
|
|
|
|
ncp->nc_name, ncp->nc_vp, 0, 0);
|
|
|
|
} else {
|
|
|
|
SDT_PROBE(vfs, namecache, zap_negative, done, ncp->nc_dvp,
|
|
|
|
ncp->nc_name, 0, 0, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2003-10-05 07:13:50 +00:00
|
|
|
vp = NULL;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
LIST_REMOVE(ncp, nc_hash);
|
2009-03-29 21:25:40 +00:00
|
|
|
if (ncp->nc_flag & NCF_ISDOTDOT) {
|
|
|
|
if (ncp == ncp->nc_dvp->v_cache_dd)
|
|
|
|
ncp->nc_dvp->v_cache_dd = NULL;
|
|
|
|
} else {
|
|
|
|
LIST_REMOVE(ncp, nc_src);
|
|
|
|
if (LIST_EMPTY(&ncp->nc_dvp->v_cache_src)) {
|
|
|
|
vp = ncp->nc_dvp;
|
|
|
|
numcachehv--;
|
|
|
|
}
|
2001-04-18 11:19:50 +00:00
|
|
|
}
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
if (ncp->nc_vp) {
|
|
|
|
TAILQ_REMOVE(&ncp->nc_vp->v_cache_dst, ncp, nc_dst);
|
2009-03-29 21:25:40 +00:00
|
|
|
if (ncp == ncp->nc_vp->v_cache_dd)
|
|
|
|
ncp->nc_vp->v_cache_dd = NULL;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
} else {
|
|
|
|
TAILQ_REMOVE(&ncneg, ncp, nc_dst);
|
|
|
|
numneg--;
|
|
|
|
}
|
|
|
|
numcache--;
|
2003-06-13 08:46:13 +00:00
|
|
|
cache_free(ncp);
|
2003-10-05 07:13:50 +00:00
|
|
|
if (vp)
|
|
|
|
vdrop(vp);
|
1997-02-10 02:22:35 +00:00
|
|
|
}
|
1995-03-09 20:23:45 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1997-03-08 15:22:14 +00:00
|
|
|
* Lookup an entry in the cache
|
1995-03-09 20:23:45 +00:00
|
|
|
*
|
|
|
|
* Lookup is called with dvp pointing to the directory to search,
|
1997-02-10 02:22:35 +00:00
|
|
|
* cnp pointing to the name of the entry being sought. If the lookup
|
|
|
|
* succeeds, the vnode is returned in *vpp, and a status of -1 is
|
|
|
|
* returned. If the lookup determines that the name does not exist
|
|
|
|
* (negative cacheing), a status of ENOENT is returned. If the lookup
|
2008-09-24 18:51:33 +00:00
|
|
|
* fails, a status of zero is returned. If the directory vnode is
|
|
|
|
* recycled out from under us due to a forced unmount, a status of
|
2009-03-24 18:16:42 +00:00
|
|
|
* ENOENT is returned.
|
2005-03-29 12:59:06 +00:00
|
|
|
*
|
|
|
|
* vpp is locked and ref'd on return. If we're looking up DOTDOT, dvp is
|
|
|
|
* unlocked. If we're looking up . an extra ref is taken, but the lock is
|
|
|
|
* not recursively acquired.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1995-03-09 20:23:45 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
int
|
|
|
|
cache_lookup(dvp, vpp, cnp)
|
|
|
|
struct vnode *dvp;
|
|
|
|
struct vnode **vpp;
|
|
|
|
struct componentname *cnp;
|
|
|
|
{
|
1999-10-03 12:18:29 +00:00
|
|
|
struct namecache *ncp;
|
2001-03-17 09:31:06 +00:00
|
|
|
u_int32_t hash;
|
2009-01-28 19:05:18 +00:00
|
|
|
int error, ltype, wlocked;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-03-06 06:45:52 +00:00
|
|
|
if (!doingcache) {
|
|
|
|
cnp->cn_flags &= ~MAKEENTRY;
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
1995-03-06 06:45:52 +00:00
|
|
|
}
|
2005-03-29 12:59:06 +00:00
|
|
|
retry:
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RLOCK();
|
|
|
|
wlocked = 0;
|
1997-09-24 07:46:54 +00:00
|
|
|
numcalls++;
|
2009-01-28 19:05:18 +00:00
|
|
|
error = 0;
|
1997-09-24 07:46:54 +00:00
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
retry_wlocked:
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
if (cnp->cn_nameptr[0] == '.') {
|
|
|
|
if (cnp->cn_namelen == 1) {
|
|
|
|
*vpp = dvp;
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR2(KTR_VFS, "cache_lookup(%p, %s) found via .",
|
|
|
|
dvp, cnp->cn_nameptr);
|
1997-09-24 07:46:54 +00:00
|
|
|
dothits++;
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, lookup, hit, dvp, ".",
|
|
|
|
*vpp, 0, 0);
|
2005-03-29 12:59:06 +00:00
|
|
|
goto success;
|
1995-03-06 06:45:52 +00:00
|
|
|
}
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.') {
|
1997-09-24 07:46:54 +00:00
|
|
|
dotdothits++;
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
if (dvp->v_cache_dd == NULL) {
|
|
|
|
SDT_PROBE(vfs, namecache, lookup, miss, dvp,
|
|
|
|
"..", NULL, 0, 0);
|
2009-03-29 21:25:40 +00:00
|
|
|
goto unlock;
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
}
|
2009-03-29 21:25:40 +00:00
|
|
|
if ((cnp->cn_flags & MAKEENTRY) == 0) {
|
2009-04-11 16:12:20 +00:00
|
|
|
if (!wlocked && !CACHE_UPGRADE_LOCK())
|
|
|
|
goto wlock;
|
2009-03-29 21:25:40 +00:00
|
|
|
if (dvp->v_cache_dd->nc_flag & NCF_ISDOTDOT)
|
|
|
|
cache_zap(dvp->v_cache_dd);
|
|
|
|
dvp->v_cache_dd = NULL;
|
2009-01-28 19:05:18 +00:00
|
|
|
goto unlock;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
}
|
2009-03-29 21:25:40 +00:00
|
|
|
if (dvp->v_cache_dd->nc_flag & NCF_ISDOTDOT)
|
|
|
|
*vpp = dvp->v_cache_dd->nc_vp;
|
|
|
|
else
|
|
|
|
*vpp = dvp->v_cache_dd->nc_dvp;
|
2009-04-14 23:46:57 +00:00
|
|
|
/* Return failure if negative entry was found. */
|
|
|
|
if (*vpp == NULL) {
|
2009-04-14 23:56:48 +00:00
|
|
|
ncp = dvp->v_cache_dd;
|
|
|
|
goto negative_success;
|
2009-04-14 23:46:57 +00:00
|
|
|
}
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR3(KTR_VFS, "cache_lookup(%p, %s) found %p via ..",
|
|
|
|
dvp, cnp->cn_nameptr, *vpp);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, lookup, hit, dvp, "..",
|
|
|
|
*vpp, 0, 0);
|
2005-03-29 12:59:06 +00:00
|
|
|
goto success;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-20 02:10:18 +00:00
|
|
|
hash = fnv_32_buf(cnp->cn_nameptr, cnp->cn_namelen, FNV1_32_INIT);
|
2005-03-30 03:01:36 +00:00
|
|
|
hash = fnv_32_buf(&dvp, sizeof(dvp), hash);
|
2001-03-20 02:10:18 +00:00
|
|
|
LIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) {
|
1997-09-24 07:46:54 +00:00
|
|
|
numchecks++;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
if (ncp->nc_dvp == dvp && ncp->nc_nlen == cnp->cn_namelen &&
|
1997-12-19 23:18:37 +00:00
|
|
|
!bcmp(ncp->nc_name, cnp->cn_nameptr, ncp->nc_nlen))
|
1997-02-10 02:22:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We failed to find an entry */
|
2009-01-28 19:05:18 +00:00
|
|
|
if (ncp == NULL) {
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, lookup, miss, dvp, cnp->cn_nameptr,
|
|
|
|
NULL, 0, 0);
|
1997-09-24 15:54:10 +00:00
|
|
|
if ((cnp->cn_flags & MAKEENTRY) == 0) {
|
|
|
|
nummisszap++;
|
|
|
|
} else {
|
|
|
|
nummiss++;
|
|
|
|
}
|
1997-02-10 02:22:35 +00:00
|
|
|
nchstats.ncs_miss++;
|
2009-01-28 19:05:18 +00:00
|
|
|
goto unlock;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1995-03-09 20:23:45 +00:00
|
|
|
|
|
|
|
/* We don't want to have an entry, so dump it */
|
1995-03-06 06:45:52 +00:00
|
|
|
if ((cnp->cn_flags & MAKEENTRY) == 0) {
|
1997-09-24 07:46:54 +00:00
|
|
|
numposzaps++;
|
1994-05-24 10:09:53 +00:00
|
|
|
nchstats.ncs_badhits++;
|
2009-01-28 19:05:18 +00:00
|
|
|
if (!wlocked && !CACHE_UPGRADE_LOCK())
|
|
|
|
goto wlock;
|
2005-01-24 10:24:12 +00:00
|
|
|
cache_zap(ncp);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
1995-03-09 20:23:45 +00:00
|
|
|
return (0);
|
1997-03-08 15:22:14 +00:00
|
|
|
}
|
1995-03-09 20:23:45 +00:00
|
|
|
|
|
|
|
/* We found a "positive" match, return the vnode */
|
2003-06-11 07:35:56 +00:00
|
|
|
if (ncp->nc_vp) {
|
1997-09-24 07:46:54 +00:00
|
|
|
numposhits++;
|
1994-05-24 10:09:53 +00:00
|
|
|
nchstats.ncs_goodhits++;
|
|
|
|
*vpp = ncp->nc_vp;
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR4(KTR_VFS, "cache_lookup(%p, %s) found %p via ncp %p",
|
|
|
|
dvp, cnp->cn_nameptr, *vpp, ncp);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, lookup, hit, dvp, ncp->nc_name,
|
|
|
|
*vpp, 0, 0);
|
2005-03-29 12:59:06 +00:00
|
|
|
goto success;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2009-04-14 23:56:48 +00:00
|
|
|
negative_success:
|
1995-03-09 20:23:45 +00:00
|
|
|
/* We found a negative match, and want to create it, so purge */
|
|
|
|
if (cnp->cn_nameiop == CREATE) {
|
1997-09-24 07:46:54 +00:00
|
|
|
numnegzaps++;
|
1995-03-12 02:01:20 +00:00
|
|
|
nchstats.ncs_badhits++;
|
2009-01-28 19:05:18 +00:00
|
|
|
if (!wlocked && !CACHE_UPGRADE_LOCK())
|
|
|
|
goto wlock;
|
2005-01-24 10:24:12 +00:00
|
|
|
cache_zap(ncp);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
1995-03-09 20:23:45 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
if (!wlocked && !CACHE_UPGRADE_LOCK())
|
|
|
|
goto wlock;
|
1997-09-24 07:46:54 +00:00
|
|
|
numneghits++;
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
2003-02-15 23:25:12 +00:00
|
|
|
* We found a "negative" match, so we shift it to the end of
|
|
|
|
* the "negative" cache entries queue to satisfy LRU. Also,
|
|
|
|
* check to see if the entry is a whiteout; indicate this to
|
|
|
|
* the componentname, if so.
|
1997-02-10 02:22:35 +00:00
|
|
|
*/
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
TAILQ_REMOVE(&ncneg, ncp, nc_dst);
|
|
|
|
TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
|
1995-03-09 20:23:45 +00:00
|
|
|
nchstats.ncs_neghits++;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
if (ncp->nc_flag & NCF_WHITE)
|
|
|
|
cnp->cn_flags |= ISWHITEOUT;
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, lookup, hit_negative, dvp, ncp->nc_name,
|
|
|
|
0, 0, 0);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
1995-03-09 20:23:45 +00:00
|
|
|
return (ENOENT);
|
2005-03-29 12:59:06 +00:00
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
wlock:
|
|
|
|
/*
|
|
|
|
* We need to update the cache after our lookup, so upgrade to
|
|
|
|
* a write lock and retry the operation.
|
|
|
|
*/
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
CACHE_WLOCK();
|
|
|
|
numupgrades++;
|
|
|
|
wlocked = 1;
|
|
|
|
goto retry_wlocked;
|
|
|
|
|
2005-03-29 12:59:06 +00:00
|
|
|
success:
|
|
|
|
/*
|
|
|
|
* On success we return a locked and ref'd vnode as per the lookup
|
|
|
|
* protocol.
|
|
|
|
*/
|
|
|
|
if (dvp == *vpp) { /* lookup on "." */
|
|
|
|
VREF(*vpp);
|
2009-01-28 19:05:18 +00:00
|
|
|
if (wlocked)
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
else
|
|
|
|
CACHE_RUNLOCK();
|
2007-09-21 10:16:56 +00:00
|
|
|
/*
|
|
|
|
* When we lookup "." we still can be asked to lock it
|
|
|
|
* differently...
|
|
|
|
*/
|
2008-04-09 20:19:55 +00:00
|
|
|
ltype = cnp->cn_lkflags & LK_TYPE_MASK;
|
2008-09-24 18:51:33 +00:00
|
|
|
if (ltype != VOP_ISLOCKED(*vpp)) {
|
|
|
|
if (ltype == LK_EXCLUSIVE) {
|
|
|
|
vn_lock(*vpp, LK_UPGRADE | LK_RETRY);
|
|
|
|
if ((*vpp)->v_iflag & VI_DOOMED) {
|
|
|
|
/* forced unmount */
|
|
|
|
vrele(*vpp);
|
|
|
|
*vpp = NULL;
|
2009-03-24 18:16:42 +00:00
|
|
|
return (ENOENT);
|
2008-09-24 18:51:33 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
vn_lock(*vpp, LK_DOWNGRADE | LK_RETRY);
|
|
|
|
}
|
2005-03-29 12:59:06 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2007-05-25 22:23:38 +00:00
|
|
|
ltype = 0; /* silence gcc warning */
|
|
|
|
if (cnp->cn_flags & ISDOTDOT) {
|
2008-02-25 18:45:57 +00:00
|
|
|
ltype = VOP_ISLOCKED(dvp);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(dvp, 0);
|
2007-05-25 22:23:38 +00:00
|
|
|
}
|
2005-03-29 12:59:06 +00:00
|
|
|
VI_LOCK(*vpp);
|
2009-01-28 19:05:18 +00:00
|
|
|
if (wlocked)
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
else
|
|
|
|
CACHE_RUNLOCK();
|
2008-02-25 18:45:57 +00:00
|
|
|
error = vget(*vpp, cnp->cn_lkflags | LK_INTERLOCK, cnp->cn_thread);
|
2009-04-10 10:22:44 +00:00
|
|
|
if (cnp->cn_flags & ISDOTDOT) {
|
2008-01-10 01:10:58 +00:00
|
|
|
vn_lock(dvp, ltype | LK_RETRY);
|
2009-04-10 10:22:44 +00:00
|
|
|
if (dvp->v_iflag & VI_DOOMED) {
|
|
|
|
if (error == 0)
|
|
|
|
vput(*vpp);
|
|
|
|
*vpp = NULL;
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
}
|
2005-04-13 10:59:09 +00:00
|
|
|
if (error) {
|
2005-03-29 12:59:06 +00:00
|
|
|
*vpp = NULL;
|
|
|
|
goto retry;
|
|
|
|
}
|
2008-04-09 20:19:55 +00:00
|
|
|
if ((cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(cnp->cn_lkflags & LK_TYPE_MASK) == LK_EXCLUSIVE) {
|
|
|
|
ASSERT_VOP_ELOCKED(*vpp, "cache_lookup");
|
|
|
|
}
|
2005-03-29 12:59:06 +00:00
|
|
|
return (-1);
|
2009-01-28 19:05:18 +00:00
|
|
|
|
|
|
|
unlock:
|
|
|
|
if (wlocked)
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
else
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-03-09 20:23:45 +00:00
|
|
|
* Add an entry to the cache.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
void
|
1994-05-24 10:09:53 +00:00
|
|
|
cache_enter(dvp, vp, cnp)
|
|
|
|
struct vnode *dvp;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct componentname *cnp;
|
|
|
|
{
|
2008-12-02 11:14:16 +00:00
|
|
|
struct namecache *ncp, *n2;
|
1999-10-03 12:18:29 +00:00
|
|
|
struct nchashhead *ncpp;
|
2001-03-17 09:31:06 +00:00
|
|
|
u_int32_t hash;
|
2009-03-29 21:25:40 +00:00
|
|
|
int flag;
|
2003-10-05 07:13:50 +00:00
|
|
|
int hold;
|
|
|
|
int zap;
|
1999-10-03 12:18:29 +00:00
|
|
|
int len;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR3(KTR_VFS, "cache_enter(%p, %p, %s)", dvp, vp, cnp->cn_nameptr);
|
2005-06-11 08:47:30 +00:00
|
|
|
VNASSERT(vp == NULL || (vp->v_iflag & VI_DOOMED) == 0, vp,
|
|
|
|
("cahe_enter: Adding a doomed vnode"));
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
if (!doingcache)
|
|
|
|
return;
|
1995-03-09 20:23:45 +00:00
|
|
|
|
2009-01-20 04:21:21 +00:00
|
|
|
/*
|
|
|
|
* Avoid blowout in namecache entries.
|
|
|
|
*/
|
|
|
|
if (numcache >= desiredvnodes * 2)
|
|
|
|
return;
|
|
|
|
|
2009-03-29 21:25:40 +00:00
|
|
|
flag = 0;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
if (cnp->cn_nameptr[0] == '.') {
|
2009-03-29 21:25:40 +00:00
|
|
|
if (cnp->cn_namelen == 1)
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
return;
|
|
|
|
if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.') {
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WLOCK();
|
2009-03-29 21:25:40 +00:00
|
|
|
/*
|
|
|
|
* If dotdot entry already exists, just retarget it
|
|
|
|
* to new parent vnode, otherwise continue with new
|
|
|
|
* namecache entry allocation.
|
|
|
|
*/
|
2009-04-17 18:11:11 +00:00
|
|
|
if ((ncp = dvp->v_cache_dd) != NULL &&
|
|
|
|
ncp->nc_flag & NCF_ISDOTDOT) {
|
|
|
|
KASSERT(ncp->nc_dvp == dvp,
|
|
|
|
("wrong isdotdot parent"));
|
|
|
|
if (ncp->nc_vp != NULL)
|
2009-03-29 21:25:40 +00:00
|
|
|
TAILQ_REMOVE(&ncp->nc_vp->v_cache_dst,
|
|
|
|
ncp, nc_dst);
|
2009-04-17 18:11:11 +00:00
|
|
|
else
|
|
|
|
TAILQ_REMOVE(&ncneg, ncp, nc_dst);
|
|
|
|
if (vp != NULL)
|
2009-03-29 21:25:40 +00:00
|
|
|
TAILQ_INSERT_HEAD(&vp->v_cache_dst,
|
|
|
|
ncp, nc_dst);
|
2009-04-17 18:11:11 +00:00
|
|
|
else
|
|
|
|
TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
|
|
|
|
ncp->nc_vp = vp;
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
return;
|
2009-03-29 21:25:40 +00:00
|
|
|
}
|
|
|
|
dvp->v_cache_dd = NULL;
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, enter, done, dvp, "..", vp,
|
|
|
|
0, 0);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
2009-03-29 21:25:40 +00:00
|
|
|
flag = NCF_ISDOTDOT;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1995-03-09 20:23:45 +00:00
|
|
|
}
|
2003-06-11 07:35:56 +00:00
|
|
|
|
2003-10-05 07:13:50 +00:00
|
|
|
hold = 0;
|
|
|
|
zap = 0;
|
2008-08-23 15:13:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the hash key and setup as much of the new
|
|
|
|
* namecache entry as possible before acquiring the lock.
|
|
|
|
*/
|
2003-06-13 08:46:13 +00:00
|
|
|
ncp = cache_alloc(cnp->cn_namelen);
|
2008-08-23 15:13:39 +00:00
|
|
|
ncp->nc_vp = vp;
|
|
|
|
ncp->nc_dvp = dvp;
|
2009-03-29 21:25:40 +00:00
|
|
|
ncp->nc_flag = flag;
|
2008-08-23 15:13:39 +00:00
|
|
|
len = ncp->nc_nlen = cnp->cn_namelen;
|
|
|
|
hash = fnv_32_buf(cnp->cn_nameptr, len, FNV1_32_INIT);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
strlcpy(ncp->nc_name, cnp->cn_nameptr, len + 1);
|
2008-08-23 15:13:39 +00:00
|
|
|
hash = fnv_32_buf(&dvp, sizeof(dvp), hash);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WLOCK();
|
2008-08-23 15:13:39 +00:00
|
|
|
|
|
|
|
/*
|
2008-12-30 12:51:14 +00:00
|
|
|
* See if this vnode or negative entry is already in the cache
|
|
|
|
* with this name. This can happen with concurrent lookups of
|
|
|
|
* the same path name.
|
2008-08-23 15:13:39 +00:00
|
|
|
*/
|
2008-12-30 12:51:14 +00:00
|
|
|
ncpp = NCHHASH(hash);
|
|
|
|
LIST_FOREACH(n2, ncpp, nc_hash) {
|
|
|
|
if (n2->nc_dvp == dvp &&
|
|
|
|
n2->nc_nlen == cnp->cn_namelen &&
|
|
|
|
!bcmp(n2->nc_name, cnp->cn_nameptr, n2->nc_nlen)) {
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
2008-12-30 12:51:14 +00:00
|
|
|
cache_free(ncp);
|
|
|
|
return;
|
2008-12-02 11:14:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-23 15:13:39 +00:00
|
|
|
|
2009-04-11 20:23:08 +00:00
|
|
|
if (flag == NCF_ISDOTDOT) {
|
|
|
|
/*
|
|
|
|
* See if we are trying to add .. entry, but some other lookup
|
|
|
|
* has populated v_cache_dd pointer already.
|
|
|
|
*/
|
|
|
|
if (dvp->v_cache_dd != NULL) {
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
cache_free(ncp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
KASSERT(vp == NULL || vp->v_type == VDIR,
|
|
|
|
("wrong vnode type %p", vp));
|
|
|
|
dvp->v_cache_dd = ncp;
|
2009-03-29 21:25:40 +00:00
|
|
|
}
|
|
|
|
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
numcache++;
|
1997-08-31 07:32:39 +00:00
|
|
|
if (!vp) {
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
numneg++;
|
2009-03-29 21:25:40 +00:00
|
|
|
if (cnp->cn_flags & ISWHITEOUT)
|
|
|
|
ncp->nc_flag |= NCF_WHITE;
|
1997-09-03 09:20:17 +00:00
|
|
|
} else if (vp->v_type == VDIR) {
|
2009-04-11 20:23:08 +00:00
|
|
|
if (flag != NCF_ISDOTDOT) {
|
2009-03-29 21:25:40 +00:00
|
|
|
if ((n2 = vp->v_cache_dd) != NULL &&
|
|
|
|
(n2->nc_flag & NCF_ISDOTDOT) != 0)
|
|
|
|
cache_zap(n2);
|
|
|
|
vp->v_cache_dd = ncp;
|
|
|
|
}
|
2005-03-30 03:01:36 +00:00
|
|
|
} else {
|
2009-03-29 21:25:40 +00:00
|
|
|
vp->v_cache_dd = NULL;
|
1997-08-31 07:32:39 +00:00
|
|
|
}
|
1997-03-08 15:22:14 +00:00
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
/*
|
2008-08-23 15:13:39 +00:00
|
|
|
* Insert the new namecache entry into the appropriate chain
|
|
|
|
* within the cache entries table.
|
1997-02-10 02:22:35 +00:00
|
|
|
*/
|
1995-03-06 06:45:52 +00:00
|
|
|
LIST_INSERT_HEAD(ncpp, ncp, nc_hash);
|
2009-03-29 21:25:40 +00:00
|
|
|
if (flag != NCF_ISDOTDOT) {
|
|
|
|
if (LIST_EMPTY(&dvp->v_cache_src)) {
|
|
|
|
hold = 1;
|
|
|
|
numcachehv++;
|
|
|
|
}
|
|
|
|
LIST_INSERT_HEAD(&dvp->v_cache_src, ncp, nc_src);
|
2001-04-18 11:19:50 +00:00
|
|
|
}
|
2009-03-29 21:25:40 +00:00
|
|
|
|
2003-02-15 23:25:12 +00:00
|
|
|
/*
|
|
|
|
* If the entry is "negative", we place it into the
|
|
|
|
* "negative" cache queue, otherwise, we place it into the
|
|
|
|
* destination vnode's cache entries queue.
|
|
|
|
*/
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
if (vp) {
|
|
|
|
TAILQ_INSERT_HEAD(&vp->v_cache_dst, ncp, nc_dst);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, enter, done, dvp, ncp->nc_name, vp,
|
|
|
|
0, 0);
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
} else {
|
|
|
|
TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, enter_negative, done, dvp,
|
|
|
|
ncp->nc_name, 0, 0, 0);
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
}
|
1999-10-03 12:18:29 +00:00
|
|
|
if (numneg * ncnegfactor > numcache) {
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
ncp = TAILQ_FIRST(&ncneg);
|
2003-10-05 07:13:50 +00:00
|
|
|
zap = 1;
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
}
|
2003-10-05 07:13:50 +00:00
|
|
|
if (hold)
|
|
|
|
vhold(dvp);
|
|
|
|
if (zap)
|
2005-01-24 10:24:12 +00:00
|
|
|
cache_zap(ncp);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Name cache initialization, from vfs_init() when we are booting
|
|
|
|
*/
|
2000-12-06 07:09:08 +00:00
|
|
|
static void
|
|
|
|
nchinit(void *dummy __unused)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1997-03-08 15:22:14 +00:00
|
|
|
|
1. Add a {pointer, v_id} pair to the vnode to store the reference to the
".." vnode. This is cheaper storagewise than keeping it in the
namecache, and it makes more sense since it's a 1:1 mapping.
2. Also handle the case of "." more intelligently rather than stuff
the namecache with pointless entries.
3. Add two lists to the vnode and hang namecache entries which go from
or to this vnode. When cleaning a vnode, delete all namecache
entries it invalidates.
4. Never reuse namecache enties, malloc new ones when we need it, free
old ones when they die. No longer a hard limit on how many we can
have.
5. Remove the upper limit on namelength of namecache entries.
6. Make a global list for negative namecache entries, limit their number
to a sysctl'able (debug.ncnegfactor) fraction of the total namecache.
Currently the default fraction is 1/16th. (Suggestions for better
default wanted!)
7. Assign v_id correctly in the face of 32bit rollover.
8. Remove the LRU list for namecache entries, not needed. Remove the
#ifdef NCH_STATISTICS stuff, it's not needed either.
9. Use the vnode freelist as a true LRU list, also for namecache accesses.
10. Reuse vnodes more aggresively but also more selectively, if we can't
reuse, malloc a new one. There is no longer a hard limit on their
number, they grow to the point where we don't reuse potentially
usable vnodes. A vnode will not get recycled if still has pages in
core or if it is the source of namecache entries (Yes, this does
indeed work :-) "." and ".." are not namecache entries any longer...)
11. Do not overload the v_id field in namecache entries with whiteout
information, use a char sized flags field instead, so we can get
rid of the vpid and v_id fields from the namecache struct. Since
we're linked to the vnodes and purged when they're cleaned, we don't
have to check the v_id any more.
12. NFS knew about the limitation on name length in the namecache, it
shouldn't and doesn't now.
Bugs:
The namecache statistics no longer includes the hits for ".."
and "." hits.
Performance impact:
Generally in the +/- 0.5% for "normal" workstations, but
I hope this will allow the system to be selftuning over a
bigger range of "special" applications. The case where
RAM is available but unused for cache because we don't have
any vnodes should be gone.
Future work:
Straighten out the namecache statistics.
"desiredvnodes" is still used to (bogusly ?) size hash
tables in the filesystems.
I have still to find a way to safely free unused vnodes
back so their number can shrink when not needed.
There is a few uses of the v_id field left in the filesystems,
scheduled for demolition at a later time.
Maybe a one slot cache for unused namecache entries should
be implemented to decrease the malloc/free frequency.
1997-05-04 09:17:38 +00:00
|
|
|
TAILQ_INIT(&ncneg);
|
2003-06-13 08:46:13 +00:00
|
|
|
|
|
|
|
cache_zone_small = uma_zcreate("S VFS Cache", CACHE_ZONE_SMALL, NULL,
|
|
|
|
NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
|
|
|
|
cache_zone_large = uma_zcreate("L VFS Cache", CACHE_ZONE_LARGE, NULL,
|
|
|
|
NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
|
|
|
|
|
2000-12-06 07:09:08 +00:00
|
|
|
nchashtbl = hashinit(desiredvnodes * 2, M_VFSCACHE, &nchash);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_SECOND, nchinit, NULL);
|
2000-12-06 07:09:08 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
1999-04-24 17:58:14 +00:00
|
|
|
* Invalidate all entries to a particular vnode.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
void
|
1994-05-24 10:09:53 +00:00
|
|
|
cache_purge(vp)
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR1(KTR_VFS, "cache_purge(%p)", vp);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, purge, done, vp, 0, 0, 0, 0);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WLOCK();
|
2005-06-13 05:59:59 +00:00
|
|
|
while (!LIST_EMPTY(&vp->v_cache_src))
|
|
|
|
cache_zap(LIST_FIRST(&vp->v_cache_src));
|
2003-06-11 07:35:56 +00:00
|
|
|
while (!TAILQ_EMPTY(&vp->v_cache_dst))
|
2005-01-24 10:24:12 +00:00
|
|
|
cache_zap(TAILQ_FIRST(&vp->v_cache_dst));
|
2009-03-29 21:25:40 +00:00
|
|
|
if (vp->v_cache_dd != NULL) {
|
|
|
|
KASSERT(vp->v_cache_dd->nc_flag & NCF_ISDOTDOT,
|
|
|
|
("lost dotdot link"));
|
|
|
|
cache_zap(vp->v_cache_dd);
|
|
|
|
}
|
|
|
|
KASSERT(vp->v_cache_dd == NULL, ("incomplete purge"));
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2009-02-19 22:28:48 +00:00
|
|
|
/*
|
|
|
|
* Invalidate all negative entries for a particular directory vnode.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cache_purge_negative(vp)
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
struct namecache *cp, *ncp;
|
|
|
|
|
|
|
|
CTR1(KTR_VFS, "cache_purge_negative(%p)", vp);
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, purge_negative, done, vp, 0, 0, 0, 0);
|
2009-02-19 22:28:48 +00:00
|
|
|
CACHE_WLOCK();
|
|
|
|
LIST_FOREACH_SAFE(cp, &vp->v_cache_src, nc_src, ncp) {
|
|
|
|
if (cp->nc_vp == NULL)
|
|
|
|
cache_zap(cp);
|
|
|
|
}
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1995-03-09 20:23:45 +00:00
|
|
|
* Flush all entries referencing a particular filesystem.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
void
|
1994-05-24 10:09:53 +00:00
|
|
|
cache_purgevfs(mp)
|
|
|
|
struct mount *mp;
|
|
|
|
{
|
1995-03-09 20:23:45 +00:00
|
|
|
struct nchashhead *ncpp;
|
1997-02-10 02:22:35 +00:00
|
|
|
struct namecache *ncp, *nnp;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-03-09 20:23:45 +00:00
|
|
|
/* Scan hash tables for applicable entries */
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, purgevfs, done, mp, 0, 0, 0, 0);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WLOCK();
|
1997-09-03 09:20:17 +00:00
|
|
|
for (ncpp = &nchashtbl[nchash]; ncpp >= nchashtbl; ncpp--) {
|
2007-05-25 22:19:49 +00:00
|
|
|
LIST_FOREACH_SAFE(ncp, ncpp, nc_hash, nnp) {
|
|
|
|
if (ncp->nc_dvp->v_mount == mp)
|
|
|
|
cache_zap(ncp);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1997-08-26 07:32:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform canonical checks and cache lookup and pass on to filesystem
|
|
|
|
* through the vop_cachedlookup only if needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
vfs_cache_lookup(ap)
|
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
2005-03-29 12:59:06 +00:00
|
|
|
struct vnode *dvp;
|
1997-08-26 07:32:51 +00:00
|
|
|
int error;
|
|
|
|
struct vnode **vpp = ap->a_vpp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct ucred *cred = cnp->cn_cred;
|
|
|
|
int flags = cnp->cn_flags;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td = cnp->cn_thread;
|
1997-08-26 07:32:51 +00:00
|
|
|
|
|
|
|
*vpp = NULL;
|
2000-09-10 03:46:12 +00:00
|
|
|
dvp = ap->a_dvp;
|
1997-08-26 07:32:51 +00:00
|
|
|
|
2000-09-10 03:46:12 +00:00
|
|
|
if (dvp->v_type != VDIR)
|
2003-06-11 07:35:56 +00:00
|
|
|
return (ENOTDIR);
|
1997-08-26 07:32:51 +00:00
|
|
|
|
2000-09-10 03:46:12 +00:00
|
|
|
if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
|
1997-08-26 07:32:51 +00:00
|
|
|
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
|
|
|
|
return (EROFS);
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VOP_ACCESS(dvp, VEXEC, cred, td);
|
1997-08-26 07:32:51 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2000-09-10 03:46:12 +00:00
|
|
|
error = cache_lookup(dvp, vpp, cnp);
|
2005-03-29 12:59:06 +00:00
|
|
|
if (error == 0)
|
2005-03-29 10:08:23 +00:00
|
|
|
return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
|
2008-09-24 18:51:33 +00:00
|
|
|
if (error == -1)
|
|
|
|
return (0);
|
|
|
|
return (error);
|
1997-08-26 07:32:51 +00:00
|
|
|
}
|
1999-10-03 12:18:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
|
|
|
struct __getcwd_args {
|
|
|
|
u_char *buf;
|
|
|
|
u_int buflen;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2002-03-05 15:38:49 +00:00
|
|
|
/*
|
|
|
|
* XXX All of these sysctls would probably be more productive dead.
|
|
|
|
*/
|
1999-10-03 12:18:29 +00:00
|
|
|
static int disablecwd;
|
2002-03-05 15:38:49 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, disablecwd, CTLFLAG_RW, &disablecwd, 0,
|
|
|
|
"Disable the getcwd syscall");
|
1999-10-03 12:18:29 +00:00
|
|
|
|
2007-03-05 13:10:58 +00:00
|
|
|
/* Implementation of the getcwd syscall. */
|
1999-10-03 12:18:29 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
__getcwd(td, uap)
|
|
|
|
struct thread *td;
|
1999-10-03 12:18:29 +00:00
|
|
|
struct __getcwd_args *uap;
|
|
|
|
{
|
2003-03-17 12:21:08 +00:00
|
|
|
|
2003-03-20 10:40:45 +00:00
|
|
|
return (kern___getcwd(td, uap->buf, UIO_USERSPACE, uap->buflen));
|
2003-03-17 12:21:08 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 22:40:30 +00:00
|
|
|
int
|
2003-03-20 10:40:45 +00:00
|
|
|
kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, u_int buflen)
|
2002-09-02 22:40:30 +00:00
|
|
|
{
|
|
|
|
char *bp, *tmpbuf;
|
1999-10-03 12:18:29 +00:00
|
|
|
struct filedesc *fdp;
|
2008-11-25 15:36:15 +00:00
|
|
|
struct vnode *cdir, *rdir;
|
|
|
|
int error, vfslocked;
|
1999-10-03 12:18:29 +00:00
|
|
|
|
2003-03-20 10:40:45 +00:00
|
|
|
if (disablecwd)
|
1999-10-03 12:18:29 +00:00
|
|
|
return (ENODEV);
|
2002-09-02 22:40:30 +00:00
|
|
|
if (buflen < 2)
|
1999-10-03 12:18:29 +00:00
|
|
|
return (EINVAL);
|
2002-09-02 22:40:30 +00:00
|
|
|
if (buflen > MAXPATHLEN)
|
|
|
|
buflen = MAXPATHLEN;
|
2005-03-30 02:59:32 +00:00
|
|
|
|
|
|
|
tmpbuf = malloc(buflen, M_TEMP, M_WAITOK);
|
2001-09-12 08:38:13 +00:00
|
|
|
fdp = td->td_proc->p_fd;
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SLOCK(fdp);
|
2008-11-25 15:36:15 +00:00
|
|
|
cdir = fdp->fd_cdir;
|
|
|
|
VREF(cdir);
|
|
|
|
rdir = fdp->fd_rdir;
|
|
|
|
VREF(rdir);
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SUNLOCK(fdp);
|
2008-11-25 15:36:15 +00:00
|
|
|
error = vn_fullpath1(td, cdir, rdir, tmpbuf, &bp, buflen);
|
|
|
|
vfslocked = VFS_LOCK_GIANT(rdir->v_mount);
|
|
|
|
vrele(rdir);
|
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
|
|
|
vfslocked = VFS_LOCK_GIANT(cdir->v_mount);
|
|
|
|
vrele(cdir);
|
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
2005-03-30 02:59:32 +00:00
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
if (bufseg == UIO_SYSSPACE)
|
|
|
|
bcopy(bp, buf, strlen(bp) + 1);
|
|
|
|
else
|
|
|
|
error = copyout(bp, buf, strlen(bp) + 1);
|
2009-03-20 10:47:16 +00:00
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(curthread, KTR_NAMEI))
|
|
|
|
ktrnamei(bp);
|
|
|
|
#endif
|
2005-03-30 02:59:32 +00:00
|
|
|
}
|
2005-01-24 10:24:12 +00:00
|
|
|
free(tmpbuf, M_TEMP);
|
|
|
|
return (error);
|
1999-10-03 12:18:29 +00:00
|
|
|
}
|
|
|
|
|
2000-04-26 11:57:45 +00:00
|
|
|
/*
|
|
|
|
* Thus begins the fullpath magic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef STATNODE
|
|
|
|
#define STATNODE(name) \
|
|
|
|
static u_int name; \
|
2000-07-05 07:46:41 +00:00
|
|
|
SYSCTL_UINT(_vfs_cache, OID_AUTO, name, CTLFLAG_RD, &name, 0, "")
|
2000-04-26 11:57:45 +00:00
|
|
|
|
|
|
|
static int disablefullpath;
|
2002-03-05 15:38:49 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, disablefullpath, CTLFLAG_RW, &disablefullpath, 0,
|
|
|
|
"Disable the vn_fullpath function");
|
2000-04-26 11:57:45 +00:00
|
|
|
|
2005-03-30 02:59:32 +00:00
|
|
|
/* These count for kern___getcwd(), too. */
|
2000-04-26 11:57:45 +00:00
|
|
|
STATNODE(numfullpathcalls);
|
|
|
|
STATNODE(numfullpathfail1);
|
|
|
|
STATNODE(numfullpathfail2);
|
|
|
|
STATNODE(numfullpathfail4);
|
|
|
|
STATNODE(numfullpathfound);
|
|
|
|
|
2002-03-05 15:38:49 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the full filesystem path that correspond to a vnode from the name
|
|
|
|
* cache (if available)
|
|
|
|
*/
|
2000-04-26 11:57:45 +00:00
|
|
|
int
|
2001-10-21 15:52:51 +00:00
|
|
|
vn_fullpath(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf)
|
|
|
|
{
|
2005-03-30 02:59:32 +00:00
|
|
|
char *buf;
|
2000-04-26 11:57:45 +00:00
|
|
|
struct filedesc *fdp;
|
2008-11-25 15:36:15 +00:00
|
|
|
struct vnode *rdir;
|
|
|
|
int error, vfslocked;
|
2000-04-26 11:57:45 +00:00
|
|
|
|
|
|
|
if (disablefullpath)
|
|
|
|
return (ENODEV);
|
2001-10-21 15:52:51 +00:00
|
|
|
if (vn == NULL)
|
2000-04-26 11:57:45 +00:00
|
|
|
return (EINVAL);
|
2005-03-30 02:59:32 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
|
2001-10-21 15:52:51 +00:00
|
|
|
fdp = td->td_proc->p_fd;
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SLOCK(fdp);
|
2008-11-25 15:36:15 +00:00
|
|
|
rdir = fdp->fd_rdir;
|
|
|
|
VREF(rdir);
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SUNLOCK(fdp);
|
2008-11-25 15:36:15 +00:00
|
|
|
error = vn_fullpath1(td, vn, rdir, buf, retbuf, MAXPATHLEN);
|
|
|
|
vfslocked = VFS_LOCK_GIANT(rdir->v_mount);
|
|
|
|
vrele(rdir);
|
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
2005-03-30 02:59:32 +00:00
|
|
|
|
|
|
|
if (!error)
|
2008-07-31 16:57:41 +00:00
|
|
|
*freebuf = buf;
|
|
|
|
else
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is similar to vn_fullpath, but it attempts to lookup the
|
|
|
|
* pathname relative to the global root mount point. This is required for the
|
|
|
|
* auditing sub-system, as audited pathnames must be absolute, relative to the
|
|
|
|
* global root mount point.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vn_fullpath_global(struct thread *td, struct vnode *vn,
|
|
|
|
char **retbuf, char **freebuf)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (disablefullpath)
|
|
|
|
return (ENODEV);
|
|
|
|
if (vn == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
|
|
|
|
error = vn_fullpath1(td, vn, rootvnode, buf, retbuf, MAXPATHLEN);
|
|
|
|
if (!error)
|
2005-03-30 02:59:32 +00:00
|
|
|
*freebuf = buf;
|
|
|
|
else
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2009-05-31 14:57:43 +00:00
|
|
|
int
|
|
|
|
vn_vptocnp(struct vnode **vp, char *buf, u_int *buflen)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
CACHE_RLOCK();
|
|
|
|
error = vn_vptocnp_locked(vp, buf, buflen);
|
|
|
|
if (error == 0) {
|
|
|
|
/*
|
|
|
|
* vn_vptocnp_locked() dropped hold acquired by
|
|
|
|
* VOP_VPTOCNP immediately after locking the
|
|
|
|
* cache. Since we are going to drop the cache rlock,
|
|
|
|
* re-hold the result.
|
|
|
|
*/
|
|
|
|
vhold(*vp);
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-12-12 00:57:38 +00:00
|
|
|
static int
|
2009-05-31 14:57:43 +00:00
|
|
|
vn_vptocnp_locked(struct vnode **vp, char *buf, u_int *buflen)
|
2008-12-12 00:57:38 +00:00
|
|
|
{
|
|
|
|
struct vnode *dvp;
|
2009-05-31 14:57:43 +00:00
|
|
|
struct namecache *ncp;
|
2008-12-12 00:57:38 +00:00
|
|
|
int error, vfslocked;
|
|
|
|
|
2009-05-31 14:57:43 +00:00
|
|
|
TAILQ_FOREACH(ncp, &((*vp)->v_cache_dst), nc_dst) {
|
|
|
|
if ((ncp->nc_flag & NCF_ISDOTDOT) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ncp != NULL) {
|
|
|
|
if (*buflen < ncp->nc_nlen) {
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
numfullpathfail4++;
|
|
|
|
error = ENOMEM;
|
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return, error,
|
2009-05-31 20:16:06 +00:00
|
|
|
vp, NULL, 0, 0);
|
2009-05-31 14:57:43 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
*buflen -= ncp->nc_nlen;
|
|
|
|
memcpy(buf + *buflen, ncp->nc_name, ncp->nc_nlen);
|
|
|
|
SDT_PROBE(vfs, namecache, fullpath, hit, ncp->nc_dvp,
|
|
|
|
ncp->nc_name, vp, 0, 0);
|
|
|
|
*vp = ncp->nc_dvp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
SDT_PROBE(vfs, namecache, fullpath, miss, vp, 0, 0, 0, 0);
|
|
|
|
|
2008-12-12 00:57:38 +00:00
|
|
|
vhold(*vp);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2008-12-12 00:57:38 +00:00
|
|
|
vfslocked = VFS_LOCK_GIANT((*vp)->v_mount);
|
|
|
|
vn_lock(*vp, LK_SHARED | LK_RETRY);
|
|
|
|
error = VOP_VPTOCNP(*vp, &dvp, buf, buflen);
|
|
|
|
VOP_UNLOCK(*vp, 0);
|
2008-12-23 20:04:31 +00:00
|
|
|
vdrop(*vp);
|
2008-12-12 00:57:38 +00:00
|
|
|
VFS_UNLOCK_GIANT(vfslocked);
|
|
|
|
if (error) {
|
|
|
|
numfullpathfail2++;
|
2009-05-31 20:16:06 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return, error, vp,
|
2009-05-31 14:57:43 +00:00
|
|
|
NULL, 0, 0);
|
2008-12-12 00:57:38 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2009-05-31 14:57:43 +00:00
|
|
|
|
2008-12-12 00:57:38 +00:00
|
|
|
*vp = dvp;
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RLOCK();
|
2008-12-12 00:57:38 +00:00
|
|
|
if ((*vp)->v_iflag & VI_DOOMED) {
|
|
|
|
/* forced unmount */
|
2009-04-04 17:48:38 +00:00
|
|
|
CACHE_RUNLOCK();
|
2008-12-12 00:57:38 +00:00
|
|
|
vdrop(*vp);
|
2009-05-31 14:57:43 +00:00
|
|
|
error = ENOENT;
|
2009-05-31 20:16:06 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return, error, vp,
|
2009-05-31 14:57:43 +00:00
|
|
|
NULL, 0, 0);
|
|
|
|
return (error);
|
2008-12-12 00:57:38 +00:00
|
|
|
}
|
|
|
|
vdrop(*vp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-03-30 02:59:32 +00:00
|
|
|
/*
|
|
|
|
* The magic behind kern___getcwd() and vn_fullpath().
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir,
|
|
|
|
char *buf, char **retbuf, u_int buflen)
|
|
|
|
{
|
2009-05-31 14:57:43 +00:00
|
|
|
int error, slash_prefixed;
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
#ifdef KDTRACE_HOOKS
|
|
|
|
struct vnode *startvp = vp;
|
|
|
|
#endif
|
2005-03-30 02:59:32 +00:00
|
|
|
|
2008-12-12 00:57:38 +00:00
|
|
|
buflen--;
|
2009-05-31 14:57:43 +00:00
|
|
|
buf[buflen] = '\0';
|
2005-03-30 02:59:32 +00:00
|
|
|
error = 0;
|
|
|
|
slash_prefixed = 0;
|
|
|
|
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, entry, vp, 0, 0, 0, 0);
|
2005-03-30 02:59:32 +00:00
|
|
|
numfullpathcalls++;
|
2009-05-31 14:57:43 +00:00
|
|
|
CACHE_RLOCK();
|
2005-03-30 02:59:32 +00:00
|
|
|
if (vp->v_type != VDIR) {
|
2009-05-31 14:57:43 +00:00
|
|
|
error = vn_vptocnp_locked(&vp, buf, &buflen);
|
|
|
|
if (error)
|
Nul-terminate strings in the VFS name cache, which negligibly change
the size and cost of name cache entries, but make adding debugging
and tracing easier.
Add SDT DTrace probes for various namecache events:
vfs:namecache:enter:done - new entry in the name cache, passed parent
directory vnode pointer, name added to the cache, and child vnode
pointer.
vfs:namecache:enter_negative:done - new negative entry in the name cache,
passed parent vnode pointer, name added to the cache.
vfs:namecache:fullpath:enter - call to vn_fullpath1() is made, passed
the vnode to resolve to a name.
vfs:namecache:fullpath:hit - vn_fullpath1() successfully resolved a
search for the parent of an object using the namecache, passed the
discovered parent directory vnode pointer, name, and child vnode
pointer.
vfs:namecache:fullpath:miss - vn_fullpath1() failed to resolve a search
for the parent of an object using the namecache, passed the child
vnode pointer.
vfs:namecache:fullpath:return - vn_fullpath1() has completed, passed the
error number, and if that is zero, the vnode to resolve, and the
returned path.
vfs:namecache:lookup:hit - postive name cache entry hit, passed the
parent directory vnode pointer, name, and child vnode pointer.
vfs:namecache:lookup:hit_negative - negative name cache entry hit,
passed the parent directory vnode pointer and name.
vfs:namecache:lookup:miss - name cache miss, passed the parent directory
pointer and the full remaining component name (not terminated after the
cache miss component).
vfs:namecache:purge:done - name cache purge for a vnode, passed the vnode
pointer to purge.
vfs:namecache:purge_negative:done - name cache purge of negative entries
for children of a vnode, passed the vnode pointer to purge.
vfs:namecache:purgevfs - name cache purge for a mountpoint, passed the
mount pointer. Separate probes will also be invoked for each cache
entry zapped.
vfs:namecache:zap:done - name cache entry zapped, passed the parent
directory vnode pointer, name, and child vnode pointer.
vfs:namecache:zap_negative:done - negative name cache entry zapped,
passed the parent directory vnode pointer and name.
For any probes involving an extant name cache entry (enter, hit, zapp),
we use the nul-terminated string for the name component. For misses,
the remainder of the path, including later components, is provided as
an argument instead since there is no handy nul-terminated version of
the string around. This is arguably a bug.
MFC after: 1 month
Sponsored by: Google, Inc.
Reviewed by: jhb, kan, kib (earlier version)
2009-04-07 20:58:56 +00:00
|
|
|
return (error);
|
2009-06-05 16:44:42 +00:00
|
|
|
if (buflen == 0) {
|
|
|
|
CACHE_RUNLOCK();
|
2009-05-31 14:57:43 +00:00
|
|
|
return (ENOMEM);
|
2009-06-05 16:44:42 +00:00
|
|
|
}
|
2009-05-31 14:57:43 +00:00
|
|
|
buf[--buflen] = '/';
|
2005-03-30 02:59:32 +00:00
|
|
|
slash_prefixed = 1;
|
|
|
|
}
|
|
|
|
while (vp != rdir && vp != rootvnode) {
|
2002-08-04 10:29:36 +00:00
|
|
|
if (vp->v_vflag & VV_ROOT) {
|
2006-02-06 10:15:27 +00:00
|
|
|
if (vp->v_iflag & VI_DOOMED) { /* forced unmount */
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2009-03-24 18:16:42 +00:00
|
|
|
error = ENOENT;
|
2009-05-31 20:16:06 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return,
|
|
|
|
error, vp, NULL, 0, 0);
|
2005-03-30 02:59:32 +00:00
|
|
|
break;
|
2000-04-26 11:57:45 +00:00
|
|
|
}
|
|
|
|
vp = vp->v_mount->mnt_vnodecovered;
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-12 00:57:38 +00:00
|
|
|
if (vp->v_type != VDIR) {
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2009-05-31 14:57:43 +00:00
|
|
|
numfullpathfail1++;
|
2005-03-30 02:59:32 +00:00
|
|
|
error = ENOTDIR;
|
2009-05-31 20:16:06 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return,
|
|
|
|
error, vp, NULL, 0, 0);
|
2005-03-30 02:59:32 +00:00
|
|
|
break;
|
2000-04-26 11:57:45 +00:00
|
|
|
}
|
2009-05-31 14:57:43 +00:00
|
|
|
error = vn_vptocnp_locked(&vp, buf, &buflen);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (buflen == 0) {
|
2009-06-05 16:44:42 +00:00
|
|
|
CACHE_RUNLOCK();
|
2005-03-30 02:59:32 +00:00
|
|
|
error = ENOMEM;
|
2009-05-31 20:16:06 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return, error,
|
|
|
|
startvp, NULL, 0, 0);
|
2005-03-30 02:59:32 +00:00
|
|
|
break;
|
2000-04-26 11:57:45 +00:00
|
|
|
}
|
2009-05-31 14:57:43 +00:00
|
|
|
buf[--buflen] = '/';
|
2000-04-26 11:57:45 +00:00
|
|
|
slash_prefixed = 1;
|
2005-03-30 02:59:32 +00:00
|
|
|
}
|
2009-05-31 14:57:43 +00:00
|
|
|
if (error)
|
2005-03-30 02:59:32 +00:00
|
|
|
return (error);
|
2000-04-26 11:57:45 +00:00
|
|
|
if (!slash_prefixed) {
|
2009-05-31 14:57:43 +00:00
|
|
|
if (buflen == 0) {
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2009-05-31 14:57:43 +00:00
|
|
|
numfullpathfail4++;
|
2009-05-31 20:16:06 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return, ENOMEM,
|
|
|
|
startvp, NULL, 0, 0);
|
2000-04-26 11:57:45 +00:00
|
|
|
return (ENOMEM);
|
2009-05-31 14:57:43 +00:00
|
|
|
}
|
|
|
|
buf[--buflen] = '/';
|
2000-04-26 11:57:45 +00:00
|
|
|
}
|
|
|
|
numfullpathfound++;
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2005-03-30 02:59:32 +00:00
|
|
|
|
2009-05-31 20:16:06 +00:00
|
|
|
SDT_PROBE(vfs, namecache, fullpath, return, 0, startvp, buf + buflen,
|
2009-05-31 14:57:43 +00:00
|
|
|
0, 0);
|
|
|
|
*retbuf = buf + buflen;
|
2000-04-26 11:57:45 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2008-03-31 11:53:03 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
vn_commname(struct vnode *vp, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
struct namecache *ncp;
|
|
|
|
int l;
|
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RLOCK();
|
2009-03-29 21:25:40 +00:00
|
|
|
TAILQ_FOREACH(ncp, &vp->v_cache_dst, nc_dst)
|
|
|
|
if ((ncp->nc_flag & NCF_ISDOTDOT) == 0)
|
|
|
|
break;
|
|
|
|
if (ncp == NULL) {
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2008-03-31 11:53:03 +00:00
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
l = min(ncp->nc_nlen, buflen - 1);
|
|
|
|
memcpy(buf, ncp->nc_name, l);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2008-03-31 11:53:03 +00:00
|
|
|
buf[l] = '\0';
|
|
|
|
return (0);
|
|
|
|
}
|