public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: Ammar Faizi <[email protected]>,
	Pavel Begunkov <[email protected]>,
	Gilang Fachrezy <[email protected]>,
	VNLX Kernel Department <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>,
	io-uring Mailing List <[email protected]>
Subject: [PATCH liburing v1 2/2] register: Simplify `io_uring_register_file_alloc_range()` function
Date: Fri,  6 Jan 2023 22:42:59 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

From: Ammar Faizi <[email protected]>

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 <[email protected]>
---
 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


  parent reply	other threads:[~2023-01-06 15:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 15:42 [PATCH liburing v1 0/2] liburing micro-optimzation Ammar Faizi
2023-01-06 15:42 ` [PATCH liburing v1 1/2] nolibc: Fix bloated memset due to unexpected vectorization Ammar Faizi
2023-01-06 15:56   ` Alviro Iskandar Setiawan
2023-01-06 15:42 ` Ammar Faizi [this message]
2023-01-06 15:59   ` [PATCH liburing v1 2/2] register: Simplify `io_uring_register_file_alloc_range()` function Alviro Iskandar Setiawan
2023-01-06 17:08 ` [PATCH liburing v1 0/2] liburing micro-optimzation Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox