2023-08-12 13:02:33

by Mateusz Guzik

[permalink] [raw]
Subject: [PATCH] vfs: remove spin_lock_prefetch(&sb->s_inode_list_lock) from new_inode

It showed up in 2001, in the following commit in a historical repo [1]:

commit c37fa164f793735b32aa3f53154ff1a7659e6442
Author: linus1 <[email protected]>
Date: Thu Aug 16 11:00:00 2001 -0800

v2.4.9.9 -> v2.4.9.10

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 concede upfront I did not see value in benchmarking this change, but I
can do it if that is deemed appropriate.

Also worth nothing is that this was the only remaining consumer.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/fs/inode.c?id=c37fa164f793735b32aa3f53154ff1a7659e6442
Signed-off-by: Mateusz Guzik <[email protected]>
---
fs/inode.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 8fefb69e1f84..67611a360031 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -16,7 +16,6 @@
#include <linux/fsnotify.h>
#include <linux/mount.h>
#include <linux/posix_acl.h>
-#include <linux/prefetch.h>
#include <linux/buffer_head.h> /* for inode_has_buffers */
#include <linux/ratelimit.h>
#include <linux/list_lru.h>
@@ -1041,8 +1040,6 @@ struct inode *new_inode(struct super_block *sb)
{
struct inode *inode;

- spin_lock_prefetch(&sb->s_inode_list_lock);
-
inode = new_inode_pseudo(sb);
if (inode)
inode_sb_list_add(inode);
--
2.39.2



2023-08-12 15:54:43

by Linus Torvalds

[permalink] [raw]
Subject: Re: [PATCH] vfs: remove spin_lock_prefetch(&sb->s_inode_list_lock) from new_inode

On Sat, 12 Aug 2023 at 05:38, Mateusz Guzik <[email protected]> wrote:
>
> Also worth nothing is that this was the only remaining consumer.

Send a patch that also includes just removing the definition of that
thing, and I'll happily apply it.

Linus