Linux 7.4 changes how Clang estimates the traffic through branches in kernel code.
Gear / The story

Why Linux 7.4 changes how Clang reads performance samples

Clang 21 changed how it fills gaps in a sampled profile. For some Linux kernel builds, that calculation could take more than half an hour. Three lines bring back the earlier method.

GeekRadar3 min read

One of the slower jobs in a Linux kernel build can be figuring out which code ought to run faster. A three-line change for Linux 7.4 switches off an LLVM algorithm called Profi when building a kernel with a sampled performance profile. The patch describes cases where its calculation took more than 30 minutes or appeared to hang. The kernel still uses the samples. What changes is how the compiler fills in the parts they missed.

The distinction matters if you build kernels for a fleet of similar machines. You can run a representative workload, collect a profile and give it to Clang when compiling the next kernel. That process, called AutoFDO, gives the compiler evidence about which paths deserve its attention. It also means a change in a compiler default can alter the kernel you ship even if the workload and source code stay the same.

An illustrative branch with 100 arrivals, 80 through one arm and 20 through the other. The numbers show how counts constrain one another, and are not kernel measurements.
An illustrative branch with 100 arrivals, 80 through one arm and 20 through the other. The numbers show how counts constrain one another, and are not kernel measurements.

What the compiler has to infer

Imagine a stretch of code with one entrance and two exits. If it ran 100 times and took the left exit 80 times, the right exit accounts for the other 20. A hardware sampler rarely hands the compiler such a tidy ledger. It observes execution at intervals. A rarely used path might receive no samples at all, and several branches might meet again before the next observation. Different estimates of the missing traffic can fit the same handful of observations.

Clang 21 began selecting Profi by default for sample-based optimization. Its flow calculation tries to reconcile the observations across the graph of possible paths. The kernel’s profiles already carry extra information to distinguish paths through code. According to the patch, Profi interacted poorly with those profiles in some cases. The maintainers reported two separate costs: the time spent doing the calculation and poorer performance in the resulting program compared with the previous method. The patch supplies no general percentage for that second effect.

Who actually gets the change

The fix sits in the kernel build system. For a C build using an AutoFDO profile, it explicitly selects the earlier behavior on Clang 21 and newer. It also keeps the corresponding settings consistent for Rust and for ThinLTO, the stage that can optimize across separately compiled files. A kernel built without a sample profile never enters this part of the build. There is no desktop switch to flip after installation.

That scope makes this a different kind of result from a timed Linux storage test, where a particular operation finished sooner on a specified setup. Here the evidence explains why kernel builders want a predictable interpretation of their data. The kernel’s AutoFDO documentation stresses the choice that still belongs to them: sample a workload that resembles what the machine will actually do. A compiler can reconcile counts on a thousand branches. It cannot tell that the job you measured on Tuesday is the wrong one for the server you deploy on Friday.