Skip to content

Commit 5107cc7

Browse files
sysfs: decouple IOKit snapshot allocation and traversal from g_lock
Holding g_lock across IOMalloc allocations, registry traversals, and memory frees in sysfs_iokit.cpp causes severe lock contention and thread starvation during frequent /sys filesystem operations. Refactor sysfs_iokit.cpp to use a Read-Copy-Update (RCU) / Double-Checked Swap pattern: - Encapsulate snapshot state (nodes, child indices, hash slots) inside a single heap-allocated struct sysfs_snapshot container. - Modify sysfs_snap_build() to construct and populate fresh snapshots in complete isolation without acquiring g_lock. - Update sysfs_snap_ensure() to execute memory allocation and IOKit tree traversals unlocked, re-acquiring g_lock only to perform an atomic pointer swap with double-checked TTL validation. - Deallocate stale snapshot memory after dropping g_lock. This reduces g_lock hold times from millisecond-range tree walks to a few nanoseconds for pointer swaps, eliminating reader starvation during parallel vnode lookups and tree walks.
1 parent 807e937 commit 5107cc7

1 file changed

Lines changed: 145 additions & 98 deletions

File tree

0 commit comments

Comments
 (0)