How 18 Linux 7.4 patches make kernfs more efficient by reducing lock contention, improving path walking, and fixing filesystem bugs.
Introduction
Meta engineers uncovered a performance problem in the Linux kernel that could leave critical system daemons waiting for minutes across the company’s server fleet. The investigation led to 18 patches authored by Meta engineer Shakeel Butt for Linux 7.4, improving kernfs locking behavior and fixing several bugs.
As reported by Michael Larabel of Phoronix, four highlighted patches improved path-walking throughput by 35% to 53% in a reported benchmark. The work is a useful example of a core scalability principle: adding more processors or servers is not always the answer. Sometimes, the best improvement comes from removing software bottlenecks that prevent existing resources from working efficiently.
Kernfs scalability · Linux 7.4
Reported Benchmark Results
Path-walking throughput
+35–53%
Improvement under the tested workload
Read-lock acquisitions
48.59M → 1.28M
≈97.4% reduction
Read-lock contentions
1.74M → 429.8K
≈75.4% reduction
Test environment
8 CPUs
Virtual machine under concurrent activity
1. The Hidden Bottleneck: Why Kernfs Matters
Kernfs is a Linux kernel infrastructure framework used to implement pseudo-filesystems, including sysfs and cgroupfs. These interfaces let userspace applications and system services inspect and manage information exposed by the kernel.
sysfs exposes information about devices, drivers, and kernel objects. cgroupfs provides interfaces for Linux control groups, which organize and control resource use by processes. Monitoring services, container platforms, and resource-management tools may access these interfaces frequently, especially on servers running many workloads.
Kernfs must support frequent reads as well as structural changes such as creating, removing, and renaming entries. To coordinate these activities safely, it uses synchronization mechanisms, including the read-write semaphore kernfs_rwsem. Under heavy concurrency, this shared lock can become a bottleneck.
2. How Lock Contention Caused System Daemons to Stall
Lock contention occurs when multiple threads or processes compete for a resource protected by a lock. A read-write semaphore permits concurrent readers but coordinates them with writers. In the behavior discussed in the kernel report, a queued writer can prevent new readers from moving ahead, allowing a queue of readers to build up behind a pending write operation.
On a large server, one process might create or modify a control-group entry while monitoring services repeatedly inspect cgroup information. Even if each read is individually inexpensive, many operations can wait on the same shared lock. The delay can spread to services that depend on the interface.
The kernel development report identified two affected services: systemd-oomd, which helps respond to memory pressure, and below, a Linux performance and resource-monitoring tool. The report described allocation stalls lasting about 120 seconds in a below execution path, while systemd-oomd could also become stuck waiting for kernfs operations.
This is especially concerning because software responsible for responding to resource pressure can itself be delayed by the infrastructure it depends on. A bottleneck in a shared kernel component can affect multiple services at once.
3. Shakeel Butt’s 18 Patches: Reducing Unnecessary Locking
The 18-patch series targeted kernfs in the Linux 7.4 development cycle. The changes improved locking behavior, directory-entry validation, directory iteration, and filesystem correctness. The central goal was to reduce work performed while holding shared locks and remove locking operations where they were unnecessary.
A. Removing unnecessary locking during path validation
When a process accesses a filesystem path, the kernel resolves the path and checks whether relevant directory entries remain valid. Kernfs’s kernfs_dop_revalidate() routine previously acquired kernfs_rwsem for reading while checking path components. The changes reworked the validation path to use read-copy-update (RCU) protection where appropriate, reducing repeated semaphore acquisitions.
RCU is a Linux synchronization technique that allows certain readers to access data with low overhead while updates are coordinated safely. The point is not that locks are inherently bad—locks are essential for correctness—but that they should protect only the operations that require them.
B. Shortening the time locks are held
The patches also changed directory iteration in kernfs_fop_readdir(). Previously, the semaphore could remain held while directory-entry information was copied to userspace. If that copy stalled, operations needing the same lock could be delayed. The updated approach releases the semaphore around the operation and resumes iteration using a more complete entry key, helping avoid repeated or skipped entries when a directory changes.
C. Moving expensive work outside critical sections
A critical section is code that runs while holding a lock. Memory allocation, memory reclaim, notification delivery, or other potentially slow work inside a critical section can make lock hold times unpredictable. The patch series moved several operations outside protected regions—for example, allocating new directory-entry names before acquiring a write lock and freeing old names after releasing it.
These changes illustrate a widely useful systems-engineering technique: reduce the time shared resources are held, while preserving correctness under concurrent changes.
4. The Performance Results: Up to 53% Better Path-Walking Throughput
The reported benchmark simulated concurrent reads of cgroupfs and sysfs while other activity created and modified cgroups, renamed network devices, and added or removed devices on an eight-CPU virtual machine.
The number of read-lock acquisitions fell from 48,593,360 to 1,280,280—about a 97.4% reduction. Read-lock contentions fell from 1,744,517 to 429,846—about a 75.4% reduction. These percentages are calculations from the reported figures.
The headline result is the 35–53% improvement in path-walking throughput. Path walking is a fundamental filesystem operation, but the benchmark does not mean every application becomes 35–53% faster. The benefit depends on how much a workload relies on the affected operations.
Benchmark caveat: These figures describe the reported test environment and workload, not a universal improvement for every Linux system.
5. The Broader Patch Series: Performance and Correctness
The four highlighted performance changes are part of a broader series addressing directory-entry validation, lock contention during filesystem changes, directory-iteration behavior, synchronization around file handles and renames, attribute-reading and ownership-related race conditions, and additional filesystem self-tests.
- Improving directory-entry validation and reducing repeated lock acquisition.
- Reducing contention during file creation, modification, and directory iteration.
- Preventing directory iteration from repeating or skipping entries when directories change.
- Correcting synchronization and race-condition issues.
- Expanding tests to cover additional concurrent and edge-case scenarios.
Scalability is not achieved by improving a benchmark in isolation. A concurrent filesystem must remain correct while many processes inspect, create, remove, rename, and access entries. A change that increases throughput but introduces race conditions would not be an acceptable optimization.
6. Why This Matters for Cloud Computing and Enterprise Linux
Organizations running Linux servers, container platforms, virtual machines, and resource-intensive applications rely on kernel interfaces for monitoring, orchestration, and resource management. When those interfaces become bottlenecks, the result can be slower management operations, delayed monitoring, reduced throughput, and unpredictable behavior under load.
More hardware is not always the answer
If lock contention is the limiting factor, adding CPUs may not solve the problem. Additional concurrent activity can even increase competition for the same shared resource. Engineers should determine whether a workload is limited by computation, memory, storage, networking, synchronization, or a combination.
Monitoring must remain responsive during emergencies
Resource-management services need access to system information precisely when a machine is under pressure. If they depend on a congested kernel interface, delays can undermine their effectiveness. The performance of monitoring and control paths is therefore an important part of infrastructure reliability.
Small kernel changes can have broad effects
Kernfs is a foundational component rather than a standalone application. Improving a shared component can benefit multiple userspace services, although the actual impact varies with their workloads and use of the affected paths.
7. Practical Lessons for Linux Administrators and Developers
- Reproduce the problem under realistic concurrency. A component that performs well in isolation can behave differently when readers and writers compete for shared resources.
- Measure contention, not only CPU utilization. A system can have available CPU capacity while important threads remain blocked on locks.
- Inspect critical-section duration. Memory allocation, filesystem access, and communication with userspace can make lock hold times unpredictable.
- Remove unnecessary synchronization carefully. Techniques such as RCU can reduce reader overhead where the data model permits, but correctness requirements must guide the design.
- Validate performance and correctness together. Pair benchmarks with tests for concurrent modification, race conditions, and edge cases.
- Measure application-level impact. Faster filesystem operations matter, but their effect on end-to-end latency depends on the workload.
Conclusion: Better Scalability Begins With Removing the Right Bottleneck
Meta’s kernfs work for Linux 7.4 demonstrates how a focused investigation into real-world performance problems can improve a foundational software component. Shakeel Butt’s 18 patches address lock contention, unnecessary synchronization, long critical sections, and filesystem correctness issues that were contributing to delays across Meta’s infrastructure.
The reported 35–53% improvement in path-walking throughput shows the potential benefit of eliminating unnecessary work under shared locks. More broadly, scalable systems require more than additional computing resources: they require careful analysis of how components interact, how synchronization affects concurrency, and how performance behaves under realistic conditions.
For Linux developers and infrastructure engineers, the lesson is clear: find the bottleneck, measure its impact, minimize unnecessary contention, and verify that the solution remains correct under load. This approach can turn a hidden performance limitation into a practical scalability improvement.
Sources and Further Reading
- Michael Larabel, Phoronix — Meta Makes Improvements To Kernfs Scalability With Linux 7.4.
- Linux Kernel Mailing List — Git pull: v7.4 kernfs scalability work.
Editorial note: Performance figures are attributed to the cited Phoronix report and kernel pull request. Calculated percentage reductions are derived from the reported counts. The stated throughput improvement applies to the reported benchmark and should not be generalized to all workloads.
Leave a Reply