Fundamentals 4 min read

Linux Kernel Patch Improves Performance by 2.6% in Intel Benchmark

Linus Torvalds merged a small patch into the Linux kernel that streamlines the 64‑bit copy_from_user() routine by skipping the costly barrier_nospec() and applying masked user‑address handling, delivering a 2.6% speedup on Intel’s “will it scale” per‑thread‑ops benchmark and slated for inclusion in the upcoming Linux 6.12 stable release.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Linux Kernel Patch Improves Performance by 2.6% in Intel Benchmark

Linus Torvalds merged a small patch into the Linux kernel that modifies the 64‑bit copy_from_user() implementation. By avoiding the costly barrier_nospec() and adding masked user‑access handling, the patch yields a 2.6% performance gain on Intel’s “will it scale” per‑thread‑ops benchmark.

The purpose of the patch is to skip barrier_nospec() in 64‑bit copy_from_user() and to use pointer masking when the user pointer is invalid. Linus explained that the original function runs slowly and that pointer masking can force all user pointers to be all‑ones when invalid.

@@ -38,6 +38,7 @@
#else
 #define can_do_masked_user_access() 0
 #define masked_user_access_begin(src) NULL
+#define mask_user_address(src) (src)
 #endif

@@ -159,19 +160,27 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)
 {
   unsigned long res = n;
   might_fault();
-  if (!should_fail_usercopy() && likely(access_ok(from, n))) {
+  if (should_fail_usercopy())
+    goto fail;
+  if (can_do_masked_user_access())
+    from = mask_user_address(from);
+  else {
+    if (!access_ok(from, n))
+      goto fail;
      /*
       * Ensure that bad access_ok() speculation will not
       * lead to nasty side effects *after* the copy is
       * finished:
       */
      barrier_nospec();
-    instrument_copy_from_user_before(to, from, n);
-    res = raw_copy_from_user(to, from, n);
-    instrument_copy_from_user_after(to, from, n, res);
   }
-  if (unlikely(res))
-    memset(to + (n - res), 0, res);
+  instrument_copy_from_user_before(to, from, n);
+  res = raw_copy_from_user(to, from, n);
+  instrument_copy_from_user_after(to, from, n, res);
+  if (likely(!res))
+    return 0;
+fail:
+  memset(to + (n - res), 0, res);
   return res;
 }
 extern __must_check unsigned long

The patch has been merged into the Linux kernel Git repository and will be part of the Linux 6.12 stable release scheduled for late November.

For full details, see the commit announcement: https://git.kernel.org/.../commit/?id=0fc810ae3ae110f9e2fcccce80fc8c8d62f97907

Performance Optimizationbenchmarkcopy_from_userLinux KernelPatch
Java Tech Enthusiast
Written by

Java Tech Enthusiast

Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.