$ uname -a A_BLOG_ABOUT_UNIX_TOOLS_AND_THE_BEAUTY_OF_SIMPLE_SYSTEMS
SYS.YEAR  2026
← Back to articles
2026-12-01ARTICLE

Fdesc Hang Paper

How a FreeBSD fdescfs vnode self-lock can stall the system

Abstract

A worker in the disk-usage program dust continued consuming kernel CPU after process exit began. We used a kernel trace, repeated stack samples, and a live dump from FreeBSD 15.1-RELEASE-p1 to determine why a descriptor lookup reached final file close. The lookup acquired an exclusive lock on a ZFS directory vnode, released the last reference to the file, and entered a close path that requested the same lock. The dump identified the worker as the lock owner. A disposable stock 15.1-RELEASE-p6 guest reproduced the lookup-to-close stack and retained the process after SIGKILL. A separate p1 dump showed an unrelated process blocked on the same lock. The investigator reports a system-wide hang when the locked directory was critical to OS operation. The available captures establish the mechanism by which the stall spreads across processes. Patch validation remains open.

1. Introduction

A thread waiting for a process to exit can stay blocked even when the thread preventing exit is still running. In the dust incident, repeated samples put the worker in _vn_lock_fallback() and another thread in the process-exit path. The worker accumulated approximately 4.055 seconds of system CPU between samples roughly four seconds apart. The stack gave us the lock request. Determining why it could never finish required identifying the object and the owner. The scope of the resulting stall depends on which processes need that object. [1]

A file descriptor is a slot in a process's descriptor table. Its kernel file object can hold a vnode, the kernel representation of a filesystem object. FreeBSD's fdescfs exposes descriptors as names. With the nodup mount option, a lookup can resolve to the underlying vnode. The lookup temporarily holds a file reference of its own. Releasing that reference can execute the file's close operation synchronously if it is the last one. That coupling between lookup and close is the subject of this case study. [2]

2. Evidence and environments

Table 1. Build identities and the evidence obtained from each environment.

Environment FreeBSD/amd64 build Evidence
Incident system 15.1-RELEASE-p1, releng/15.1-n283582-0f691888dc56 Repeated stacks, DTrace events, and live-dump inspection
Offline bhyve guest 15.1-RELEASE-p6, releng/15.1-n283643-95719d8a895b GENERIC Console transcript, kernel stacks, resource accounting, signal outcome, and JSON run metadata

The guest ran with one vCPU, 1,024 MiB of RAM, and a private 512 MiB scratch disk for the ZFS pool. The FreeBSD Test Framework (FTF) staged a host-built static payload into the compiler-free guest and captured the serial console. The runner reused a validated image and recorded the loaded release and build. The 15.1 target label alone does not identify the patch level. FTF's separate relocation smoke test establishes that the embedded framework can boot a cached image with an external cache and collect results. [2, 4, 5]

3. Establishing the lock owner

A. Identifying a single file lifetime

The detailed trace initially missed the relevant directory. The filter compared the CTF-decoded vnode type with the directory value 2, but the decoded value in this capture was 258. Reading the packed type byte returned 2 and recovered the events. An additional selection problem was address reuse. Earlier records show the same file address paired with other vnodes, so we follow the final lifetime in which the file and vnode agree throughout the sequence. [1, 3]

Table 2. Selected p1 events for one file and vnode, in monotonic timestamp order. Reference counts are point samples.

Thread Recorded event Relevant state
Lookup worker, TID 113188 VGET_ENTER Target acquisition begins
Closing thread, TID 113187 FD_REMOVED, CLOSEF_RETURN The descriptor is removed and its close returns successfully
Lookup worker VGET_RETURN Acquisition succeeds and the worker owns the exclusive lock
Lookup worker FINAL_DROP, VNODE_CLOSE The file count reaches zero and close enters with the lock still held
Lookup worker CALLBACK_STALLED The lock word still identifies the worker

The descriptor close returned before vnode acquisition succeeded. The later close ran in the lookup worker, through that worker's final file release. The trace establishes this ordering while leaving the identity of an additional reference in an earlier sample unresolved. [3]

B. Confirming ownership independently

We inspected the live dump read-only using Compact C Type Format (CTF) field offsets, symbol tables, and the callback frame layout. The SHA-256 hashes of the archived kernel, fdescfs module, and ZFS module matched the incident artifacts. The callback's output vnode, the file's vnode, and the traced vnode matched. The vnode lock's masked owner equaled the stalled worker's thread pointer. The file reference count was zero and the callback's fdropped flag was clear, consistent with final release having entered the close operation before the callback could record its return. [1]

The dump also distinguished the fdescfs lookup directory from the underlying ZFS directory. That distinction explained a flaw in an early probe, which used the fdescfs root as the target. A later guest check compared device and inode numbers through each interface and confirmed that the lookup reached the open ZFS directory. [1, 2, 4]

C. Explaining the retry loop

In the recorded nodup vnode path, fdesc_get_ino_alloc() acquires the target vnode through vget() before releasing its file reference through fdrop(). When the reference count reaches zero, _fdrop() invokes vn_closefile(), which reaches vn_close1(). The incident analysis identifies a shared close lock request against the worker's existing exclusive lock. Earlier incident tracing recorded repeated EDEADLK returns, and disassembly identified the retry loop in _vn_lock_fallback(). The worker can unwind to release its exclusive lock only after the nested close returns. Together, the owned lock and the retry explain sustained CPU consumption during the stall. [1, 2]

4. Reproduction on the stock p6 guest

Earlier timing-only trials completed without the incident stack. The successful guest experiment used a synthetic workload to increase overlap between lookup and close. It reproduced the failure on the first recorded attempt in that configuration. The following selected frames are from PID 526, TID 100227, with the innermost frame first. [2, 4]

_vn_lock_fallback+0x9e vn_close1+0x1b0 vn_closefile+0x3d _fdrop+0x11
fdesc_get_ino_alloc+0x91 vn_vget_ino_gen+0x16b fdesc_lookup+0x145
vfs_lookup+0x401 namei+0x26d kern_statat+0xfe sys_fstatat+0x27

Read from the bottom, the stack starts in the fstatat system call and reaches vnode close inside the fdescfs callback. At capture, procstat reported 45.098922 seconds of system CPU and zero user CPU for the process. The process remained present after SIGKILL. The guest iteration took 49.052 seconds and the full run took 49.517 seconds. The console's 2,000 ms threshold was a configured value. CPU starvation of the polling and diagnostic processes on the single vCPU is a plausible explanation for the delayed capture. FTF reported passed because the payload expected the hang and exited successfully after recording it. [4]

The archived console and JSON provide an independent check of the p6 stack, CPU accounting, signal outcome, and image identity. Direct lock-owner evidence comes from the p1 dump. The stock guest did not supply a WITNESS or INVARIANTS report. One successful synthetic trial leaves the natural race frequency and the affected filesystem range unknown. [1, 2, 4]

5. From one stuck worker to system-wide loss of service

A separate p1 dump captured both the spinning dust worker and an unrelated ls process blocked in a directory lookup. The wait-channel address for ls matched the lock on the ZFS directory vnode. After masking the state bits in the lock word, the owner pointer matched the dust worker. The two observations in one dump establish that the self-lock can block filesystem access by a second process. [7]

The effect depends on how widely the directory is used. A lock on a rarely accessed directory can leave unrelated work running. A lock on a directory traversed by essential services can leave those services waiting indefinitely as they encounter the locked vnode. The investigator reports that the project's reproducer caused a system-wide hang in this situation. The archived p6 run used a private scratch directory and documents the process-level failure. The system-wide outcome is based on the investigator's report. [4, 6, 7]

6. Candidate correction and validation criteria

The proposed change separates vnode lifetime from vnode locking. The lookup would first retain the vnode independently of the file, release the file while it holds no target vnode lock, and then finish vnode acquisition. Final close can then acquire the lock, while the vnode remains available to the lookup. The matching source exposes vget_prep(), vget_finish(), and vget_abort() for review as part of that handoff. A patch must account for failed acquisition, doomed vnodes, parent relocking, and preservation of descriptor metadata. [1, 6]

A controlled comparison would use matched unpatched and patched kernels and modules, equivalent synchronization points, and the same guest workload. The baseline should show the recorded conflict. The patched case should show final close completing before the lookup takes the target lock, followed by either a successful lookup or a normal error if acquisition fails. Reverting the patch should restore the baseline outcome. The patch and paired results were pending in the source material. [6]

7. Conclusion

In the p1 incident, the lookup worker reached final file close while holding the very lock that close needed. The p6 guest showed that the same lookup-to-close failure signature persisted in a later stock build. The blocked ls shows how the fault propagates to other processes. If their filesystem operations are necessary for essential services, that dependency can turn a stuck worker into a system-wide outage. The repair criterion follows from the observed ownership sequence. Final file release must be able to complete while the lookup preserves the vnode's lifetime without owning its lock. Whether a candidate implementation satisfies that criterion remains to be tested.

References

  1. Incident analysis, trace corrections, and live-dump inspection.
  2. Engineering record and source-path analysis.
  3. Selected p1 trace events from the final file lifetime.
  4. Stock p6 guest run run.fq85Wo. Console transcript and run metadata.
  5. FreeBSD Test Framework. Pinned runner documentation and vendor provenance and relocation check.
  6. Investigation status. Validation plan and local triage draft.
  7. Same-dump comparison of the blocked ls and the dust lock owner.