Linux 6.9 Lowering The Overhead Of CR3 Writes

Written by Michael Larabel in Linux Kernel on 20 March 2024 at 02:00 PM EDT. 1 Comment
LINUX KERNEL
The x86/entry pull request last week for the Linux 6.9 kernel contained just a single patch but it was a significant one at that in that it helps lower the overhead for CR3 writes and the benefits can be visible for workloads like Linux's perf functionality.

Thomas Gleixner explained in the x86/entry pull request for Linux 6.9:
"The current CR3 handling for kernel page table isolation in the paranoid return paths which are relevant for #NMI, #MCE, #VC, #DB and #DF is unconditionally writing CR3 with the value retrieved on exception entry.

In the vast majority of cases when returning to the kernel this is a pointless exercise because CR3 was not modified on exception entry. The only situation where this is necessary is when the exception interrupts a entry from user before switching to kernel CR3 or interrupts an exit to user after switching back to user CR3.

As CR3 writes can be expensive on some systems this becomes measurable overhead with high frequency #NMIs such as perf.

Avoid this overhead by checking the CR3 value, which was saved on entry, and write it back to CR3 only when it us a user CR3."

The pull request was successfully merged ahead of Linux 6.9-rc1 due out this weekend. This patch was written by an Alibaba engineer while Google also has carried a similar patch for their own internal kernel builds to this point.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week