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.
|
2016-09-15 13:16:20 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-24 10:09:53 +00:00
|
|
|
* 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$");
|
|
|
|
|
2009-03-20 10:47:16 +00:00
|
|
|
#include "opt_ktrace.h"
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
2011-12-12 10:05:13 +00:00
|
|
|
#include <sys/systm.h>
|
2016-01-21 01:04:03 +00:00
|
|
|
#include <sys/counter.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>
|
2012-01-15 12:08:20 +00:00
|
|
|
#include <sys/fcntl.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>
|
2016-09-10 16:29:53 +00:00
|
|
|
#include <sys/smp.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/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);
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, enter, done, "struct vnode *", "char *",
|
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
|
|
|
"struct vnode *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, enter_negative, done, "struct vnode *",
|
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 *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE1(vfs, namecache, fullpath, entry, "struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, fullpath, hit, "struct vnode *",
|
2013-07-09 08:58:34 +00:00
|
|
|
"char *", "struct vnode *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE1(vfs, namecache, fullpath, miss, "struct vnode *");
|
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, fullpath, return, "int",
|
2013-07-09 08:58:34 +00:00
|
|
|
"struct vnode *", "char *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE3(vfs, namecache, lookup, hit, "struct vnode *", "char *",
|
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
|
|
|
"struct vnode *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, lookup, hit__negative,
|
2010-08-22 11:18:57 +00:00
|
|
|
"struct vnode *", "char *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, lookup, miss, "struct vnode *",
|
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 *");
|
2013-11-26 08:46:27 +00:00
|
|
|
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 *",
|
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
|
|
|
"struct vnode *");
|
2013-11-26 08:46:27 +00:00
|
|
|
SDT_PROBE_DEFINE2(vfs, namecache, zap_negative, done, "struct vnode *",
|
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 *");
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2012-01-22 01:11:06 +00:00
|
|
|
/*
|
|
|
|
* struct namecache_ts repeats struct namecache layout up to the
|
|
|
|
* nc_nlen member.
|
2012-03-03 01:06:54 +00:00
|
|
|
* struct namecache_ts is used in place of struct namecache when time(s) need
|
|
|
|
* to be stored. The nc_dotdottime field is used when a cache entry is mapping
|
|
|
|
* both a non-dotdot directory name plus dotdot for the directory's
|
|
|
|
* parent.
|
2012-01-22 01:11:06 +00:00
|
|
|
*/
|
|
|
|
struct namecache_ts {
|
|
|
|
LIST_ENTRY(namecache) nc_hash; /* hash chain */
|
|
|
|
LIST_ENTRY(namecache) nc_src; /* source vnode list */
|
|
|
|
TAILQ_ENTRY(namecache) nc_dst; /* destination vnode list */
|
|
|
|
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 */
|
|
|
|
struct timespec nc_time; /* timespec provided by fs */
|
2012-03-03 01:06:54 +00:00
|
|
|
struct timespec nc_dotdottime; /* dotdot timespec provided by fs */
|
2012-01-22 01:11:06 +00:00
|
|
|
int nc_ticks; /* ticks value when entry was added */
|
|
|
|
char nc_name[0]; /* segment name + nul */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flags in namecache.nc_flag
|
|
|
|
*/
|
|
|
|
#define NCF_WHITE 0x01
|
|
|
|
#define NCF_ISDOTDOT 0x02
|
|
|
|
#define NCF_TS 0x04
|
2012-03-03 01:06:54 +00:00
|
|
|
#define NCF_DTS 0x08
|
2016-09-04 16:52:14 +00:00
|
|
|
#define NCF_DVDROP 0x10
|
2012-01-22 01:11:06 +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.
|
2016-09-10 16:29:53 +00:00
|
|
|
*
|
|
|
|
* These locks are used (in the order in which they can be taken):
|
|
|
|
* NAME TYPE ROLE
|
|
|
|
* cache_lock rwlock global, needed for all modifications
|
|
|
|
* bucketlock rwlock for access to given hash bucket
|
|
|
|
* ncneg_mtx mtx negative entry LRU management
|
|
|
|
*
|
|
|
|
* A name -> vnode lookup can be safely performed by either locking cache_lock
|
|
|
|
* or the relevant hash bucket.
|
|
|
|
*
|
|
|
|
* ".." and vnode -> name lookups require cache_lock.
|
|
|
|
*
|
|
|
|
* Modifications require both cache_lock and relevant bucketlock taken for
|
|
|
|
* writing.
|
|
|
|
*
|
|
|
|
* Negative entry LRU management requires ncneg_mtx taken on top of either
|
|
|
|
* cache_lock or bucketlock.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-04-29 22:15:33 +00:00
|
|
|
* Structures associated with name caching.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
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 */
|
2010-10-16 09:44:31 +00:00
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, 0,
|
|
|
|
"Size of namecache hash table");
|
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 */
|
2010-10-16 09:44:31 +00:00
|
|
|
SYSCTL_ULONG(_vfs, OID_AUTO, ncnegfactor, CTLFLAG_RW, &ncnegfactor, 0,
|
|
|
|
"Ratio of negative namecache entries");
|
|
|
|
static u_long numneg; /* number of negative entries allocated */
|
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, numneg, CTLFLAG_RD, &numneg, 0,
|
|
|
|
"Number of negative entries in namecache");
|
1997-03-08 15:22:14 +00:00
|
|
|
static u_long numcache; /* number of cache entries allocated */
|
2010-10-16 09:44:31 +00:00
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, numcache, CTLFLAG_RD, &numcache, 0,
|
|
|
|
"Number of namecache entries");
|
2001-04-18 11:19:50 +00:00
|
|
|
static u_long numcachehv; /* number of cache entries with vnodes held */
|
2010-10-16 09:44:31 +00:00
|
|
|
SYSCTL_ULONG(_debug, OID_AUTO, numcachehv, CTLFLAG_RD, &numcachehv, 0,
|
|
|
|
"Number of namecache entries with vnodes held");
|
2016-02-24 15:15:46 +00:00
|
|
|
u_int ncsizefactor = 2;
|
2010-10-16 09:44:31 +00:00
|
|
|
SYSCTL_UINT(_vfs, OID_AUTO, ncsizefactor, CTLFLAG_RW, &ncsizefactor, 0,
|
|
|
|
"Size factor for namecache");
|
|
|
|
|
|
|
|
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;
|
2016-09-10 16:29:53 +00:00
|
|
|
RW_SYSINIT(vfscache, &cache_lock, "ncglobal");
|
2003-10-05 07:13:50 +00:00
|
|
|
|
2016-09-10 16:29:53 +00:00
|
|
|
#define CACHE_TRY_WLOCK() rw_try_wlock(&cache_lock)
|
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
|
|
|
|
2016-09-04 08:58:35 +00:00
|
|
|
static struct mtx_padalign ncneg_mtx;
|
2016-09-10 16:29:53 +00:00
|
|
|
MTX_SYSINIT(vfscache_neg, &ncneg_mtx, "ncneg", MTX_DEF);
|
|
|
|
|
|
|
|
static u_int numbucketlocks;
|
|
|
|
static struct rwlock_padalign *bucketlocks;
|
|
|
|
#define HASH2BUCKETLOCK(hash) \
|
|
|
|
((struct rwlock *)(&bucketlocks[((hash) % numbucketlocks)]))
|
2016-09-04 08:58:35 +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;
|
2012-01-22 01:11:06 +00:00
|
|
|
static uma_zone_t cache_zone_small_ts;
|
2003-06-13 08:46:13 +00:00
|
|
|
static uma_zone_t cache_zone_large;
|
2012-03-03 01:06:54 +00:00
|
|
|
static uma_zone_t cache_zone_large_ts;
|
2003-06-13 08:46:13 +00:00
|
|
|
|
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
|
2012-01-22 01:11:06 +00:00
|
|
|
|
|
|
|
static struct namecache *
|
|
|
|
cache_alloc(int len, int ts)
|
|
|
|
{
|
|
|
|
|
2012-03-03 01:06:54 +00:00
|
|
|
if (len > CACHE_PATH_CUTOFF) {
|
|
|
|
if (ts)
|
|
|
|
return (uma_zalloc(cache_zone_large_ts, M_WAITOK));
|
|
|
|
else
|
|
|
|
return (uma_zalloc(cache_zone_large, M_WAITOK));
|
|
|
|
}
|
2012-01-22 01:11:06 +00:00
|
|
|
if (ts)
|
|
|
|
return (uma_zalloc(cache_zone_small_ts, M_WAITOK));
|
|
|
|
else
|
|
|
|
return (uma_zalloc(cache_zone_small, M_WAITOK));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cache_free(struct namecache *ncp)
|
|
|
|
{
|
|
|
|
int ts;
|
|
|
|
|
|
|
|
if (ncp == NULL)
|
|
|
|
return;
|
|
|
|
ts = ncp->nc_flag & NCF_TS;
|
2016-09-04 16:52:14 +00:00
|
|
|
if ((ncp->nc_flag & NCF_DVDROP) != 0)
|
|
|
|
vdrop(ncp->nc_dvp);
|
2012-01-22 01:11:06 +00:00
|
|
|
if (ncp->nc_nlen <= CACHE_PATH_CUTOFF) {
|
|
|
|
if (ts)
|
|
|
|
uma_zfree(cache_zone_small_ts, ncp);
|
|
|
|
else
|
|
|
|
uma_zfree(cache_zone_small, ncp);
|
2012-03-03 01:06:54 +00:00
|
|
|
} else if (ts)
|
|
|
|
uma_zfree(cache_zone_large_ts, ncp);
|
|
|
|
else
|
2012-01-22 01:11:06 +00:00
|
|
|
uma_zfree(cache_zone_large, ncp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
nc_get_name(struct namecache *ncp)
|
|
|
|
{
|
|
|
|
struct namecache_ts *ncp_ts;
|
|
|
|
|
|
|
|
if ((ncp->nc_flag & NCF_TS) == 0)
|
|
|
|
return (ncp->nc_name);
|
|
|
|
ncp_ts = (struct namecache_ts *)ncp;
|
|
|
|
return (ncp_ts->nc_name);
|
|
|
|
}
|
2003-06-13 08:46:13 +00:00
|
|
|
|
2012-01-23 17:09:23 +00:00
|
|
|
static void
|
|
|
|
cache_out_ts(struct namecache *ncp, struct timespec *tsp, int *ticksp)
|
|
|
|
{
|
|
|
|
|
2012-01-25 20:48:20 +00:00
|
|
|
KASSERT((ncp->nc_flag & NCF_TS) != 0 ||
|
|
|
|
(tsp == NULL && ticksp == NULL),
|
|
|
|
("No NCF_TS"));
|
2012-01-23 17:09:23 +00:00
|
|
|
|
|
|
|
if (tsp != NULL)
|
|
|
|
*tsp = ((struct namecache_ts *)ncp)->nc_time;
|
|
|
|
if (ticksp != NULL)
|
|
|
|
*ticksp = ((struct namecache_ts *)ncp)->nc_ticks;
|
|
|
|
}
|
|
|
|
|
1997-03-08 15:22:14 +00:00
|
|
|
static int doingcache = 1; /* 1 => enable the cache */
|
2010-10-16 09:44:31 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
|
|
|
|
"VFS namecache enabled");
|
2002-03-05 15:38:49 +00:00
|
|
|
|
|
|
|
/* Export size information to userland */
|
2014-10-21 07:31:21 +00:00
|
|
|
SYSCTL_INT(_debug_sizeof, OID_AUTO, namecache, CTLFLAG_RD, SYSCTL_NULL_INT_PTR,
|
2010-11-14 16:10:15 +00:00
|
|
|
sizeof(struct namecache), "sizeof(struct namecache)");
|
1997-03-08 15:22:14 +00:00
|
|
|
|
1997-09-24 07:46:54 +00:00
|
|
|
/*
|
|
|
|
* The new name cache statistics
|
|
|
|
*/
|
2010-11-14 08:06:29 +00:00
|
|
|
static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, 0,
|
2010-11-14 16:10:15 +00:00
|
|
|
"Name cache statistics");
|
2016-01-21 01:04:03 +00:00
|
|
|
#define STATNODE_ULONG(name, descr) \
|
|
|
|
SYSCTL_ULONG(_vfs_cache, OID_AUTO, name, CTLFLAG_RD, &name, 0, descr);
|
|
|
|
#define STATNODE_COUNTER(name, descr) \
|
|
|
|
static counter_u64_t name; \
|
|
|
|
SYSCTL_COUNTER_U64(_vfs_cache, OID_AUTO, name, CTLFLAG_RD, &name, descr);
|
|
|
|
STATNODE_ULONG(numneg, "Number of negative cache entries");
|
|
|
|
STATNODE_ULONG(numcache, "Number of cache entries");
|
|
|
|
STATNODE_COUNTER(numcalls, "Number of cache lookups");
|
|
|
|
STATNODE_COUNTER(dothits, "Number of '.' hits");
|
|
|
|
STATNODE_COUNTER(dotdothits, "Number of '..' hits");
|
|
|
|
STATNODE_COUNTER(numchecks, "Number of checks in lookup");
|
|
|
|
STATNODE_COUNTER(nummiss, "Number of cache misses");
|
|
|
|
STATNODE_COUNTER(nummisszap, "Number of cache misses we do not want to cache");
|
|
|
|
STATNODE_COUNTER(numposzaps,
|
2010-11-14 16:10:15 +00:00
|
|
|
"Number of cache hits (positive) we do not want to cache");
|
2016-01-21 01:04:03 +00:00
|
|
|
STATNODE_COUNTER(numposhits, "Number of cache hits (positive)");
|
|
|
|
STATNODE_COUNTER(numnegzaps,
|
2010-11-14 16:10:15 +00:00
|
|
|
"Number of cache hits (negative) we do not want to cache");
|
2016-01-21 01:04:03 +00:00
|
|
|
STATNODE_COUNTER(numneghits, "Number of cache hits (negative)");
|
|
|
|
/* These count for kern___getcwd(), too. */
|
|
|
|
STATNODE_COUNTER(numfullpathcalls, "Number of fullpath search calls");
|
|
|
|
STATNODE_COUNTER(numfullpathfail1, "Number of fullpath search errors (ENOTDIR)");
|
|
|
|
STATNODE_COUNTER(numfullpathfail2,
|
|
|
|
"Number of fullpath search errors (VOP_VPTOCNP failures)");
|
|
|
|
STATNODE_COUNTER(numfullpathfail4, "Number of fullpath search errors (ENOMEM)");
|
|
|
|
STATNODE_COUNTER(numfullpathfound, "Number of successful fullpath calls");
|
|
|
|
static long numupgrades; STATNODE_ULONG(numupgrades,
|
2010-11-14 16:10:15 +00:00
|
|
|
"Number of updates of the cache after lookup (write lock + retry)");
|
2016-09-10 16:29:53 +00:00
|
|
|
static long zap_and_exit_bucket_fail; STATNODE_ULONG(zap_and_exit_bucket_fail,
|
|
|
|
"Number of times bucketlocked zap_and_exit case failed to writelock");
|
1997-09-24 07:46:54 +00:00
|
|
|
|
2005-01-24 10:24:12 +00:00
|
|
|
static void cache_zap(struct namecache *ncp);
|
2009-06-21 19:21:01 +00:00
|
|
|
static int vn_vptocnp_locked(struct vnode **vp, struct ucred *cred, 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
|
|
|
|
2016-01-21 01:05:41 +00:00
|
|
|
static uint32_t
|
|
|
|
cache_get_hash(char *name, u_char len, struct vnode *dvp)
|
|
|
|
{
|
|
|
|
uint32_t hash;
|
|
|
|
|
|
|
|
hash = fnv_32_buf(name, len, FNV1_32_INIT);
|
|
|
|
hash = fnv_32_buf(&dvp, sizeof(dvp), hash);
|
|
|
|
return (hash);
|
|
|
|
}
|
|
|
|
|
2016-09-10 16:29:53 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
static void
|
|
|
|
cache_assert_bucket_locked(struct namecache *ncp, int mode)
|
|
|
|
{
|
|
|
|
struct rwlock *bucketlock;
|
|
|
|
uint32_t hash;
|
|
|
|
|
|
|
|
hash = cache_get_hash(nc_get_name(ncp), ncp->nc_nlen, ncp->nc_dvp);
|
|
|
|
bucketlock = HASH2BUCKETLOCK(hash);
|
|
|
|
rw_assert(bucketlock, mode);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define cache_assert_bucket_locked(x, y) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
cache_lock_all_buckets(void)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numbucketlocks; i++)
|
|
|
|
rw_wlock(&bucketlocks[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cache_unlock_all_buckets(void)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numbucketlocks; i++)
|
|
|
|
rw_wunlock(&bucketlocks[i]);
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:04:03 +00:00
|
|
|
static int
|
|
|
|
sysctl_nchstats(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct nchstats snap;
|
|
|
|
|
|
|
|
if (req->oldptr == NULL)
|
|
|
|
return (SYSCTL_OUT(req, 0, sizeof(snap)));
|
|
|
|
|
|
|
|
snap = nchstats;
|
|
|
|
snap.ncs_goodhits = counter_u64_fetch(numposhits);
|
|
|
|
snap.ncs_neghits = counter_u64_fetch(numneghits);
|
|
|
|
snap.ncs_badhits = counter_u64_fetch(numposzaps) +
|
|
|
|
counter_u64_fetch(numnegzaps);
|
|
|
|
snap.ncs_miss = counter_u64_fetch(nummisszap) +
|
|
|
|
counter_u64_fetch(nummiss);
|
|
|
|
|
|
|
|
return (SYSCTL_OUT(req, &snap, sizeof(snap)));
|
|
|
|
}
|
|
|
|
SYSCTL_PROC(_vfs_cache, OID_AUTO, nchstats, CTLTYPE_OPAQUE | CTLFLAG_RD |
|
|
|
|
CTLFLAG_MPSAFE, 0, 0, sysctl_nchstats, "LU",
|
|
|
|
"VFS cache effectiveness statistics");
|
|
|
|
|
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
|
|
|
|
*/
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_debug, OID_AUTO, hashstat, CTLFLAG_RW, NULL,
|
|
|
|
"hash table stats");
|
2001-04-11 00:39:20 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_debug_hashstat_rawnchash(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct nchashhead *ncpp;
|
|
|
|
struct namecache *ncp;
|
2015-04-18 00:59:03 +00:00
|
|
|
int i, error, n_nchash, *cntbuf;
|
2001-04-11 00:39:20 +00:00
|
|
|
|
2015-09-06 05:50:51 +00:00
|
|
|
retry:
|
2001-04-11 00:39:20 +00:00
|
|
|
n_nchash = nchash + 1; /* nchash is max index, not count */
|
2015-04-18 00:59:03 +00:00
|
|
|
if (req->oldptr == NULL)
|
2001-04-11 00:39:20 +00:00
|
|
|
return SYSCTL_OUT(req, 0, n_nchash * sizeof(int));
|
2015-04-18 00:59:03 +00:00
|
|
|
cntbuf = malloc(n_nchash * sizeof(int), M_TEMP, M_ZERO | M_WAITOK);
|
|
|
|
CACHE_RLOCK();
|
2015-09-06 05:50:51 +00:00
|
|
|
if (n_nchash != nchash + 1) {
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
free(cntbuf, M_TEMP);
|
|
|
|
goto retry;
|
|
|
|
}
|
2015-04-18 00:59:03 +00:00
|
|
|
/* Scan hash tables counting entries */
|
|
|
|
for (ncpp = nchashtbl, i = 0; i < n_nchash; ncpp++, i++)
|
|
|
|
LIST_FOREACH(ncp, ncpp, nc_hash)
|
|
|
|
cntbuf[i]++;
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
for (error = 0, i = 0; i < n_nchash; i++)
|
|
|
|
if ((error = SYSCTL_OUT(req, &cntbuf[i], sizeof(int))) != 0)
|
|
|
|
break;
|
|
|
|
free(cntbuf, M_TEMP);
|
|
|
|
return (error);
|
2001-04-11 00:39:20 +00:00
|
|
|
}
|
2009-01-23 22:49:23 +00:00
|
|
|
SYSCTL_PROC(_debug_hashstat, OID_AUTO, rawnchash, CTLTYPE_INT|CTLFLAG_RD|
|
2010-11-14 16:10:15 +00:00
|
|
|
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));
|
|
|
|
|
2015-04-18 00:59:03 +00:00
|
|
|
CACHE_RLOCK();
|
2001-04-11 00:39:20 +00:00
|
|
|
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;
|
|
|
|
LIST_FOREACH(ncp, ncpp, nc_hash) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (count)
|
|
|
|
used++;
|
|
|
|
if (maxlength < count)
|
|
|
|
maxlength = count;
|
|
|
|
}
|
|
|
|
n_nchash = nchash + 1;
|
2015-04-18 00:59:03 +00:00
|
|
|
CACHE_RUNLOCK();
|
2012-02-25 12:06:40 +00:00
|
|
|
pct = (used * 100) / (n_nchash / 100);
|
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|
|
2010-11-14 16:10:15 +00:00
|
|
|
CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_nchash, "I",
|
2012-02-25 12:06:40 +00:00
|
|
|
"nchash statistics (number of total/used buckets, maximum chain length, usage percentage)");
|
2009-03-09 19:04:53 +00:00
|
|
|
#endif
|
2001-04-11 00:39:20 +00:00
|
|
|
|
2016-09-04 08:55:15 +00:00
|
|
|
/*
|
|
|
|
* Negative entries management
|
|
|
|
*/
|
|
|
|
static void
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_negative_hit(struct namecache *ncp)
|
2016-09-04 08:55:15 +00:00
|
|
|
{
|
|
|
|
|
2016-09-10 16:29:53 +00:00
|
|
|
mtx_lock(&ncneg_mtx);
|
2016-09-04 08:55:15 +00:00
|
|
|
TAILQ_REMOVE(&ncneg, ncp, nc_dst);
|
|
|
|
TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
|
2016-09-10 16:29:53 +00:00
|
|
|
mtx_unlock(&ncneg_mtx);
|
2016-09-04 08:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cache_negative_insert(struct namecache *ncp)
|
|
|
|
{
|
|
|
|
|
|
|
|
rw_assert(&cache_lock, RA_WLOCKED);
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_assert_bucket_locked(ncp, RA_WLOCKED);
|
2016-09-04 08:55:15 +00:00
|
|
|
MPASS(ncp->nc_vp == NULL);
|
2016-09-10 16:29:53 +00:00
|
|
|
mtx_lock(&ncneg_mtx);
|
2016-09-04 08:55:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
|
|
|
|
numneg++;
|
2016-09-10 16:29:53 +00:00
|
|
|
mtx_unlock(&ncneg_mtx);
|
2016-09-04 08:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cache_negative_remove(struct namecache *ncp)
|
|
|
|
{
|
|
|
|
|
|
|
|
rw_assert(&cache_lock, RA_WLOCKED);
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_assert_bucket_locked(ncp, RA_WLOCKED);
|
2016-09-04 08:55:15 +00:00
|
|
|
MPASS(ncp->nc_vp == NULL);
|
2016-09-10 16:29:53 +00:00
|
|
|
mtx_lock(&ncneg_mtx);
|
2016-09-04 08:55:15 +00:00
|
|
|
TAILQ_REMOVE(&ncneg, ncp, nc_dst);
|
|
|
|
numneg--;
|
2016-09-10 16:29:53 +00:00
|
|
|
mtx_unlock(&ncneg_mtx);
|
2016-09-04 08:55:15 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 16:52:14 +00:00
|
|
|
static struct namecache *
|
2016-09-04 08:55:15 +00:00
|
|
|
cache_negative_zap_one(void)
|
|
|
|
{
|
|
|
|
struct namecache *ncp;
|
|
|
|
|
|
|
|
rw_assert(&cache_lock, RA_WLOCKED);
|
|
|
|
ncp = TAILQ_FIRST(&ncneg);
|
|
|
|
KASSERT(ncp->nc_vp == NULL, ("ncp %p vp %p on ncneg",
|
|
|
|
ncp, ncp->nc_vp));
|
|
|
|
cache_zap(ncp);
|
2016-09-04 16:52:14 +00:00
|
|
|
return (ncp);
|
2016-09-04 08:55:15 +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
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_zap_locked(struct namecache *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
|
|
|
{
|
2003-10-05 07:13:50 +00:00
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
rw_assert(&cache_lock, RA_WLOCKED);
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_assert_bucket_locked(ncp, 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
|
|
|
if (ncp->nc_vp != NULL) {
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, zap, done, ncp->nc_dvp,
|
|
|
|
nc_get_name(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
|
|
|
} else {
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE2(vfs, namecache, zap_negative, done, ncp->nc_dvp,
|
|
|
|
nc_get_name(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
|
|
|
}
|
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)) {
|
2016-09-04 16:52:14 +00:00
|
|
|
ncp->nc_flag |= NCF_DVDROP;
|
2009-03-29 21:25:40 +00:00
|
|
|
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 {
|
2016-09-04 08:55:15 +00:00
|
|
|
cache_negative_remove(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
|
|
|
}
|
|
|
|
numcache--;
|
1997-02-10 02:22:35 +00:00
|
|
|
}
|
1995-03-09 20:23:45 +00:00
|
|
|
|
2016-09-10 16:29:53 +00:00
|
|
|
static void
|
|
|
|
cache_zap(struct namecache *ncp)
|
|
|
|
{
|
|
|
|
struct rwlock *bucketlock;
|
|
|
|
uint32_t hash;
|
|
|
|
|
|
|
|
rw_assert(&cache_lock, RA_WLOCKED);
|
|
|
|
|
|
|
|
hash = cache_get_hash(nc_get_name(ncp), ncp->nc_nlen, ncp->nc_dvp);
|
|
|
|
bucketlock = HASH2BUCKETLOCK(hash);
|
|
|
|
rw_wlock(bucketlock);
|
|
|
|
cache_zap_locked(ncp);
|
|
|
|
rw_wunlock(bucketlock);
|
|
|
|
}
|
|
|
|
|
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
|
2016-04-29 22:15:33 +00:00
|
|
|
* (negative caching), 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
|
|
|
|
2016-09-10 16:29:53 +00:00
|
|
|
enum { UNLOCKED, WLOCKED, RLOCKED };
|
|
|
|
|
|
|
|
static void
|
|
|
|
cache_unlock(int cache_locked)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (cache_locked) {
|
|
|
|
case UNLOCKED:
|
|
|
|
break;
|
|
|
|
case WLOCKED:
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
break;
|
|
|
|
case RLOCKED:
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
int
|
2016-01-07 02:04:17 +00:00
|
|
|
cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp,
|
|
|
|
struct timespec *tsp, int *ticksp)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2016-09-10 16:29:53 +00:00
|
|
|
struct rwlock *bucketlock;
|
1999-10-03 12:18:29 +00:00
|
|
|
struct namecache *ncp;
|
2010-06-21 09:55:56 +00:00
|
|
|
uint32_t hash;
|
2016-09-10 16:29:53 +00:00
|
|
|
int error, ltype, cache_locked;
|
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:
|
2016-09-10 16:29:53 +00:00
|
|
|
bucketlock = NULL;
|
|
|
|
cache_locked = UNLOCKED;
|
2009-01-28 19:05:18 +00:00
|
|
|
error = 0;
|
2016-09-10 16:29:53 +00:00
|
|
|
counter_u64_add(numcalls, 1);
|
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);
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(dothits, 1);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, lookup, hit, dvp, ".", *vpp);
|
2012-01-20 20:02:01 +00:00
|
|
|
if (tsp != NULL)
|
|
|
|
timespecclear(tsp);
|
|
|
|
if (ticksp != NULL)
|
|
|
|
*ticksp = ticks;
|
2016-01-21 01:07:05 +00:00
|
|
|
VREF(*vpp);
|
|
|
|
/*
|
|
|
|
* When we lookup "." we still can be asked to lock it
|
|
|
|
* differently...
|
|
|
|
*/
|
|
|
|
ltype = cnp->cn_lkflags & LK_TYPE_MASK;
|
|
|
|
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;
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
vn_lock(*vpp, LK_DOWNGRADE | LK_RETRY);
|
|
|
|
}
|
|
|
|
return (-1);
|
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] == '.') {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(dotdothits, 1);
|
2016-09-10 16:29:53 +00:00
|
|
|
if (cache_locked == UNLOCKED) {
|
|
|
|
CACHE_RLOCK();
|
|
|
|
cache_locked = RLOCKED;
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, lookup, miss, dvp,
|
|
|
|
"..", NULL);
|
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) {
|
2016-09-10 16:29:53 +00:00
|
|
|
if (cache_locked != WLOCKED &&
|
|
|
|
!CACHE_UPGRADE_LOCK())
|
2009-04-11 16:12:20 +00:00
|
|
|
goto wlock;
|
2016-09-04 16:52:14 +00:00
|
|
|
ncp = NULL;
|
|
|
|
if (dvp->v_cache_dd->nc_flag & NCF_ISDOTDOT) {
|
|
|
|
ncp = dvp->v_cache_dd;
|
|
|
|
cache_zap(ncp);
|
|
|
|
}
|
2009-03-29 21:25:40 +00:00
|
|
|
dvp->v_cache_dd = NULL;
|
2009-08-14 10:57:28 +00:00
|
|
|
CACHE_WUNLOCK();
|
2016-09-04 16:52:14 +00:00
|
|
|
cache_free(ncp);
|
2009-08-14 10:57:28 +00:00
|
|
|
return (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
|
|
|
}
|
2012-01-20 20:02:01 +00:00
|
|
|
ncp = dvp->v_cache_dd;
|
|
|
|
if (ncp->nc_flag & NCF_ISDOTDOT)
|
|
|
|
*vpp = ncp->nc_vp;
|
2009-03-29 21:25:40 +00:00
|
|
|
else
|
2012-01-20 20:02:01 +00:00
|
|
|
*vpp = ncp->nc_dvp;
|
2009-04-14 23:46:57 +00:00
|
|
|
/* Return failure if negative entry was found. */
|
2012-01-20 20:02:01 +00:00
|
|
|
if (*vpp == NULL)
|
2009-04-14 23:56:48 +00:00
|
|
|
goto negative_success;
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR3(KTR_VFS, "cache_lookup(%p, %s) found %p via ..",
|
|
|
|
dvp, cnp->cn_nameptr, *vpp);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, lookup, hit, dvp, "..",
|
|
|
|
*vpp);
|
2012-01-23 17:09:23 +00:00
|
|
|
cache_out_ts(ncp, tsp, ticksp);
|
2012-03-03 01:06:54 +00:00
|
|
|
if ((ncp->nc_flag & (NCF_ISDOTDOT | NCF_DTS)) ==
|
|
|
|
NCF_DTS && tsp != NULL)
|
|
|
|
*tsp = ((struct namecache_ts *)ncp)->
|
|
|
|
nc_dotdottime;
|
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
|
|
|
}
|
2016-09-10 16:29:53 +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
|
|
|
|
2016-01-21 01:05:41 +00:00
|
|
|
hash = cache_get_hash(cnp->cn_nameptr, cnp->cn_namelen, dvp);
|
2016-09-10 16:29:53 +00:00
|
|
|
if (cache_locked == UNLOCKED) {
|
|
|
|
bucketlock = HASH2BUCKETLOCK(hash);
|
|
|
|
rw_rlock(bucketlock);
|
|
|
|
}
|
|
|
|
|
2001-03-20 02:10:18 +00:00
|
|
|
LIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numchecks, 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
|
|
|
if (ncp->nc_dvp == dvp && ncp->nc_nlen == cnp->cn_namelen &&
|
2012-01-22 01:11:06 +00:00
|
|
|
!bcmp(nc_get_name(ncp), 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) {
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, lookup, miss, dvp, cnp->cn_nameptr,
|
|
|
|
NULL);
|
1997-09-24 15:54:10 +00:00
|
|
|
if ((cnp->cn_flags & MAKEENTRY) == 0) {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(nummisszap, 1);
|
1997-09-24 15:54:10 +00:00
|
|
|
} else {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(nummiss, 1);
|
1997-09-24 15:54:10 +00:00
|
|
|
}
|
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) {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numposzaps, 1);
|
2016-09-10 16:29:53 +00:00
|
|
|
goto zap_and_exit;
|
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) {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numposhits, 1);
|
1994-05-24 10:09:53 +00:00
|
|
|
*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);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, lookup, hit, dvp, nc_get_name(ncp),
|
|
|
|
*vpp);
|
2012-01-23 17:09:23 +00:00
|
|
|
cache_out_ts(ncp, tsp, ticksp);
|
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) {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numnegzaps, 1);
|
2016-09-10 16:29:53 +00:00
|
|
|
goto zap_and_exit;
|
1995-03-09 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numneghits, 1);
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_negative_hit(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
|
|
|
if (ncp->nc_flag & NCF_WHITE)
|
|
|
|
cnp->cn_flags |= ISWHITEOUT;
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE2(vfs, namecache, lookup, hit__negative, dvp,
|
|
|
|
nc_get_name(ncp));
|
2012-01-23 17:09:23 +00:00
|
|
|
cache_out_ts(ncp, tsp, ticksp);
|
2016-09-10 16:29:53 +00:00
|
|
|
MPASS(bucketlock != NULL || cache_locked != UNLOCKED);
|
|
|
|
if (bucketlock != NULL)
|
|
|
|
rw_runlock(bucketlock);
|
|
|
|
cache_unlock(cache_locked);
|
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();
|
2016-09-10 16:29:53 +00:00
|
|
|
wlock_unlocked:
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WLOCK();
|
|
|
|
numupgrades++;
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_locked = WLOCKED;
|
2009-01-28 19:05:18 +00:00
|
|
|
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.
|
|
|
|
*/
|
2016-01-21 01:07:05 +00:00
|
|
|
MPASS(dvp != *vpp);
|
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
|
|
|
}
|
2015-07-16 13:57:05 +00:00
|
|
|
vhold(*vpp);
|
2016-09-10 16:29:53 +00:00
|
|
|
MPASS(bucketlock != NULL || cache_locked != UNLOCKED);
|
|
|
|
if (bucketlock != NULL)
|
|
|
|
rw_runlock(bucketlock);
|
|
|
|
cache_unlock(cache_locked);
|
2015-07-16 13:57:05 +00:00
|
|
|
error = vget(*vpp, cnp->cn_lkflags | LK_VNHELD, 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:
|
2016-09-10 16:29:53 +00:00
|
|
|
MPASS(bucketlock != NULL || cache_locked != UNLOCKED);
|
|
|
|
if (bucketlock != NULL)
|
|
|
|
rw_runlock(bucketlock);
|
|
|
|
cache_unlock(cache_locked);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
zap_and_exit:
|
|
|
|
if (bucketlock != NULL) {
|
|
|
|
rw_assert(&cache_lock, RA_UNLOCKED);
|
|
|
|
if (!CACHE_TRY_WLOCK()) {
|
|
|
|
rw_runlock(bucketlock);
|
|
|
|
bucketlock = NULL;
|
|
|
|
zap_and_exit_bucket_fail++;
|
|
|
|
goto wlock_unlocked;
|
|
|
|
}
|
|
|
|
cache_locked = WLOCKED;
|
|
|
|
rw_runlock(bucketlock);
|
|
|
|
bucketlock = NULL;
|
|
|
|
} else if (cache_locked != WLOCKED && !CACHE_UPGRADE_LOCK())
|
|
|
|
goto wlock;
|
|
|
|
cache_zap(ncp);
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
cache_free(ncp);
|
2009-01-28 19:05:18 +00:00
|
|
|
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
|
2016-01-07 02:04:17 +00:00
|
|
|
cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp,
|
|
|
|
struct timespec *tsp, struct timespec *dtsp)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2016-09-10 16:29:53 +00:00
|
|
|
struct rwlock *bucketlock;
|
2016-09-04 16:52:14 +00:00
|
|
|
struct namecache *ncp, *n2, *ndd, *nneg;
|
2012-01-22 01:11:06 +00:00
|
|
|
struct namecache_ts *n3;
|
1999-10-03 12:18:29 +00:00
|
|
|
struct nchashhead *ncpp;
|
2010-06-21 09:55:56 +00:00
|
|
|
uint32_t hash;
|
2009-03-29 21:25:40 +00:00
|
|
|
int flag;
|
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,
|
2010-04-15 17:17:02 +00:00
|
|
|
("cache_enter: Adding a doomed vnode"));
|
2010-04-20 10:19:27 +00:00
|
|
|
VNASSERT(dvp == NULL || (dvp->v_iflag & VI_DOOMED) == 0, dvp,
|
|
|
|
("cache_enter: Doomed vnode used as src"));
|
2005-06-11 08:47:30 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2010-10-16 09:44:31 +00:00
|
|
|
if (numcache >= desiredvnodes * ncsizefactor)
|
2009-01-20 04:21:21 +00:00
|
|
|
return;
|
|
|
|
|
2016-09-04 16:52:14 +00:00
|
|
|
ndd = nneg = NULL;
|
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"));
|
2013-12-27 17:09:59 +00:00
|
|
|
if (ncp->nc_vp != NULL) {
|
2009-03-29 21:25:40 +00:00
|
|
|
TAILQ_REMOVE(&ncp->nc_vp->v_cache_dst,
|
|
|
|
ncp, nc_dst);
|
2013-12-27 17:09:59 +00:00
|
|
|
} else {
|
2016-09-04 08:55:15 +00:00
|
|
|
cache_negative_remove(ncp);
|
2013-12-27 17:09:59 +00:00
|
|
|
}
|
|
|
|
if (vp != NULL) {
|
2009-03-29 21:25:40 +00:00
|
|
|
TAILQ_INSERT_HEAD(&vp->v_cache_dst,
|
|
|
|
ncp, nc_dst);
|
2013-12-27 17:09:59 +00:00
|
|
|
} else {
|
2016-09-04 08:55:15 +00:00
|
|
|
cache_negative_insert(ncp);
|
2013-12-27 17:09:59 +00:00
|
|
|
}
|
2009-04-17 18:11:11 +00:00
|
|
|
ncp->nc_vp = vp;
|
|
|
|
CACHE_WUNLOCK();
|
|
|
|
return;
|
2009-03-29 21:25:40 +00:00
|
|
|
}
|
|
|
|
dvp->v_cache_dd = NULL;
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, enter, done, dvp, "..", vp);
|
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
|
|
|
|
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.
|
|
|
|
*/
|
2012-01-22 01:11:06 +00:00
|
|
|
ncp = cache_alloc(cnp->cn_namelen, tsp != NULL);
|
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;
|
2012-01-22 01:11:06 +00:00
|
|
|
if (tsp != NULL) {
|
|
|
|
n3 = (struct namecache_ts *)ncp;
|
|
|
|
n3->nc_time = *tsp;
|
|
|
|
n3->nc_ticks = ticks;
|
|
|
|
n3->nc_flag |= NCF_TS;
|
2012-03-03 01:06:54 +00:00
|
|
|
if (dtsp != NULL) {
|
|
|
|
n3->nc_dotdottime = *dtsp;
|
|
|
|
n3->nc_flag |= NCF_DTS;
|
|
|
|
}
|
2012-01-22 01:11:06 +00:00
|
|
|
}
|
2008-08-23 15:13:39 +00:00
|
|
|
len = ncp->nc_nlen = cnp->cn_namelen;
|
2016-01-21 01:05:41 +00:00
|
|
|
hash = cache_get_hash(cnp->cn_nameptr, len, dvp);
|
2012-01-22 01:11:06 +00:00
|
|
|
strlcpy(nc_get_name(ncp), cnp->cn_nameptr, len + 1);
|
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 &&
|
2012-01-22 01:11:06 +00:00
|
|
|
!bcmp(nc_get_name(n2), cnp->cn_nameptr, n2->nc_nlen)) {
|
|
|
|
if (tsp != NULL) {
|
2012-01-25 20:48:20 +00:00
|
|
|
KASSERT((n2->nc_flag & NCF_TS) != 0,
|
|
|
|
("no NCF_TS"));
|
2012-01-22 01:11:06 +00:00
|
|
|
n3 = (struct namecache_ts *)n2;
|
|
|
|
n3->nc_time =
|
|
|
|
((struct namecache_ts *)ncp)->nc_time;
|
|
|
|
n3->nc_ticks =
|
|
|
|
((struct namecache_ts *)ncp)->nc_ticks;
|
2012-03-03 01:06:54 +00:00
|
|
|
if (dtsp != NULL) {
|
|
|
|
n3->nc_dotdottime =
|
|
|
|
((struct namecache_ts *)ncp)->
|
|
|
|
nc_dotdottime;
|
|
|
|
n3->nc_flag |= NCF_DTS;
|
|
|
|
}
|
2012-01-22 01:11:06 +00:00
|
|
|
}
|
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) {
|
2016-01-07 02:04:17 +00:00
|
|
|
CACHE_WUNLOCK();
|
|
|
|
cache_free(ncp);
|
|
|
|
return;
|
2009-04-11 20:23:08 +00:00
|
|
|
}
|
|
|
|
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++;
|
2016-01-21 01:09:39 +00:00
|
|
|
if (vp != NULL) {
|
|
|
|
if (vp->v_type == VDIR) {
|
|
|
|
if (flag != NCF_ISDOTDOT) {
|
|
|
|
/*
|
|
|
|
* For this case, the cache entry maps both the
|
|
|
|
* directory name in it and the name ".." for the
|
|
|
|
* directory's parent.
|
|
|
|
*/
|
2016-09-04 16:52:14 +00:00
|
|
|
if ((ndd = vp->v_cache_dd) != NULL) {
|
|
|
|
if ((ndd->nc_flag & NCF_ISDOTDOT) != 0)
|
|
|
|
cache_zap(ndd);
|
|
|
|
else
|
|
|
|
ndd = NULL;
|
|
|
|
}
|
2016-01-21 01:09:39 +00:00
|
|
|
vp->v_cache_dd = ncp;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vp->v_cache_dd = NULL;
|
2009-03-29 21:25:40 +00:00
|
|
|
}
|
1997-08-31 07:32:39 +00:00
|
|
|
}
|
1997-03-08 15:22:14 +00:00
|
|
|
|
2009-03-29 21:25:40 +00:00
|
|
|
if (flag != NCF_ISDOTDOT) {
|
|
|
|
if (LIST_EMPTY(&dvp->v_cache_src)) {
|
2016-01-21 01:09:39 +00:00
|
|
|
vhold(dvp);
|
2009-03-29 21:25:40 +00:00
|
|
|
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
|
|
|
|
2016-09-10 16:29:53 +00:00
|
|
|
bucketlock = HASH2BUCKETLOCK(hash);
|
|
|
|
rw_wlock(bucketlock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert the new namecache entry into the appropriate chain
|
|
|
|
* within the cache entries table.
|
|
|
|
*/
|
|
|
|
LIST_INSERT_HEAD(ncpp, ncp, nc_hash);
|
|
|
|
|
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.
|
|
|
|
*/
|
2016-01-07 02:04:17 +00:00
|
|
|
if (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
|
|
|
TAILQ_INSERT_HEAD(&vp->v_cache_dst, ncp, nc_dst);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, enter, done, dvp, nc_get_name(ncp),
|
|
|
|
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
|
|
|
} else {
|
2016-01-21 01:09:39 +00:00
|
|
|
if (cnp->cn_flags & ISWHITEOUT)
|
|
|
|
ncp->nc_flag |= NCF_WHITE;
|
2016-09-04 08:55:15 +00:00
|
|
|
cache_negative_insert(ncp);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE2(vfs, namecache, enter_negative, done, dvp,
|
|
|
|
nc_get_name(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
|
|
|
}
|
2016-09-10 16:29:53 +00:00
|
|
|
rw_wunlock(bucketlock);
|
2016-09-04 08:55:15 +00:00
|
|
|
if (numneg * ncnegfactor > numcache)
|
2016-09-04 16:52:14 +00:00
|
|
|
nneg = cache_negative_zap_one();
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
2016-09-04 16:52:14 +00:00
|
|
|
cache_free(ndd);
|
|
|
|
cache_free(nneg);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2016-09-10 16:29:53 +00:00
|
|
|
static u_int
|
|
|
|
cache_roundup_2(u_int val)
|
|
|
|
{
|
|
|
|
u_int res;
|
|
|
|
|
|
|
|
for (res = 1; res <= val; res <<= 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-09-10 16:29:53 +00:00
|
|
|
u_int i;
|
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
|
|
|
|
2012-01-22 01:11:06 +00:00
|
|
|
cache_zone_small = uma_zcreate("S VFS Cache",
|
|
|
|
sizeof(struct namecache) + CACHE_PATH_CUTOFF + 1,
|
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
|
|
|
|
cache_zone_small_ts = uma_zcreate("STS VFS Cache",
|
|
|
|
sizeof(struct namecache_ts) + CACHE_PATH_CUTOFF + 1,
|
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
|
|
|
|
cache_zone_large = uma_zcreate("L VFS Cache",
|
2012-03-03 01:06:54 +00:00
|
|
|
sizeof(struct namecache) + NAME_MAX + 1,
|
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
|
|
|
|
cache_zone_large_ts = uma_zcreate("LTS VFS Cache",
|
2012-01-22 01:11:06 +00:00
|
|
|
sizeof(struct namecache_ts) + NAME_MAX + 1,
|
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
|
2003-06-13 08:46:13 +00:00
|
|
|
|
2000-12-06 07:09:08 +00:00
|
|
|
nchashtbl = hashinit(desiredvnodes * 2, M_VFSCACHE, &nchash);
|
2016-09-10 16:29:53 +00:00
|
|
|
numbucketlocks = cache_roundup_2(mp_ncpus * 16);
|
|
|
|
if (numbucketlocks > nchash)
|
|
|
|
numbucketlocks = nchash;
|
|
|
|
bucketlocks = malloc(sizeof(*bucketlocks) * numbucketlocks, M_VFSCACHE,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
for (i = 0; i < numbucketlocks; i++)
|
|
|
|
rw_init_flags(&bucketlocks[i], "ncbuc", RW_DUPOK);
|
2016-01-21 01:04:03 +00:00
|
|
|
|
|
|
|
numcalls = counter_u64_alloc(M_WAITOK);
|
|
|
|
dothits = counter_u64_alloc(M_WAITOK);
|
|
|
|
dotdothits = counter_u64_alloc(M_WAITOK);
|
|
|
|
numchecks = counter_u64_alloc(M_WAITOK);
|
|
|
|
nummiss = counter_u64_alloc(M_WAITOK);
|
|
|
|
nummisszap = counter_u64_alloc(M_WAITOK);
|
|
|
|
numposzaps = counter_u64_alloc(M_WAITOK);
|
|
|
|
numposhits = counter_u64_alloc(M_WAITOK);
|
|
|
|
numnegzaps = counter_u64_alloc(M_WAITOK);
|
|
|
|
numneghits = counter_u64_alloc(M_WAITOK);
|
|
|
|
numfullpathcalls = counter_u64_alloc(M_WAITOK);
|
|
|
|
numfullpathfail1 = counter_u64_alloc(M_WAITOK);
|
|
|
|
numfullpathfail2 = counter_u64_alloc(M_WAITOK);
|
|
|
|
numfullpathfail4 = counter_u64_alloc(M_WAITOK);
|
|
|
|
numfullpathfound = counter_u64_alloc(M_WAITOK);
|
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
|
|
|
|
2015-09-06 05:50:51 +00:00
|
|
|
void
|
|
|
|
cache_changesize(int newmaxvnodes)
|
|
|
|
{
|
|
|
|
struct nchashhead *new_nchashtbl, *old_nchashtbl;
|
|
|
|
u_long new_nchash, old_nchash;
|
|
|
|
struct namecache *ncp;
|
|
|
|
uint32_t hash;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
new_nchashtbl = hashinit(newmaxvnodes * 2, M_VFSCACHE, &new_nchash);
|
|
|
|
/* If same hash table size, nothing to do */
|
|
|
|
if (nchash == new_nchash) {
|
|
|
|
free(new_nchashtbl, M_VFSCACHE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Move everything from the old hash table to the new table.
|
|
|
|
* None of the namecache entries in the table can be removed
|
|
|
|
* because to do so, they have to be removed from the hash table.
|
|
|
|
*/
|
|
|
|
CACHE_WLOCK();
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_lock_all_buckets();
|
2015-09-06 05:50:51 +00:00
|
|
|
old_nchashtbl = nchashtbl;
|
|
|
|
old_nchash = nchash;
|
|
|
|
nchashtbl = new_nchashtbl;
|
|
|
|
nchash = new_nchash;
|
|
|
|
for (i = 0; i <= old_nchash; i++) {
|
|
|
|
while ((ncp = LIST_FIRST(&old_nchashtbl[i])) != NULL) {
|
2016-01-21 01:05:41 +00:00
|
|
|
hash = cache_get_hash(nc_get_name(ncp), ncp->nc_nlen,
|
|
|
|
ncp->nc_dvp);
|
2015-09-06 05:50:51 +00:00
|
|
|
LIST_REMOVE(ncp, nc_hash);
|
|
|
|
LIST_INSERT_HEAD(NCHHASH(hash), ncp, nc_hash);
|
|
|
|
}
|
|
|
|
}
|
2016-09-10 16:29:53 +00:00
|
|
|
cache_unlock_all_buckets();
|
2015-09-06 05:50:51 +00:00
|
|
|
CACHE_WUNLOCK();
|
|
|
|
free(old_nchashtbl, M_VFSCACHE);
|
|
|
|
}
|
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
|
2016-01-07 02:04:17 +00:00
|
|
|
cache_purge(struct vnode *vp)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_HEAD(, namecache) ncps;
|
|
|
|
struct namecache *ncp, *nnp;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2005-06-13 00:46:03 +00:00
|
|
|
CTR1(KTR_VFS, "cache_purge(%p)", vp);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE1(vfs, namecache, purge, done, vp);
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_INIT(&ncps);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WLOCK();
|
2016-09-04 16:52:14 +00:00
|
|
|
while (!LIST_EMPTY(&vp->v_cache_src)) {
|
|
|
|
ncp = LIST_FIRST(&vp->v_cache_src);
|
|
|
|
cache_zap(ncp);
|
|
|
|
TAILQ_INSERT_TAIL(&ncps, ncp, nc_dst);
|
|
|
|
}
|
|
|
|
while (!TAILQ_EMPTY(&vp->v_cache_dst)) {
|
|
|
|
ncp = TAILQ_FIRST(&vp->v_cache_dst);
|
|
|
|
cache_zap(ncp);
|
|
|
|
TAILQ_INSERT_TAIL(&ncps, ncp, nc_dst);
|
|
|
|
}
|
2009-03-29 21:25:40 +00:00
|
|
|
if (vp->v_cache_dd != NULL) {
|
2016-09-04 16:52:14 +00:00
|
|
|
ncp = vp->v_cache_dd;
|
|
|
|
KASSERT(ncp->nc_flag & NCF_ISDOTDOT,
|
2009-03-29 21:25:40 +00:00
|
|
|
("lost dotdot link"));
|
2016-09-04 16:52:14 +00:00
|
|
|
cache_zap(ncp);
|
|
|
|
TAILQ_INSERT_TAIL(&ncps, ncp, nc_dst);
|
2009-03-29 21:25:40 +00:00
|
|
|
}
|
|
|
|
KASSERT(vp->v_cache_dd == NULL, ("incomplete purge"));
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ncp, &ncps, nc_dst, nnp) {
|
|
|
|
cache_free(ncp);
|
|
|
|
}
|
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
|
2016-01-07 02:04:17 +00:00
|
|
|
cache_purge_negative(struct vnode *vp)
|
2009-02-19 22:28:48 +00:00
|
|
|
{
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_HEAD(, namecache) ncps;
|
|
|
|
struct namecache *ncp, *nnp;
|
2009-02-19 22:28:48 +00:00
|
|
|
|
|
|
|
CTR1(KTR_VFS, "cache_purge_negative(%p)", vp);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE1(vfs, namecache, purge_negative, done, vp);
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_INIT(&ncps);
|
2009-02-19 22:28:48 +00:00
|
|
|
CACHE_WLOCK();
|
2016-09-04 16:52:14 +00:00
|
|
|
LIST_FOREACH_SAFE(ncp, &vp->v_cache_src, nc_src, nnp) {
|
|
|
|
if (ncp->nc_vp != NULL)
|
|
|
|
continue;
|
|
|
|
cache_zap(ncp);
|
|
|
|
TAILQ_INSERT_TAIL(&ncps, ncp, nc_dst);
|
2009-02-19 22:28:48 +00:00
|
|
|
}
|
|
|
|
CACHE_WUNLOCK();
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ncp, &ncps, nc_dst, nnp) {
|
|
|
|
cache_free(ncp);
|
|
|
|
}
|
2009-02-19 22:28:48 +00:00
|
|
|
}
|
|
|
|
|
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
|
2016-01-07 02:04:17 +00:00
|
|
|
cache_purgevfs(struct mount *mp)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_HEAD(, namecache) ncps;
|
2016-09-10 16:29:53 +00:00
|
|
|
struct rwlock *bucketlock;
|
|
|
|
struct nchashhead *bucket;
|
1997-02-10 02:22:35 +00:00
|
|
|
struct namecache *ncp, *nnp;
|
2016-09-10 16:29:53 +00:00
|
|
|
u_long i, j, n_nchash;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-03-09 20:23:45 +00:00
|
|
|
/* Scan hash tables for applicable entries */
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE1(vfs, namecache, purgevfs, done, mp);
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_INIT(&ncps);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WLOCK();
|
2016-09-10 16:29:53 +00:00
|
|
|
n_nchash = nchash + 1;
|
|
|
|
for (i = 0; i < numbucketlocks; i++) {
|
|
|
|
bucketlock = (struct rwlock *)&bucketlocks[i];
|
|
|
|
rw_wlock(bucketlock);
|
|
|
|
for (j = i; j < n_nchash; j += numbucketlocks) {
|
|
|
|
bucket = &nchashtbl[j];
|
|
|
|
LIST_FOREACH_SAFE(ncp, bucket, nc_hash, nnp) {
|
|
|
|
cache_assert_bucket_locked(ncp, RA_WLOCKED);
|
|
|
|
if (ncp->nc_dvp->v_mount != mp)
|
|
|
|
continue;
|
|
|
|
cache_zap_locked(ncp);
|
|
|
|
TAILQ_INSERT_HEAD(&ncps, ncp, nc_dst);
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2016-09-10 16:29:53 +00:00
|
|
|
rw_wunlock(bucketlock);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_WUNLOCK();
|
2016-09-04 16:52:14 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ncp, &ncps, nc_dst, nnp) {
|
|
|
|
cache_free(ncp);
|
|
|
|
}
|
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
|
2016-01-07 02:04:17 +00:00
|
|
|
vfs_cache_lookup(struct vop_lookup_args *ap)
|
1997-08-26 07:32:51 +00:00
|
|
|
{
|
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);
|
|
|
|
|
2012-02-06 17:00:28 +00:00
|
|
|
error = cache_lookup(dvp, vpp, cnp, NULL, NULL);
|
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
|
|
|
|
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
|
2016-01-07 02:04:17 +00:00
|
|
|
sys___getcwd(struct thread *td, struct __getcwd_args *uap)
|
1999-10-03 12:18:29 +00:00
|
|
|
{
|
2003-03-17 12:21:08 +00:00
|
|
|
|
2015-04-21 13:55:24 +00:00
|
|
|
return (kern___getcwd(td, uap->buf, UIO_USERSPACE, uap->buflen,
|
|
|
|
MAXPATHLEN));
|
2003-03-17 12:21:08 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 22:40:30 +00:00
|
|
|
int
|
2015-04-21 13:55:24 +00:00
|
|
|
kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg, u_int buflen,
|
|
|
|
u_int path_max)
|
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;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
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);
|
2015-04-21 13:55:24 +00:00
|
|
|
if (buflen > path_max)
|
|
|
|
buflen = path_max;
|
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);
|
|
|
|
vrele(rdir);
|
|
|
|
vrele(cdir);
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int disablefullpath;
|
2002-03-05 15:38:49 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, disablefullpath, CTLFLAG_RW, &disablefullpath, 0,
|
2010-11-14 16:10:15 +00:00
|
|
|
"Disable the vn_fullpath function");
|
2000-04-26 11:57:45 +00:00
|
|
|
|
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;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
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);
|
|
|
|
vrele(rdir);
|
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
|
2009-06-21 19:21:01 +00:00
|
|
|
vn_vptocnp(struct vnode **vp, struct ucred *cred, char *buf, u_int *buflen)
|
2009-05-31 14:57:43 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
CACHE_RLOCK();
|
2009-06-21 19:21:01 +00:00
|
|
|
error = vn_vptocnp_locked(vp, cred, buf, buflen);
|
2011-11-19 07:50:49 +00:00
|
|
|
if (error == 0)
|
2009-05-31 14:57:43 +00:00
|
|
|
CACHE_RUNLOCK();
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-12-12 00:57:38 +00:00
|
|
|
static int
|
2009-06-21 19:21:01 +00:00
|
|
|
vn_vptocnp_locked(struct vnode **vp, struct ucred *cred, 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;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
2008-12-12 00:57:38 +00:00
|
|
|
|
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();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(*vp);
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numfullpathfail4, 1);
|
2009-05-31 14:57:43 +00:00
|
|
|
error = ENOMEM;
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return, error,
|
|
|
|
vp, NULL);
|
2009-05-31 14:57:43 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
*buflen -= ncp->nc_nlen;
|
2012-01-22 01:11:06 +00:00
|
|
|
memcpy(buf + *buflen, nc_get_name(ncp), ncp->nc_nlen);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, hit, ncp->nc_dvp,
|
|
|
|
nc_get_name(ncp), vp);
|
2011-11-19 07:50:49 +00:00
|
|
|
dvp = *vp;
|
2009-05-31 14:57:43 +00:00
|
|
|
*vp = ncp->nc_dvp;
|
2011-11-19 07:50:49 +00:00
|
|
|
vref(*vp);
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
vrele(dvp);
|
|
|
|
CACHE_RLOCK();
|
2009-05-31 14:57:43 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE1(vfs, namecache, fullpath, miss, vp);
|
2009-05-31 14:57:43 +00:00
|
|
|
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2008-12-12 00:57:38 +00:00
|
|
|
vn_lock(*vp, LK_SHARED | LK_RETRY);
|
2009-06-21 19:21:01 +00:00
|
|
|
error = VOP_VPTOCNP(*vp, &dvp, cred, buf, buflen);
|
2011-11-19 07:50:49 +00:00
|
|
|
vput(*vp);
|
2008-12-12 00:57:38 +00:00
|
|
|
if (error) {
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numfullpathfail2, 1);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return, error, vp, NULL);
|
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();
|
2011-11-19 07:50:49 +00:00
|
|
|
if (dvp->v_iflag & VI_DOOMED) {
|
2008-12-12 00:57:38 +00:00
|
|
|
/* forced unmount */
|
2009-04-04 17:48:38 +00:00
|
|
|
CACHE_RUNLOCK();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(dvp);
|
2009-05-31 14:57:43 +00:00
|
|
|
error = ENOENT;
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return, error, vp, NULL);
|
2009-05-31 14:57:43 +00:00
|
|
|
return (error);
|
2008-12-12 00:57:38 +00:00
|
|
|
}
|
2011-11-19 07:50:49 +00:00
|
|
|
/*
|
|
|
|
* *vp has its use count incremented still.
|
|
|
|
*/
|
2008-12-12 00:57:38 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-10-22 17:50:54 +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
|
2011-11-19 07:50:49 +00:00
|
|
|
struct vnode *vp1;
|
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;
|
|
|
|
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE1(vfs, namecache, fullpath, entry, vp);
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numfullpathcalls, 1);
|
2011-11-19 07:50:49 +00:00
|
|
|
vref(vp);
|
2009-05-31 14:57:43 +00:00
|
|
|
CACHE_RLOCK();
|
2005-03-30 02:59:32 +00:00
|
|
|
if (vp->v_type != VDIR) {
|
2009-06-21 19:21:01 +00:00
|
|
|
error = vn_vptocnp_locked(&vp, td->td_ucred, buf, &buflen);
|
2009-05-31 14:57:43 +00:00
|
|
|
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();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(vp);
|
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();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(vp);
|
2009-03-24 18:16:42 +00:00
|
|
|
error = ENOENT;
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return,
|
|
|
|
error, vp, NULL);
|
2005-03-30 02:59:32 +00:00
|
|
|
break;
|
2000-04-26 11:57:45 +00:00
|
|
|
}
|
2011-11-19 07:50:49 +00:00
|
|
|
vp1 = vp->v_mount->mnt_vnodecovered;
|
|
|
|
vref(vp1);
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
vrele(vp);
|
|
|
|
vp = vp1;
|
|
|
|
CACHE_RLOCK();
|
2000-04-26 11:57:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-12-12 00:57:38 +00:00
|
|
|
if (vp->v_type != VDIR) {
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(vp);
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numfullpathfail1, 1);
|
2005-03-30 02:59:32 +00:00
|
|
|
error = ENOTDIR;
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return,
|
|
|
|
error, vp, NULL);
|
2005-03-30 02:59:32 +00:00
|
|
|
break;
|
2000-04-26 11:57:45 +00:00
|
|
|
}
|
2009-06-21 19:21:01 +00:00
|
|
|
error = vn_vptocnp_locked(&vp, td->td_ucred, buf, &buflen);
|
2009-05-31 14:57:43 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (buflen == 0) {
|
2009-06-05 16:44:42 +00:00
|
|
|
CACHE_RUNLOCK();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(vp);
|
2005-03-30 02:59:32 +00:00
|
|
|
error = ENOMEM;
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return, error,
|
|
|
|
startvp, NULL);
|
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();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(vp);
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numfullpathfail4, 1);
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return, ENOMEM,
|
|
|
|
startvp, NULL);
|
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
|
|
|
}
|
2016-01-21 01:04:03 +00:00
|
|
|
counter_u64_add(numfullpathfound, 1);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2011-11-19 07:50:49 +00:00
|
|
|
vrele(vp);
|
2005-03-30 02:59:32 +00:00
|
|
|
|
2015-09-28 12:14:16 +00:00
|
|
|
SDT_PROBE3(vfs, namecache, fullpath, return, 0, startvp, buf + buflen);
|
2009-05-31 14:57:43 +00:00
|
|
|
*retbuf = buf + buflen;
|
2000-04-26 11:57:45 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2008-03-31 11:53:03 +00:00
|
|
|
|
2013-03-20 17:57:00 +00:00
|
|
|
struct vnode *
|
|
|
|
vn_dir_dd_ino(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct namecache *ncp;
|
|
|
|
struct vnode *ddvp;
|
|
|
|
|
|
|
|
ASSERT_VOP_LOCKED(vp, "vn_dir_dd_ino");
|
|
|
|
CACHE_RLOCK();
|
|
|
|
TAILQ_FOREACH(ncp, &(vp->v_cache_dst), nc_dst) {
|
|
|
|
if ((ncp->nc_flag & NCF_ISDOTDOT) != 0)
|
|
|
|
continue;
|
|
|
|
ddvp = ncp->nc_dvp;
|
2015-07-16 13:57:05 +00:00
|
|
|
vhold(ddvp);
|
2013-03-20 17:57:00 +00:00
|
|
|
CACHE_RUNLOCK();
|
2015-07-16 13:57:05 +00:00
|
|
|
if (vget(ddvp, LK_SHARED | LK_NOWAIT | LK_VNHELD, curthread))
|
2013-03-20 17:57:00 +00:00
|
|
|
return (NULL);
|
|
|
|
return (ddvp);
|
|
|
|
}
|
|
|
|
CACHE_RUNLOCK();
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
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);
|
2012-01-22 01:11:06 +00:00
|
|
|
memcpy(buf, nc_get_name(ncp), l);
|
2009-01-28 19:05:18 +00:00
|
|
|
CACHE_RUNLOCK();
|
2008-03-31 11:53:03 +00:00
|
|
|
buf[l] = '\0';
|
|
|
|
return (0);
|
|
|
|
}
|
2012-01-15 12:08:20 +00:00
|
|
|
|
2012-01-20 20:02:01 +00:00
|
|
|
/* ABI compat shims for old kernel modules. */
|
|
|
|
#undef cache_enter
|
|
|
|
|
|
|
|
void cache_enter(struct vnode *dvp, struct vnode *vp,
|
|
|
|
struct componentname *cnp);
|
|
|
|
|
|
|
|
void
|
|
|
|
cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
|
|
|
|
{
|
|
|
|
|
2012-03-03 01:06:54 +00:00
|
|
|
cache_enter_time(dvp, vp, cnp, NULL, NULL);
|
2012-01-20 20:02:01 +00:00
|
|
|
}
|
|
|
|
|
2012-01-15 12:08:20 +00:00
|
|
|
/*
|
|
|
|
* This function updates path string to vnode's full global path
|
|
|
|
* and checks the size of the new path string against the pathlen argument.
|
|
|
|
*
|
2014-08-03 07:59:19 +00:00
|
|
|
* Requires a locked, referenced vnode.
|
2012-01-15 12:08:20 +00:00
|
|
|
* Vnode is re-locked on success or ENODEV, otherwise unlocked.
|
|
|
|
*
|
|
|
|
* If sysctl debug.disablefullpath is set, ENODEV is returned,
|
|
|
|
* vnode is left locked and path remain untouched.
|
|
|
|
*
|
|
|
|
* If vp is a directory, the call to vn_fullpath_global() always succeeds
|
2012-01-15 18:08:15 +00:00
|
|
|
* because it falls back to the ".." lookup if the namecache lookup fails.
|
2012-01-15 12:08:20 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
vn_path_to_global_path(struct thread *td, struct vnode *vp, char *path,
|
|
|
|
u_int pathlen)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
struct vnode *vp1;
|
|
|
|
char *rpath, *fbuf;
|
2012-10-22 17:50:54 +00:00
|
|
|
int error;
|
2012-01-15 12:08:20 +00:00
|
|
|
|
|
|
|
ASSERT_VOP_ELOCKED(vp, __func__);
|
|
|
|
|
|
|
|
/* Return ENODEV if sysctl debug.disablefullpath==1 */
|
|
|
|
if (disablefullpath)
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
/* Construct global filesystem path from vp. */
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
error = vn_fullpath_global(td, vp, &rpath, &fbuf);
|
|
|
|
|
|
|
|
if (error != 0) {
|
|
|
|
vrele(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(rpath) >= pathlen) {
|
|
|
|
vrele(vp);
|
|
|
|
error = ENAMETOOLONG;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-lookup the vnode by path to detect a possible rename.
|
|
|
|
* As a side effect, the vnode is relocked.
|
|
|
|
* If vnode was renamed, return ENOENT.
|
|
|
|
*/
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1,
|
2012-01-15 12:08:20 +00:00
|
|
|
UIO_SYSSPACE, path, td);
|
|
|
|
error = namei(&nd);
|
|
|
|
if (error != 0) {
|
|
|
|
vrele(vp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
|
|
|
vp1 = nd.ni_vp;
|
|
|
|
vrele(vp);
|
|
|
|
if (vp1 == vp)
|
|
|
|
strcpy(path, rpath);
|
|
|
|
else {
|
|
|
|
vput(vp1);
|
|
|
|
error = ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(fbuf, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|