Free Intensive Nov 21–22Free 2-day hands-on Vibecoding Intensive on Nov 21–22 at 16:00 MSK (Sat–Sun) · Live Cohort 3 starts Nov 23Join Free →Cohort 3 (Nov 23)
ReleaseInsight · On RadarNeurohive→ original

Claude Code sped up Linux file reads up to 23x, but missed a bug that people found

Linus Torvalds asked Claude Code to speed up the Linux kernel. When dozens of threads read the same file, they queue up behind a shared reference counter. The patches delivered up to a 23x speedup on 64 threads, but that was in a synthetic test; with CPU mitigations enabled, the gain is about 4.5x. Four hours later, Kirill Shutemov found a race: a failure that occurs when one thread reads a page while another replaces it. The model's tests had not caught it. That is why AI-written kernel code should not go in without expert review.

AI-processed from Neurohive; edited by Hamidun News
Claude Code sped up Linux file reads up to 23x, but missed a bug that people found
Source: Neurohive. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceNeurohive ↗
Editor-in-Chief
Without CPU mitigations on a Threadripper13.3 → 304 million reads per second
With mitigations enabled, ext4about 4.5x; XFS: less than 2x
Key metric #3The patches will not make it into Linux 7.4; the next chance is version 7.5 in 2027

Picture a store checkout where all the customers share one notebook: each shopper first writes "I started" in it, then "I finished." There are plenty of registers, but only one notebook, so people spend more time waiting in line for the notebook than being served. That is roughly how reading a single file slowed down in the Linux kernel when dozens of threads went after it.

Linus Torvalds assigned Claude Code a task that kernel developers had failed to close for two and a half years, and got a speedup of up to 23x. But that is the maximum for a specially chosen synthetic test on a 64-thread processor, and the code also contained a race bug: a rare failure where one thread reads a memory page at the moment another thread replaces it. The tests the model wrote itself did not catch it.

What the problem was

When a file is already in RAM (in the page cache), the kernel does not need to touch the disk. But before copying the data, it increments a reference counter on the memory block, and after copying, it decrements it. This is how the kernel marks that the memory is still in use and cannot be freed yet. That is the shared notebook.

When one thread reads the file, this costs almost nothing. But when dozens of threads read it, the CPU cores keep passing that counter between each other and spend more time waiting than working. In Torvalds's measurement with eight threads, 99.92% of the events on the cache line holding that counter were cases where one core needed data that another core had just modified.

You cannot simply remove the counter: a page could be freed and handed over to other data right in the middle of a copy. Earlier attempts copied the data without the counter and checked correctness afterward, but that check missed some races. For example, a page was freed and a new one took its place in the cache.

What Torvalds and Claude Code came up with

Torvalds took a different approach. He chose to remove the cause of the race rather than catch its consequences: pages are now freed with a delay, and the RCU mechanism waits for all reads already in progress to finish. Since memory cannot be reused for other data during a copy, the counter is not needed on the fast read path.

He assigned the implementation to Claude Code. The model prepared the code, tests, an analysis of open issues, and a draft of the cover letter. Torvalds chose the approach, directed the work, and ran the measurements himself. He named the branch noref-filemap-read-with-llm and wrote explicitly that the work was done with an AI assistant under his direction.

The numbers are as follows. On a workstation with an AMD Ryzen Threadripper 3970X and 64 threads, reads rose from 13.3 to 304 million operations per second, and the cost of a single operation fell from roughly 20,000 CPU cycles to 735. On a laptop with a Core i7-8565U and eight threads, the gain was about 3x.

The 23x figure needs a caveat. In the test, all threads kept reading the same small region of one page. That is the worst case for the old code, and it almost never occurs in real workloads. When Kirill Shutemov ran a series with CPU mitigations enabled by default, reads from ext4 sped up about 4.5x, from XFS less than 2x, and with one thread there was no difference. The speedup also has a cost: if the destination buffer's pages are not yet in memory, the fast attempt triggers an extra CPU exception, and that operation ends up costing more than it did without the patches.

The bug people found

Four hours after publication, Shutemov, who works on the memory subsystem, found a race condition in the filemap_read_rcu_batch() function. One thread selects a page to read, while another thread at that moment replaces it in the cache and appends to the file. The first thread sees the new file size but reads the old page, including a section where the file's data was never written.

Deferred freeing does not help here. It guarantees that the page will not be reused for other data, but not that it still matches the file. The tests did not catch this scenario: in the measurements, threads read an unchanging file, and the bug only shows up when page eviction coincides with an append.

If the patches had gone into the kernel as they were, a program reading a file that is being appended to (a log or a database) would, in rare cases, receive data that never existed in the file, and would not know it. Such failures are almost impossible to reproduce.

Shutemov immediately proposed a fix with a recheck, and Torvalds replied that the size could be read earlier, making a single check sufficient. Then he handed the series over to Shutemov, as his vacation was about to start. Shutemov reworked it in five days, and on October 19 a version of 18 patches was posted, seven of which Torvalds wrote himself. Reviewers also debated the PG_rcu_free flag, and in the end the mechanism was kept only for 64-bit systems.

What this means

The series is currently being circulated as an RFC (request for comments). It will not make it into Linux 7.4, since the merge window only accepts code that maintainers have already reviewed. The next realistic opportunity is Linux 7.5 in 2027.

For developers, the takeaway is simple. The agent did move a task that people had been stuck on for years. But the roles were divided: a human chose the approach and ran the measurements, the model wrote the code and the tests, and the bug was found by a reviewer who knew where earlier solutions had broken. Tests written by the model itself only check what the model imagined. That is why risky code needs independent reviewers and tests for concurrent scenarios, not just the happy path.

Story

Key Questions Answered

What the problem was?

When a file is already in RAM (in the page cache), the kernel does not need to touch the disk. But before copying the data, it increments a reference counter on the memory block, and after copying, it decrements it. This is how the kernel marks that the memory is still in use and cannot be freed yet. That is the shared notebook. When one thread reads the file, this costs almost nothing.

What Torvalds and Claude Code came up with?

Torvalds took a different approach. He chose to remove the cause of the race rather than catch its consequences: pages are now freed with a delay, and the RCU mechanism waits for all reads already in progress to finish. Since memory cannot be reused for other data during a copy, the counter is not needed on the fast read path. He assigned the implementation to Claude Code. The model prepared the code, tests, an analysis of open issues, and a draft of the cover letter.

What are the key details on The bug people found?

Four hours after publication, Shutemov, who works on the memory subsystem, found a race condition in the filemap_read_rcu_batch() function. One thread selects a page to read, while another thread at that moment replaces it in the cache and appends to the file. The first thread sees the new file size but reads the old page, including a section where the file's data was never written. Deferred freeing does not help here.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…