[PATCH liburing v1 2/2] register: Simplify `io_uring_register_file_alloc_range()` function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>

Use a struct initializer instead of memset(). It simplifies the C code
plus effectively reduces the code size.

Extra bonus on x86-64. It reduces the stack allocation because it
doesn't need to allocate stack for the local variable @range. It can
just use 128 bytes of redzone below the `%rsp` (redzone is only
available in a leaf function).

Before this patch:

```
  0000000000003910 <io_uring_register_file_alloc_range>:
    3910:  push   %rbp
    3911:  push   %r15
    3913:  push   %r14
    3915:  push   %rbx
    3916:  sub    $0x18,%rsp
    391a:  mov    %edx,%r14d
    391d:  mov    %esi,%ebp
    391f:  mov    %rdi,%rbx
    3922:  lea    0x8(%rsp),%r15
    3927:  mov    $0x10,%edx
    392c:  mov    %r15,%rdi
    392f:  xor    %esi,%esi
    3931:  call   3a00 <__uring_memset>
    3936:  mov    %ebp,0x8(%rsp)
    393a:  mov    %r14d,0xc(%rsp)
    393f:  mov    0xc4(%rbx),%edi
    3945:  mov    $0x1ab,%eax
    394a:  mov    $0x19,%esi
    394f:  mov    %r15,%rdx
    3952:  xor    %r10d,%r10d
    3955:  syscall
    3957:  add    $0x18,%rsp
    395b:  pop    %rbx
    395c:  pop    %r14
    395e:  pop    %r15
    3960:  pop    %rbp
    3961:  ret
    3962:  cs nopw 0x0(%rax,%rax,1)
    396c:  nopl   0x0(%rax)
```

After this patch:

```
  0000000000003910 <io_uring_register_file_alloc_range>:
    3910:  mov    %esi,-0x10(%rsp) # set range.off
    3914:  mov    %edx,-0xc(%rsp)  # set range.len
    3918:  movq   $0x0,-0x8(%rsp)  # zero the resv
    3921:  mov    0xc4(%rdi),%edi
    3927:  lea    -0x10(%rsp),%rdx
    392c:  mov    $0x1ab,%eax
    3931:  mov    $0x19,%esi
    3936:  xor    %r10d,%r10d
    3939:  syscall
    393b:  ret
```

Signed-off-by: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>
---
 src/register.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/register.c b/src/register.c
index 5fdc6e5..ac4c9e3 100644
--- a/src/register.c
+++ b/src/register.c
@@ -333,11 +333,10 @@ int io_uring_register_sync_cancel(struct io_uring *ring,
 int io_uring_register_file_alloc_range(struct io_uring *ring,
 					unsigned off, unsigned len)
 {
-	struct io_uring_file_index_range range;
-
-	memset(&range, 0, sizeof(range));
-	range.off = off;
-	range.len = len;
+	struct io_uring_file_index_range range = {
+		.off = off,
+		.len = len
+	};
 
 	return __sys_io_uring_register(ring->ring_fd,
 				       IORING_REGISTER_FILE_ALLOC_RANGE, &range,
-- 
Ammar Faizi




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux