WITNESS(4)
πΈ witness(4) β lock validation facility πΈ
okay so bestie, this is witness(4) from the Kernel Interfaces Manual, and it is literally the vibe-checker for your kernel locks. no cap. let's get into it π
β¨ NAME β¨
witness β lock validation facility π«Ά
π SYNOPSIS π
options WITNESS
options WITNESS_COUNT
options WITNESS_KDB
options WITNESS_NO_VNODE
options WITNESS_SKIPSPIN
π DESCRIPTION π
so the witness module is out here keeping receipts π. it keeps track of the locks that each thread acquires and releases, and it also keeps track of the order in which locks are acquired with respect to each other. two lists, main character energy π
every single time a lock is acquired, witness uses these two lists to verify that the lock is not being acquired in the wrong order. and if a lock order violation is detected?? π it outputs a message to the kernel console or log, detailing the locks involved and the locations in question. iconic detective work fr fr π
witness can also be configured to drop into the kernel debugger when an order violation occurs. dramatic? yes. useful? also yes β¨
the witness code also checks various other conditions, such as:
- verifying that one does not recurse on a non-recursive lock
- verifying that one does not attempt an upgrade on a shared lock held by another thread
if any of these checks fail, then the kernel will panic π. not a drill.
The WITNESS_COUNT kernel option controls the maximum number of witness entries that are tracked in the kernel. the maximum number of entries can be queried via the debug.witness.count sysctl π¦. it can also be set from the loader(8) via the debug.witness.count environment variable.
The WITNESS_NO_VNODE kernel option tells witness to ignore locking issues between vnode(9) objects π. yes bestie, it's giving "i simply will not be looking at that".
the flag that controls whether or not the kernel debugger is entered when a lock order violation is detected can be set in a variety of ways. by default, the flag is off, but if the WITNESS_KDB kernel option is specified, then the flag will default to on β¨. it can also be set from the loader(8) via the debug.witness.kdb environment variable, or after the kernel has booted via the debug.witness.kdb sysctl.
- if the flag is set to
0, then the debugger will not be entered - if the flag is non-zero, then the debugger will be entered
the witness code can also be configured to skip all checks on spin mutexes π. by default, this flag defaults to off, but it can be turned on by specifying the WITNESS_SKIPSPIN kernel option. the flag can also be set via the loader(8) environment variable debug.witness.skipspin. if the variable is set to a non-zero value, then spin mutexes are skipped. once the kernel has booted, the status of this flag can be examined but not set via the read-only sysctl debug.witness.skipspin π.
the sysctl debug.witness.watch specifies the level of witness involvement in the system. here's the breakdown, bestie:
- a value of
1specifies thatwitnessis enabled β - a value of
0specifies thatwitnessis disabled, but that can be enabled again. this will maintain a small amount of overhead in the system π« - a value of
-1specifies thatwitnessis disabled permanently and cannot be enabled again π
the sysctl debug.witness.watch can be set via loader(8).
the sysctl debug.witness.output_channel specifies the output channel used to display warnings emitted by witness π’. the possible values are:
consoleβ indicating that warnings are to be printed to the system consolelogβ indicating that warnings are to be logged vialog(9)none
this sysctl can be set via loader(8).
π§ the extra ddb(4) commands π§
the witness code also provides three extra ddb(4) commands if both witness and ddb(4) are compiled into the kernel π:
show locks [thread]
outputs the list of locks held by a thread to the kernel console, along with the filename and line number at which each lock was last acquired by the thread. the optional thread argument may be either a TID, PID, or pointer to a thread structure π§΅. if thread is not specified, then the locks held by the current thread are displayed.
show all locks
outputs the list of locks held by all threads in the system to the kernel console π.
show witness
dump the current order list to the kernel console. the code first displays the lock order tree for all of the sleep locks π΄, then it displays the lock order tree for all of the spin locks π, and finally it displays a list of locks that have not yet been acquired π».
π₯ SEE ALSO π₯
ddb(4), loader(8), sysctl(8), mutex(9)
π HISTORY π
the witness code first appeared in BSD/OS 5.0 and was imported from there into FreeBSD 5.0 π. a true icon with a glow-up arc.
and that's the whole page bestie, no cap, every last detail preserved πβ¨
this was the WITNESS(4) page from the Debian crew, dated November 18, 2015 π¦. slay, go check your lock order, and stay hydrated ππ
πΈ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms