LOCK_PROFILING(9)
π LOCK_PROFILING β kernel lock profiling support
okay bestie, welcome to LOCK_PROFILING(9), a kernel developer's manual page, and lemme tell you, this one is so niche and so useful. it's the vibe check for your locks. π₯
β¨ SYNOPSIS β¨
options LOCK_PROFILING
that's it. one line. iconic behavior honestly. π
π¦ DESCRIPTION π¦
so the LOCK_PROFILING kernel option adds support for measuring and reporting lock use and contention statistics. yes, it's giving "your locks are being watched and the receipts are being kept." π
these stats get collated by βacquisition pointβ. and what is an acquisition point, you ask? it's a distinct place in the kernel source code β identified by source file name and line number β where a lock is acquired. so like, not "the mutex," but "the exact line where somebody grabbed the mutex." very specific. very main character.
for each acquisition point, these stats pile up:
- The longest time the lock was ever continuously held after being acquired at this point. π
- The total time the lock was held after being acquired at this point.
- The total time that threads have spent waiting to acquire the lock. π
- The total number of non-recursive acquisitions.
- The total number of times the lock was already held by another thread when this point was reached, requiring a spin or a sleep.
- The total number of times another thread tried to acquire the lock while it was held after having been acquired at this point.
and in addition, the average hold time and average wait time are derived from the total hold time and total wait time respectively, and the number of acquisitions. math! β¨
the LOCK_PROFILING kernel option also adds the following sysctl(8) variables so you can control and monitor the profiling code. here's the whole roster, no skips:
debug.lock.prof.enableβ Enable or disable the lock profiling code. This defaults to0(off). π«debug.lock.prof.resetβ Reset the current lock profiling buffers. fresh start bestie π§debug.lock.prof.statsβ The actual profiling statistics in plain text. the columns are as follows, from left to right:maxβ The longest continuous hold time in microseconds.wait_maxβ The longest continuous wait time in microseconds.totalβ The total (accumulated) hold time in microseconds.wait_totalβ The total (accumulated) wait time in microseconds.countβ The total number of acquisitions.avgβ The average hold time in microseconds, derived from the total hold time and the number of acquisitions.wait_avgβ The average wait time in microseconds, derived from the total wait time and the number of acquisitions.cnt_holdβ The number of times the lock was held and another thread attempted to acquire the lock.cnt_lockβ The number of times the lock was already held when this point was reached.nameβ The name of the acquisition point, derived from the source file name and line number, followed by the name of the lock in parentheses.
debug.lock.prof.rejectedβ The number of acquisition points that were ignored after the table filled up. π¬ yeah. the table can fill up.debug.lock.prof.skipspinβ Disable or enable the lock profiling code for the spin locks. This defaults to0(do profiling for the spin locks). πdebug.lock.prof.skipcountβ Do sampling approximately every N lock acquisitions.
π SEE ALSO π
π HISTORY π
- Mutex profiling support appeared in FreeBSD 5.0.
- Generalized lock profiling support appeared in FreeBSD 7.0.
glow up timeline fr fr β¨
π«Ά AUTHORS π«Ά
The MUTEX_PROFILING code was written by:
- Eivind Eklund
<eivind@FreeBSD.org> - Dag-Erling SmΓΈrgrav
<des@FreeBSD.org> - Robert Watson
<rwatson@FreeBSD.org>
The LOCK_PROFILING code was written by Kip Macy <kmacy@FreeBSD.org>.
This manual page was written by Dag-Erling SmΓΈrgrav <des@FreeBSD.org>.
absolute legends, all of them π
β οΈ NOTES β οΈ
bestie. please read these. i'm begging. π
- The
LOCK_PROFILINGoption increases the size ofstruct lock_object, so a kernel built with that option will not work with modules built without it. no cap. it just won't. π - The
LOCK_PROFILINGoption also prevents inlining of the mutex code, which can result in a fairly severe performance penalty. This is, however, not always the case.LOCK_PROFILINGcan introduce a substantial performance overhead that is easily monitorable using other profiling tools, so combining profiling tools withLOCK_PROFILINGis not recommended. π© - Measurements are made and stored in nanoseconds using
nanotime(9), (on architectures without a synchronized TSC) but are presented in microseconds. This should still be sufficient for the locks one would be most interested in profiling (those that are held long and/or acquired often). β LOCK_PROFILINGshould generally not be used in combination with other debugging options, as the results may be strongly affected by interactions between the features. In particular:LOCK_PROFILINGwill report higher than normaluma(9)lock contention when run withINVARIANTSdue to extra locking that occurs whenINVARIANTSis present. π- Likewise, using it in combination with
WITNESSwill lead to much higher lock hold times and contention in profiling output. ππ
and that's the whole page, bestie!! π this one came from the Debian build of the page, dated March 7, 2012. go forth and profile your locks responsibly, i love you, bye πβ¨π¦
π¦ 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) 2004 Dag-Erling CoΓ―dan SmΓΈrgrav
- Copyright (c) 2005 Robert N. M. Watson
- Copyright (c) 2006 Kip Macy
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms