* [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
@ 2025-03-19 0:46 Mateusz Guzik
2025-03-19 8:28 ` Christian Brauner
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Mateusz Guzik @ 2025-03-19 0:46 UTC (permalink / raw)
To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel, Mateusz Guzik
While this may sound like a pedantic clean up, it does in fact impact
code generation -- the patched add routine is slightly smaller.
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
Below is disasm before/after. I did not want to pull this into the
commit message because of the total length vs long term usefulness ratio.
can be moved up into the commit message no problem if someone insists on
it:
(gdb) disassemble inode_sb_list_add
before:
<+0>: endbr64
<+4>: call 0xffffffff8130e9b0 <__fentry__>
<+9>: push %rbx
<+10>: mov 0x28(%rdi),%rax
<+14>: mov %rdi,%rbx
<+17>: lea 0x540(%rax),%rdi
<+24>: call 0xffffffff8225cf20 <_raw_spin_lock>
<+29>: mov 0x28(%rbx),%rax
<+33>: lea 0x110(%rbx),%rdx
<+40>: mov 0x548(%rax),%rcx
<+47>: mov %rdx,0x8(%rcx)
<+51>: mov %rcx,0x110(%rbx)
<+58>: lea 0x548(%rax),%rcx
<+65>: mov %rcx,0x118(%rbx)
<+72>: mov %rdx,0x548(%rax)
<+79>: mov 0x28(%rbx),%rdi
<+83>: pop %rbx
<+84>: add $0x540,%rdi
<+91>: jmp 0xffffffff8225d020 <_raw_spin_unlock>
after:
<+0>: endbr64
<+4>: call 0xffffffff8130e9b0 <__fentry__>
<+9>: push %r12
<+11>: push %rbp
<+12>: push %rbx
<+13>: mov 0x28(%rdi),%rbp
<+17>: mov %rdi,%rbx
<+20>: lea 0x540(%rbp),%r12
<+27>: mov %r12,%rdi
<+30>: call 0xffffffff8225cf20 <_raw_spin_lock>
<+35>: mov 0x548(%rbp),%rdx
<+42>: lea 0x110(%rbx),%rax
<+49>: mov %r12,%rdi
<+52>: mov %rax,0x8(%rdx)
<+56>: mov %rdx,0x110(%rbx)
<+63>: lea 0x548(%rbp),%rdx
<+70>: mov %rdx,0x118(%rbx)
<+77>: mov %rax,0x548(%rbp)
<+84>: pop %rbx
<+85>: pop %rbp
<+86>: pop %r12
<+88>: jmp 0xffffffff8225d020 <_raw_spin_unlock>
fs/inode.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index 10121fc7b87e..e188bb1eb07a 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -623,18 +623,22 @@ static void inode_wait_for_lru_isolating(struct inode *inode)
*/
void inode_sb_list_add(struct inode *inode)
{
- spin_lock(&inode->i_sb->s_inode_list_lock);
- list_add(&inode->i_sb_list, &inode->i_sb->s_inodes);
- spin_unlock(&inode->i_sb->s_inode_list_lock);
+ struct super_block *sb = inode->i_sb;
+
+ spin_lock(&sb->s_inode_list_lock);
+ list_add(&inode->i_sb_list, &sb->s_inodes);
+ spin_unlock(&sb->s_inode_list_lock);
}
EXPORT_SYMBOL_GPL(inode_sb_list_add);
static inline void inode_sb_list_del(struct inode *inode)
{
+ struct super_block *sb = inode->i_sb;
+
if (!list_empty(&inode->i_sb_list)) {
- spin_lock(&inode->i_sb->s_inode_list_lock);
+ spin_lock(&sb->s_inode_list_lock);
list_del_init(&inode->i_sb_list);
- spin_unlock(&inode->i_sb->s_inode_list_lock);
+ spin_unlock(&sb->s_inode_list_lock);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
2025-03-19 0:46 [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del} Mateusz Guzik
@ 2025-03-19 8:28 ` Christian Brauner
2025-03-19 8:28 ` Christian Brauner
2025-03-19 16:11 ` Jan Kara
2 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2025-03-19 8:28 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: viro, jack, linux-kernel, linux-fsdevel
On Wed, Mar 19, 2025 at 01:46:35AM +0100, Mateusz Guzik wrote:
> While this may sound like a pedantic clean up, it does in fact impact
It also makes it easier to read. So +1.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
2025-03-19 0:46 [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del} Mateusz Guzik
2025-03-19 8:28 ` Christian Brauner
@ 2025-03-19 8:28 ` Christian Brauner
2025-03-19 16:11 ` Jan Kara
2 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2025-03-19 8:28 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: Christian Brauner, viro, jack, linux-kernel, linux-fsdevel
On Wed, 19 Mar 2025 01:46:35 +0100, Mateusz Guzik wrote:
> While this may sound like a pedantic clean up, it does in fact impact
> code generation -- the patched add routine is slightly smaller.
>
>
Applied to the vfs-6.15.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.15.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.15.misc
[1/1] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
https://git.kernel.org/vfs/vfs/c/5a607aa94398
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
2025-03-19 0:46 [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del} Mateusz Guzik
2025-03-19 8:28 ` Christian Brauner
2025-03-19 8:28 ` Christian Brauner
@ 2025-03-19 16:11 ` Jan Kara
2025-03-19 16:14 ` Matthew Wilcox
2025-03-19 16:16 ` Mateusz Guzik
2 siblings, 2 replies; 7+ messages in thread
From: Jan Kara @ 2025-03-19 16:11 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: brauner, viro, jack, linux-kernel, linux-fsdevel
On Wed 19-03-25 01:46:35, Mateusz Guzik wrote:
> While this may sound like a pedantic clean up, it does in fact impact
> code generation -- the patched add routine is slightly smaller.
>
> Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
I'm surprised it matters for the compiler but as Christian wrote, why not.
Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
>
> Below is disasm before/after. I did not want to pull this into the
> commit message because of the total length vs long term usefulness ratio.
>
> can be moved up into the commit message no problem if someone insists on
> it:
>
> (gdb) disassemble inode_sb_list_add
> before:
> <+0>: endbr64
> <+4>: call 0xffffffff8130e9b0 <__fentry__>
> <+9>: push %rbx
> <+10>: mov 0x28(%rdi),%rax
> <+14>: mov %rdi,%rbx
> <+17>: lea 0x540(%rax),%rdi
> <+24>: call 0xffffffff8225cf20 <_raw_spin_lock>
> <+29>: mov 0x28(%rbx),%rax
> <+33>: lea 0x110(%rbx),%rdx
> <+40>: mov 0x548(%rax),%rcx
> <+47>: mov %rdx,0x8(%rcx)
> <+51>: mov %rcx,0x110(%rbx)
> <+58>: lea 0x548(%rax),%rcx
> <+65>: mov %rcx,0x118(%rbx)
> <+72>: mov %rdx,0x548(%rax)
> <+79>: mov 0x28(%rbx),%rdi
> <+83>: pop %rbx
> <+84>: add $0x540,%rdi
> <+91>: jmp 0xffffffff8225d020 <_raw_spin_unlock>
>
> after:
> <+0>: endbr64
> <+4>: call 0xffffffff8130e9b0 <__fentry__>
> <+9>: push %r12
> <+11>: push %rbp
> <+12>: push %rbx
> <+13>: mov 0x28(%rdi),%rbp
> <+17>: mov %rdi,%rbx
> <+20>: lea 0x540(%rbp),%r12
> <+27>: mov %r12,%rdi
> <+30>: call 0xffffffff8225cf20 <_raw_spin_lock>
> <+35>: mov 0x548(%rbp),%rdx
> <+42>: lea 0x110(%rbx),%rax
> <+49>: mov %r12,%rdi
> <+52>: mov %rax,0x8(%rdx)
> <+56>: mov %rdx,0x110(%rbx)
> <+63>: lea 0x548(%rbp),%rdx
> <+70>: mov %rdx,0x118(%rbx)
> <+77>: mov %rax,0x548(%rbp)
> <+84>: pop %rbx
> <+85>: pop %rbp
> <+86>: pop %r12
> <+88>: jmp 0xffffffff8225d020 <_raw_spin_unlock>
>
> fs/inode.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/fs/inode.c b/fs/inode.c
> index 10121fc7b87e..e188bb1eb07a 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -623,18 +623,22 @@ static void inode_wait_for_lru_isolating(struct inode *inode)
> */
> void inode_sb_list_add(struct inode *inode)
> {
> - spin_lock(&inode->i_sb->s_inode_list_lock);
> - list_add(&inode->i_sb_list, &inode->i_sb->s_inodes);
> - spin_unlock(&inode->i_sb->s_inode_list_lock);
> + struct super_block *sb = inode->i_sb;
> +
> + spin_lock(&sb->s_inode_list_lock);
> + list_add(&inode->i_sb_list, &sb->s_inodes);
> + spin_unlock(&sb->s_inode_list_lock);
> }
> EXPORT_SYMBOL_GPL(inode_sb_list_add);
>
> static inline void inode_sb_list_del(struct inode *inode)
> {
> + struct super_block *sb = inode->i_sb;
> +
> if (!list_empty(&inode->i_sb_list)) {
> - spin_lock(&inode->i_sb->s_inode_list_lock);
> + spin_lock(&sb->s_inode_list_lock);
> list_del_init(&inode->i_sb_list);
> - spin_unlock(&inode->i_sb->s_inode_list_lock);
> + spin_unlock(&sb->s_inode_list_lock);
> }
> }
>
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
2025-03-19 16:11 ` Jan Kara
@ 2025-03-19 16:14 ` Matthew Wilcox
2025-03-19 16:16 ` Mateusz Guzik
1 sibling, 0 replies; 7+ messages in thread
From: Matthew Wilcox @ 2025-03-19 16:14 UTC (permalink / raw)
To: Jan Kara; +Cc: Mateusz Guzik, brauner, viro, linux-kernel, linux-fsdevel
On Wed, Mar 19, 2025 at 05:11:25PM +0100, Jan Kara wrote:
> On Wed 19-03-25 01:46:35, Mateusz Guzik wrote:
> > While this may sound like a pedantic clean up, it does in fact impact
> > code generation -- the patched add routine is slightly smaller.
> >
> > Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
>
> I'm surprised it matters for the compiler but as Christian wrote, why not.
> Feel free to add:
I suspect it's because there's a spin_lock() involved. The barriers
we have probably mean we've told the compiler that it can't cache the
value loaded before the spin_lock().
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
2025-03-19 16:11 ` Jan Kara
2025-03-19 16:14 ` Matthew Wilcox
@ 2025-03-19 16:16 ` Mateusz Guzik
2025-03-19 16:36 ` Jan Kara
1 sibling, 1 reply; 7+ messages in thread
From: Mateusz Guzik @ 2025-03-19 16:16 UTC (permalink / raw)
To: Jan Kara; +Cc: brauner, viro, linux-kernel, linux-fsdevel
On Wed, Mar 19, 2025 at 5:11 PM Jan Kara <jack@suse.cz> wrote:
>
> On Wed 19-03-25 01:46:35, Mateusz Guzik wrote:
> > While this may sound like a pedantic clean up, it does in fact impact
> > code generation -- the patched add routine is slightly smaller.
> >
> > Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
>
> I'm surprised it matters for the compiler but as Christian wrote, why not.
> Feel free to add:
>
In stock code the fence in spin_lock forces the compiler to load
->i_sb again -- as far as it knows it could have changed.
On the other this patch forces the compiler to remember the value for
the same reason, which turns out to produce less code.
--
Mateusz Guzik <mjguzik gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del}
2025-03-19 16:16 ` Mateusz Guzik
@ 2025-03-19 16:36 ` Jan Kara
0 siblings, 0 replies; 7+ messages in thread
From: Jan Kara @ 2025-03-19 16:36 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: Jan Kara, brauner, viro, linux-kernel, linux-fsdevel
On Wed 19-03-25 17:16:06, Mateusz Guzik wrote:
> On Wed, Mar 19, 2025 at 5:11 PM Jan Kara <jack@suse.cz> wrote:
> >
> > On Wed 19-03-25 01:46:35, Mateusz Guzik wrote:
> > > While this may sound like a pedantic clean up, it does in fact impact
> > > code generation -- the patched add routine is slightly smaller.
> > >
> > > Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
> >
> > I'm surprised it matters for the compiler but as Christian wrote, why not.
> > Feel free to add:
> >
>
> In stock code the fence in spin_lock forces the compiler to load
> ->i_sb again -- as far as it knows it could have changed.
>
> On the other this patch forces the compiler to remember the value for
> the same reason, which turns out to produce less code.
I see. Thanks for explanation!
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-03-19 16:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19 0:46 [PATCH] fs: load the ->i_sb pointer once in inode_sb_list_{add,del} Mateusz Guzik
2025-03-19 8:28 ` Christian Brauner
2025-03-19 8:28 ` Christian Brauner
2025-03-19 16:11 ` Jan Kara
2025-03-19 16:14 ` Matthew Wilcox
2025-03-19 16:16 ` Mateusz Guzik
2025-03-19 16:36 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox