HAVE AI NEWS HAVE AI NEWS
tg subscribe
Tools

Torvalds and Claude Code Tandem: A 23x Linux Speedup and a Critical Bug Caught by a Human

Torvalds and Claude Code Tandem: A 23x Linux Speedup and a Critical Bug Caught by a Human

Linus Torvalds enlisted Claude Code to tackle a task that had lingered in the Linux kernel for two and a half years. The neural network helped boost parallel file reading by up to 23 times, but missed a dangerous race condition.

Linus Torvalds' experiment with generative AI has clearly delineated the limits of modern neural networks in systems programming. Using the Claude Code assistant, the creator of Linux managed to break ground on an architectural problem that had eluded developers for over two years. The benchmarks yielded striking numbers, but within hours a human audit uncovered a hidden vulnerability that AI-generated tests had completely overlooked.

The Roots of the Two-Year Deadlock Over the Reference Counter

A bottleneck in the kernel's page cache was described back in 2024 by Oracle developer Matthew Wilcox. The issue manifested in scenarios where dozens of threads concurrently read tiny chunks of the same file. The kernel had to constantly update the internal reference counter of the folio structure (a block of RAM pages) to prevent data from being freed prematurely.

Under high contention for the same counter, CPU cores stalled, constantly bouncing the modified cache line back and forth (load HITM events). In Torvalds' tests, this operation accounted for more than 99.9% of CPU stalls during multithreaded access. Previous attempts to eliminate the atomic counter had failed: they risked reading garbage data or triggering situations where memory was freed right in the middle of being copied into user buffers.

Torvalds' Idea and Claude Code's Implementation

The solution took shape following the maintainers' summit in Prague last autumn. Rather than validating correctness after the fact, Linus proposed eliminating the root cause of data corruption using RCU (Read-Copy Update)—a deferred page reclamation mechanism. Until active read operations complete, the memory is guaranteed not to be reallocated to other processes. This made it possible to completely drop counter synchronization from the fast read path.

Torvalds delegated the routine work to Claude Code: the model generated the code, authored the accompanying descriptions, and prepared a test suite. The Linux creator openly credited the authorship in his repository (branch noref-filemap-read-with-llm) while personally handling performance benchmarks.

Hardware ConfigurationBefore PatchAfter OptimizationResult
AMD Ryzen Threadripper 3970X (64 threads, btrfs)13.3M ops/sec (≈20,000 cycles)304M ops/sec (≈735 cycles)23x speedup
Intel Core i7-8565U Laptop (8 threads, ext4)≈10M ops/sec (≈2,950 cycles)≈33M ops/sec (≈725 cycles)3.3x speedup
Intel Core i7-8565U (1 thread, memory buffer miss)≈4,150 cycles≈6,550 cycles1.6x slowdown

Torvalds was quick to temper expectations regarding the 23x figure: this was a synthetic edge-case scenario where all cores hammered the exact same fragment simultaneously. In real-world software, the gains will be more modest, and reading into not-yet-allocated pages incurs CPU exception overhead that actually causes a slight slowdown.

The Race Condition Missed by AI

The triumph was short-lived. Just four hours after the patch series was posted to the LKML mailing list, memory subsystem developer Kirill Shutemov identified a critical bug in the filemap_read_rcu_batch() function. Hidden within Claude Code's logic was an overlooked race condition.

The crux of the bug was as follows: if one thread intended to read a page while a second thread replaced it in the cache and appended to the file within the same microsecond window, the first process would read the correct new file size but pull data from the old page—resulting in a phantom "tail" filled with stale junk. Deferred RCU cleanup prevented memory from being hijacked by another application, but it did not guarantee consistency with the file's current contents.

The automated tests written by Claude Code failed to catch the race condition: they repeatedly hammered a static file, whereas the bug only surfaces under overlapping concurrent writes, page evictions, and reads.

In server environments and database workloads, such a bug could cause silent transaction corruption that is nearly impossible to diagnose on a live system. A potential disaster was averted only because Shutemov had previously investigated this mechanism and was well aware of its subtle failure modes.

When to Expect the Release and What It Means for the Industry

Before heading out on vacation, Linus handed off the refinement of the patch series to Shutemov. He quickly reinforced validation checks, enforced operational ordering with memory barriers, and restricted the controversial PG_rcu_free flag to 64-bit architectures only. In a realistic test incorporating standard CPU hardware mitigations, the updated patch yields roughly a 4.5x speedup on ext4 for 64 threads.

The changes will not make it into the 7.4 kernel release: the code remains in RFC status and requires thorough review by maintainers. The earliest window for the technology to land is the Linux 7.5 release in 2027.

This precedent clearly sets priorities: neural networks excel as a digital hammer, rapidly drafting code and lowering the barrier to entry on complex tasks. However, they lack deep context regarding edge conditions and produce blind tests. Responsibility, catching subtle traps, and architectural decision-making still rest entirely with human engineers.

Author: Boris Sedu

Source: neurohive.io