Linus Torvalds Improves Futex Code To Improve User-Space Accesses

Written by Michael Larabel in Linux Kernel on 26 November 2024 at 06:16 AM EST. 3 Comments
LINUX KERNEL
In between managing all of the pull requests being submitted during this two week long merge window for the Linux 6.13 kernel, Linus Torvalds has merged some of his own code this cycle.

Coming just a month after Torvalds himself worked out a minor performance optimization patch in Linux 6.12, for Linux 6.13 he's onto another minor optimization. This time around Torvalds is working on improving user-space accesses from within the Futex code.

Torvalds writes a new patch


Going off this Linux kernel mailing list thread, Torvalds came up with a new improvement to the kernel. The Linux creator explained in yesterday's commit:
"Josh Poimboeuf reports that he got a "will-it-scale.per_process_ops 1.9% improvement" report for his patch that changed __get_user() to use pointer masking instead of the explicit speculation barrier. However, that patch doesn't actually work in the general case, because some (very bad) architecture-specific code actually depends on __get_user() also working on kernel addresses.

A profile showed that the offending __get_user() was the futex code, which really should be fixed up to not use that horrid legacy case. Rewrite futex_get_value_locked() to use the modern user acccess helpers, and inline it so that the compiler not only avoids the function call for a few instructions, but can do CSE on the address masking.

It also turns out the x86 futex functions have unnecessary barriers in other places, so let's fix those up too."

Linus Torvalds got that Futex code cleaned up with a few dozen lines of code. Josh Poimboeuf who worked on the original optimization patch commented he didn't have a chance yet to re-create the original benchmark but the new code "looks obviously correct."

This is just a minor improvement overall but Linux 6.13 as a whole is shaping up to be very exciting from new features to continuing with more performance optimizations.
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