Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

locking: remove spin_lock_prefetch

The only remaining consumer is new_inode, where it showed up in 2001 as
commit c37fa164f793 ("v2.4.9.9 -> v2.4.9.10") in a historical repo [1]
with a changelog which does not mention it.

Since then the line got only touched up to keep compiling.

While it may have been of benefit back in the day, it is guaranteed to
at best not get in the way in the multicore setting -- as the code
performs *a lot* of work between the prefetch and actual lock acquire,
any contention means the cacheline is already invalid by the time the
routine calls spin_lock(). It adds spurious traffic, for short.

On top of it prefetch is notoriously tricky to use for single-threaded
purposes, making it questionable from the get go.

As such, remove it.

I admit upfront I did not see value in benchmarking this change, but I
can do it if that is deemed appropriate.

Removal from new_inode and of the entire thing are in the same patch as
requested by Linus, so whatever weird looks can be directed at that guy.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/fs/inode.c?id=c37fa164f793735b32aa3f53154ff1a7659e6442 [1]
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Mateusz Guzik and committed by
Linus Torvalds
c8afaa1b 3feecb1b

+1 -47
-13
arch/alpha/include/asm/processor.h
··· 47 47 48 48 #define ARCH_HAS_PREFETCH 49 49 #define ARCH_HAS_PREFETCHW 50 - #define ARCH_HAS_SPINLOCK_PREFETCH 51 - 52 - #ifndef CONFIG_SMP 53 - /* Nothing to prefetch. */ 54 - #define spin_lock_prefetch(lock) do { } while (0) 55 - #endif 56 50 57 51 extern inline void prefetch(const void *ptr) 58 52 { ··· 57 63 { 58 64 __builtin_prefetch(ptr, 1, 3); 59 65 } 60 - 61 - #ifdef CONFIG_SMP 62 - extern inline void spin_lock_prefetch(const void *ptr) 63 - { 64 - __builtin_prefetch(ptr, 1, 3); 65 - } 66 - #endif 67 66 68 67 #endif /* __ASM_ALPHA_PROCESSOR_H */
-8
arch/arm64/include/asm/processor.h
··· 359 359 asm volatile("prfm pstl1keep, %a0\n" : : "p" (ptr)); 360 360 } 361 361 362 - #define ARCH_HAS_SPINLOCK_PREFETCH 363 - static inline void spin_lock_prefetch(const void *ptr) 364 - { 365 - asm volatile(ARM64_LSE_ATOMIC_INSN( 366 - "prfm pstl1strm, %a0", 367 - "nop") : : "p" (ptr)); 368 - } 369 - 370 362 extern unsigned long __ro_after_init signal_minsigstksz; /* sigframe size */ 371 363 extern void __init minsigstksz_setup(void); 372 364
-3
arch/ia64/include/asm/processor.h
··· 634 634 635 635 #define ARCH_HAS_PREFETCH 636 636 #define ARCH_HAS_PREFETCHW 637 - #define ARCH_HAS_SPINLOCK_PREFETCH 638 637 #define PREFETCH_STRIDE L1_CACHE_BYTES 639 638 640 639 static inline void ··· 647 648 { 648 649 ia64_lfetch_excl(ia64_lfhint_none, x); 649 650 } 650 - 651 - #define spin_lock_prefetch(x) prefetchw(x) 652 651 653 652 extern unsigned long boot_option_idle_override; 654 653
-2
arch/mips/include/asm/mach-cavium-octeon/cpu-feature-overrides.h
··· 58 58 59 59 #define cpu_has_rixi (cpu_data[0].cputype != CPU_CAVIUM_OCTEON) 60 60 61 - #define ARCH_HAS_SPINLOCK_PREFETCH 1 62 - #define spin_lock_prefetch(x) prefetch(x) 63 61 #define PREFETCH_STRIDE 128 64 62 65 63 #ifdef __OCTEON__
-3
arch/powerpc/include/asm/processor.h
··· 393 393 */ 394 394 #define ARCH_HAS_PREFETCH 395 395 #define ARCH_HAS_PREFETCHW 396 - #define ARCH_HAS_SPINLOCK_PREFETCH 397 396 398 397 static inline void prefetch(const void *x) 399 398 { ··· 409 410 410 411 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x)); 411 412 } 412 - 413 - #define spin_lock_prefetch(x) prefetchw(x) 414 413 415 414 /* asm stubs */ 416 415 extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
-3
arch/sparc/include/asm/processor_64.h
··· 213 213 */ 214 214 #define ARCH_HAS_PREFETCH 215 215 #define ARCH_HAS_PREFETCHW 216 - #define ARCH_HAS_SPINLOCK_PREFETCH 217 216 218 217 static inline void prefetch(const void *x) 219 218 { ··· 237 238 : /* no outputs */ 238 239 : "r" (x)); 239 240 } 240 - 241 - #define spin_lock_prefetch(x) prefetchw(x) 242 241 243 242 #define HAVE_ARCH_PICK_MMAP_LAYOUT 244 243
-6
arch/x86/include/asm/processor.h
··· 586 586 587 587 #define HAVE_ARCH_PICK_MMAP_LAYOUT 1 588 588 #define ARCH_HAS_PREFETCHW 589 - #define ARCH_HAS_SPINLOCK_PREFETCH 590 589 591 590 #ifdef CONFIG_X86_32 592 591 # define BASE_PREFETCH "" ··· 617 618 alternative_input(BASE_PREFETCH, "prefetchw %P1", 618 619 X86_FEATURE_3DNOWPREFETCH, 619 620 "m" (*(const char *)x)); 620 - } 621 - 622 - static inline void spin_lock_prefetch(const void *x) 623 - { 624 - prefetchw(x); 625 621 } 626 622 627 623 #define TOP_OF_INIT_STACK ((unsigned long)&init_stack + sizeof(init_stack) - \
-3
fs/inode.c
··· 16 16 #include <linux/fsnotify.h> 17 17 #include <linux/mount.h> 18 18 #include <linux/posix_acl.h> 19 - #include <linux/prefetch.h> 20 19 #include <linux/buffer_head.h> /* for inode_has_buffers */ 21 20 #include <linux/ratelimit.h> 22 21 #include <linux/list_lru.h> ··· 1039 1040 struct inode *new_inode(struct super_block *sb) 1040 1041 { 1041 1042 struct inode *inode; 1042 - 1043 - spin_lock_prefetch(&sb->s_inode_list_lock); 1044 1043 1045 1044 inode = new_inode_pseudo(sb); 1046 1045 if (inode)
+1 -6
include/linux/prefetch.h
··· 25 25 prefetch() should be defined by the architecture, if not, the 26 26 #define below provides a no-op define. 27 27 28 - There are 3 prefetch() macros: 28 + There are 2 prefetch() macros: 29 29 30 30 prefetch(x) - prefetches the cacheline at "x" for read 31 31 prefetchw(x) - prefetches the cacheline at "x" for write 32 - spin_lock_prefetch(x) - prefetches the spinlock *x for taking 33 32 34 33 there is also PREFETCH_STRIDE which is the architecure-preferred 35 34 "lookahead" size for prefetching streamed operations. ··· 41 42 42 43 #ifndef ARCH_HAS_PREFETCHW 43 44 #define prefetchw(x) __builtin_prefetch(x,1) 44 - #endif 45 - 46 - #ifndef ARCH_HAS_SPINLOCK_PREFETCH 47 - #define spin_lock_prefetch(x) prefetchw(x) 48 45 #endif 49 46 50 47 #ifndef PREFETCH_STRIDE