History log of /freebsd-current/sys/kern/vfs_hash.c
Revision Date Author Comments
# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# f19063ab 18-Aug-2021 Konstantin Belousov <kib@FreeBSD.org>

vfs_hash_rehash(): require the vnode to be exclusively locked

Rehash updates v_hash. Also, rehash moves the vnode to different hash
bucket, which should be noticed in vfs_hash_get() after sleeping for
the vnode lock.

Reviewed by: mckusick, rmacklem
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D31464


# 7c1e4aab 17-Aug-2021 Konstantin Belousov <kib@FreeBSD.org>

vfs_hash_insert: ensure that predicate is true

After vnode lock, recheck v_hash. When vfs_hash_insert() is used with
a predicate, recheck it after the selected vnode is locked. Since
vfs_hash_lock is dropped, vnode could be rehashed during the sleep for
the vnode lock, which could go unnoticed there.

Reported and tested by: pho
Reviewed by: mckusick, rmacklem
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D31464


# a0a36d48 04-Sep-2020 Chuck Silvers <chs@FreeBSD.org>

vfs: avoid exposing partially constructed vnodes

If multiple threads race calling vfs_hash_insert() while creating vnodes
with the same identity, all of the vnodes which lose the race must be
destroyed before any other thread can see them. Previously this was
accomplished by the vput() in vfs_hash_insert() resulting in the vnode's
VOP_INACTIVE() method calling vgone() before the vnode lock was unlocked,
but at some point changes to the the vnode refcount/inactive logic have caused
that to no longer work, leading to crashes, so instead vfs_hash_insert()
must call vgone() itself before calling vput() on vnodes which lose the race.

Reviewed by: mjg, kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D26291


# bb62c418 05-Aug-2020 Mateusz Guzik <mjg@FreeBSD.org>

vfs hash: annotate the lock with __exclusive_cache_line

Note the code does not scale in the current form.


# 422f38d8 10-Jul-2020 Mateusz Guzik <mjg@FreeBSD.org>

vfs: fix trivial whitespace issues which don't interefere with blame

.. even without the -w switch


# 69283067 11-Jan-2020 Mateusz Guzik <mjg@FreeBSD.org>

vfs: incomplete pass at converting more ints to u_long

Most notably numvnodes and freevnodes were u_long, but parameters used to
govern them remained as ints.


# e3c3248c 03-Sep-2019 Mateusz Guzik <mjg@FreeBSD.org>

vfs: implement usecount implying holdcnt

vnodes have 2 reference counts - holdcnt to keep the vnode itself from getting
freed and usecount to denote it is actively used.

Previously all operations bumping usecount would also bump holdcnt, which is
not necessary. We can detect if usecount is already > 1 (in which case holdcnt
is also > 1) and utilize it to avoid bumping holdcnt on our own. This saves
on atomic ops.

Reviewed by: kib
Tested by: pho (previous version)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21471


# 8a36da99 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/kern: adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 54a33d2f 11-May-2016 Konstantin Belousov <kib@FreeBSD.org>

Add vfs_hash_ref(9) function, which finds a vnode by the hash value
and returns it referenced.

The function is similar to vfs_hash_get(9), but unlike the later,
returned vnode is not locked. This operation cannot be requested with
the vget(9) flags.

Reviewed and tested by: rmacklem
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# cd85d599 11-May-2016 Konstantin Belousov <kib@FreeBSD.org>

Style: wrap long lines.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 17518b1a 05-Sep-2015 Kirk McKusick <mckusick@FreeBSD.org>

Track changes to kern.maxvnodes and appropriately increase or decrease
the size of the name cache hash table (mapping file names to vnodes)
and the vnode hash table (mapping mount point and inode number to vnode).
An appropriate locking strategy is the key to changing hash table sizes
while they are in active use.

Reviewed by: kib
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D2265
MFC after: 2 weeks


# 752fc07d 16-Jul-2015 Mateusz Guzik <mjg@FreeBSD.org>

vfs: implement v_holdcnt/v_usecount manipulation using atomic ops

Transitions 0->1 and 1->0 (which decide e.g. on putting the vnode on the free
list) of either counter are still guarded with vnode interlock.

Reviewed by: kib (earlier version)
Tested by: pho


# af77c1a6 30-Dec-2014 Mateusz Guzik <mjg@FreeBSD.org>

Convert vfs hash lock from a mutex to an rwlock.


# f6af8e37 13-Jan-2013 Konstantin Belousov <kib@FreeBSD.org>

Add exported vfs_hash_index() function, which calculates the canonical
pre-masked hash for the given vnode. The function assumes that
vp->v_hash is initialized by the filesystem vnode instantiation
function. At the moment, it is only done if filesystem uses
vfs_hash_insert().

Reviewed by: peter
Tested by: peter, pho (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 5 days


# 7b982bc8 13-Jan-2013 Konstantin Belousov <kib@FreeBSD.org>

Rename vfs_hash_index() to vfs_hash_bucket().

Reviewed by: peter
Tested by: peter, pho
Sponsored by: The FreeBSD Foundation
MFC after: 5 days


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 237fdd78 16-Mar-2008 Robert Watson <rwatson@FreeBSD.org>

In keeping with style(9)'s recommendations on macros, use a ';'
after each SYSINIT() macro invocation. This makes a number of
lightweight C parsers much happier with the FreeBSD kernel
source, including cflow's prcc and lxr.

MFC after: 1 month
Discussed with: imp, rink


# 61b9d89f 12-Mar-2007 Tor Egge <tegge@FreeBSD.org>

Make insmntque() externally visibile and allow it to fail (e.g. during
late stages of unmount). On failure, the vnode is recycled.

Add insmntque1(), to allow for file system specific cleanup when
recycling vnode on failure.

Change getnewvnode() to no longer call insmntque(). Previously,
embryonic vnodes were put onto the list of vnode belonging to a file
system, which is unsafe for a file system marked MPSAFE.

Change vfs_hash_insert() to no longer lock the vnode. The caller now
has that responsibility.

Change most file systems to lock the vnode and call insmntque() or
insmntque1() after a new vnode has been sufficiently setup. Handle
failed insmntque*() calls by propagating errors to callers, possibly
after some file system specific cleanup.

Approved by: re (kensmith)
Reviewed by: kib
In collaboration with: kib


# 4207c279 18-Apr-2006 Xin LI <delphij@FreeBSD.org>

In vfs_hash_get(): mount point should never be changed
so explicitly constify the mp parameter.

Reviewed by: phk


# 5bb84bc8 31-Oct-2005 Robert Watson <rwatson@FreeBSD.org>

Normalize a significant number of kernel malloc type names:

- Prefer '_' to ' ', as it results in more easily parsed results in
memory monitoring tools such as vmstat.

- Remove punctuation that is incompatible with using memory type names
as file names, such as '/' characters.

- Disambiguate some collisions by adding subsystem prefixes to some
memory types.

- Generally prefer lower case to upper case.

- If the same type is defined in multiple architecture directories,
attempt to use the same name in additional cases.

Not all instances were caught in this change, so more work is required to
finish this conversion. Similar changes are required for UMA zone names.


# 6ff5e2db 11-Sep-2005 Tor Egge <tegge@FreeBSD.org>

Don't retry when vget() returns ENOENT in the nonblocking case due to the
vnode being doomed. It causes a livelock.


# 2e0b9b22 07-Apr-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Fix bug in vfs_hash_rehash(): use correct bucket. This only affected
msdosfs which is broken in other ways too.


# 5d14d299 23-Mar-2005 Jeff Roberson <jeff@FreeBSD.org>

- Grab the lock type that the caller requests in vfs_hash_insert().

Sponsored by: Isilon Systems, Inc.


# a1e1d551 17-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Fix a bad copy&paste mistake I made.

Spotted by: truckman


# 51f5ce0c 16-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Add two arguments to the vfs_hash() KPI so that filesystems which do
not have unique hashes (NFS) can also use it.


# 78bb3c21 16-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Add mnt_hashseed to struct mount and initialize it witn PRNG bits, use
it to get better hashing in vfs_hash.

In case of an insert collision in vfs_hash_insert(), put the loosing vnode
on a special list so that vfs_hash_remove() can just assume that it is on
a list.

Drop the VI_HASHED flag.


# 45c26fa2 15-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Improve the vfs_hash() API: vput() the unneeded vnode centrally to
avoid replicating the vput in all the filesystems.


# e82ef95c 15-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Simplify the vfs_hash calling convention.


# ee148e26 14-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Cleanup accidentally include #if 0 section.


# 6c325a2a 14-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Currently (almost) all filesystems maintain a local inode hash table
to get from (mount + inode) to vnode. These tables are mostly
copy&pasted from UFS, sized based on desiredvnodes and therefore
quite large (128K-512K). Several filesystems are buggy enough that
they allocate the hash table even before they know if they will
ever be used or not.

Add "vfs_hash", a system wide hash table, which will replace all
the per-filesystem hash-tables.

The fields we add to struct vnode will more or less be saved in
the respective filesystems inodes.

Having one central implementation will save code and will allow us
to justify the complexity of code to dynamically (re)size the hash
at a later point.