Skip to content

Commit 23e4903

Browse files
mjguzikbrauner
authored andcommitted
fs: predict no error in close()
Vast majority of the time the system call returns 0. Letting the compiler know shortens the routine (119 -> 116) and the fast path. Disasm starting at the call to __fput_sync(): before: <+55>: call 0xffffffff816b0da0 <__fput_sync> <+60>: lea 0x201(%rbx),%eax <+66>: cmp $0x1,%eax <+69>: jbe 0xffffffff816ab707 <__x64_sys_close+103> <+71>: mov %ebx,%edx <+73>: movslq %ebx,%rax <+76>: and $0xfffffffd,%edx <+79>: cmp $0xfffffdfc,%edx <+85>: mov $0xfffffffffffffffc,%rdx <+92>: cmove %rdx,%rax <+96>: pop %rbx <+97>: pop %rbp <+98>: jmp 0xffffffff82242fa0 <__x86_return_thunk> <+103>: mov $0xfffffffffffffffc,%rax <+110>: jmp 0xffffffff816ab700 <__x64_sys_close+96> <+112>: mov $0xfffffffffffffff7,%rax <+119>: jmp 0xffffffff816ab700 <__x64_sys_close+96> after: <+56>: call 0xffffffff816b0da0 <__fput_sync> <+61>: xor %eax,%eax <+63>: test %ebp,%ebp <+65>: jne 0xffffffff816ab6ea <__x64_sys_close+74> <+67>: pop %rbx <+68>: pop %rbp <+69>: jmp 0xffffffff82242fa0 <__x86_return_thunk> # the jmp out <+74>: lea 0x201(%rbp),%edx <+80>: mov $0xfffffffffffffffc,%rax <+87>: cmp $0x1,%edx <+90>: jbe 0xffffffff816ab6e3 <__x64_sys_close+67> <+92>: mov %ebp,%edx <+94>: and $0xfffffffd,%edx <+97>: cmp $0xfffffdfc,%edx <+103>: cmovne %rbp,%rax <+107>: jmp 0xffffffff816ab6e3 <__x64_sys_close+67> <+109>: mov $0xfffffffffffffff7,%rax <+116>: jmp 0xffffffff816ab6e3 <__x64_sys_close+67> Signed-off-by: Mateusz Guzik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 2014c95 commit 23e4903

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/open.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,11 +1578,14 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
15781578
*/
15791579
__fput_sync(file);
15801580

1581+
if (likely(retval == 0))
1582+
return 0;
1583+
15811584
/* can't restart close syscall because file table entry was cleared */
1582-
if (unlikely(retval == -ERESTARTSYS ||
1583-
retval == -ERESTARTNOINTR ||
1584-
retval == -ERESTARTNOHAND ||
1585-
retval == -ERESTART_RESTARTBLOCK))
1585+
if (retval == -ERESTARTSYS ||
1586+
retval == -ERESTARTNOINTR ||
1587+
retval == -ERESTARTNOHAND ||
1588+
retval == -ERESTART_RESTARTBLOCK)
15861589
retval = -EINTR;
15871590

15881591
return retval;

0 commit comments

Comments
 (0)