Linux 7.1 Gets Rid Of Some Unnecessary Memory Clobbers
Posted by adriano26@reddit | linux | View on Reddit | 4 comments
Posted by adriano26@reddit | linux | View on Reddit | 4 comments
jar36@reddit
Always improving. Gotta love it
BCMM@reddit
In case anybody needs some context for this: GCC (and clang) supports an extension to C which allows you to use little bits of assembly within C source files. Linux makes fairly extensive use of this feature for low-level stuff.
The compiler makes various optimisation in the course of building the kernel. For example, it keeps data in the CPU's registers wherever possible, so a lot of the time, using a variable in the source doesn't actually cause a read from main memory at runtime.
Inline assembly introduces code that the compiler didn't generate and does not understand. As such, a block of assembly is required to declare everything that it might have touched, so the compiler can make sure it doesn't make assumptions like "register X contains the same data as memory location Y", if those assumptions might not be true.
This commit removes the flag warning the compiler that the asm might have changed something in memory from a couple of functions which do not, in fact, mess with memory.
mveinot@reddit
Extremely helpful context, thank you.
adriano26@reddit (OP)
"Bizjak found the memory clobber to act as a compiler barrier is unnecessary from the kernel's FS/GS base accessors as they are only reading the FS/GS base MSRs into a general purpose register and not accessing memory. The other patch removes a memory clobber from savesegment() since it too is not accessing memory and avoids the need to declare a memory clobber."