Linus Torvalds Uses Claude Code to Fix Linux Kernel Page Cache Bottleneck

Photo: Linus Torvalds (Krd (photo) Von Sprat (crop/extraction) · CC BY-SA 4.0 · Wikimedia Commons)

Linux creator and longtime lead maintainer Linus Torvalds recently turned to Anthropic's command-line coding agent, Claude Code, to address a persistent page cache performance bottleneck that kernel developers have wrestled with for over two years. Pushing an experimental branch to his repository, Torvalds credited the AI assistant with helping write the implementation, tests, and initial documentation under his direction, according to reports from The New Stack and Hardware Busters.

The Page Cache Contention Problem and AI Implementation

The underlying scalability issue stems from atomic writes to the same struct page cache line when multiple threads execute tiny reads against a shared file. First flagged in 2024 by Oracle engineer Matthew Wilcox after surfacing in a customer workload, the contention accounted for an overwhelming 99.92% of cross-core load HITMs in eight-thread tests on Torvalds' laptop, as noted by Hardware Busters. Torvalds had previously spent 18 months running a broken version of his own fix while other contributors struggled with alternative approaches.

Spotting an unusual topic branch named noref-filemap-read-with-llm based on Linux 7.3-rc6, observers noted that the commit cover letter openly credited Claude Code. Torvalds directed the agent to draft the code, design tests, and review problems, while he personally handled the benchmarking. Instead of attempting to validate stack buffer copies after the fact, the new patch series introduces a PG_rcu_free flag and RCU-delayed reclamation, allowing a reader inside an RCU read-side section to copy data straight from the page into a userspace buffer without taking a folio reference.

Benchmark Gains and Hardware Performance Differences

Both publications highlighted significant performance leaps, though they focused on different machine metrics. Hardware Busters detailed how Torvalds' initial laptop testing pushed eight-thread performance from roughly 10 million to as many as 33 million reads per second, dropping kernel cycles per read from 2,950 down to 725 and slashing load HITMs from over 30,000 to just 101. Meanwhile, The New Stack noted even larger gains under heavy contention on a 64-thread Ryzen Threadripper, where throughput soared from 13.3 million to 304 million reads per second and cycles per read plunged from nearly 20,000 to 735.

However, these speedups came with distinct trade-offs. Delayed memory freeing caused unused pages to accumulate, prompting the inclusion of safety valves forcing expedited grace periods when a CPU queues more than 1,024 pages. Hardware Busters also pointed out regressions, such as reads into unmapped user pages triggering an extra fault before falling back, which increased single-thread read cycles from approximately 4,150 to 6,550.

What the Claude Code Kernel Experiment Means for Systems Development

The decision by Linux's lead maintainer to employ an AI coding agent for a core memory-management subsystem marks a fascinating intersection between experimental AI tooling and uncompromising systems programming. For years, skeptics and maintainers alike have debated the utility of generative AI in complex codebases where a single overlooked race condition can trigger catastrophic data corruption or memory leaks. While Torvalds' experiment delivered staggering throughput numbers on synthetic benchmarks, the immediate and rigorous pushback from kernel reviewers underscores that AI-generated code bypasses none of the traditional governance hurdles. The discovery of race conditions by peers and ongoing debates regarding memory reclamation design prove that raw benchmark acceleration cannot substitute for meticulous human code review. Ultimately, this episode illustrates that while large language models can successfully prototype intricate low-level algorithms and accelerate tedious boilerplate writing, they remain subject to the exact same architectural disputes and security constraints that define the Linux kernel development lifecycle.

Reviewer Pushback and Code Modifications

The patch series immediately drew critical feedback from memory-management maintainers. Matthew Wilcox questioned the new PG_rcu_free flag, proposing instead to use a specific page type alongside inactive-list reclamation after an RCU grace period. Torvalds rejected those suggestions, arguing that the flag must be set while a folio can still map into userspace and that inactive lists fail to cover truncate and hole-punch operations.

Further scrutiny revealed substantive bugs. Linux kernel developer Kiryl Shutsemau identified a race condition in filemap_read_rcu_batch(), where folio replacement combined with an extension of i_size could expose unwritten data. Following Torvalds' recommendations to consolidate checks and read file sizes earlier, Shutsemau incorporated fixes into a revised patch. Torvalds subsequently handed further development of the series over to Shutsemau, with backing from Arm engineer David Hildenbrand to restrict the implementation to 64-bit systems.

Cover: Krd (photo) Von Sprat (crop/extraction) · CC BY-SA 4.0 · Wikimedia Commons. Layout and headline text by Signal Titans. Logo: Anthropic, via Wikimedia Commons (Public domain).

Source: Linus Torvalds let Claude Code fix the Linux page cache. Then reviewers found a race. · Linus Torvalds Uses Claude Code to Rework the Linux Page Cache, Tripling Small-Read Throughput – Hardware Busters

Share this article
FacebookThreadsLinkedInX

Leave a Reply

Your email address will not be published. Required fields are marked *