public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Jens Axboe <[email protected]>, Pavel Begunkov <[email protected]>
Cc: io-uring Mailing List <[email protected]>,
	Louvian Lyndal <[email protected]>,
	Ammar Faizi <[email protected]>,
	Ammar Faizi <[email protected]>
Subject: [PATCHSET v1 RFC liburing 4/6] Add `liburing_madvise()`
Date: Wed, 29 Sep 2021 17:16:04 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Do not use `madvise()` directly from the libc in the liburing internal
sources. Wrap them in `src/syscall.c`. This is the part of implementing
the kernel style return value (which later is supposed to support no
libc environment).

`liburing_madvise()` does the same thing with `madvise()` from the libc.
The only different is when error happens, the return value is of
`liburing_madvise()` will be a negative error code.

Signed-off-by: Ammar Faizi <[email protected]>
---
 src/setup.c   | 18 +++++++++---------
 src/syscall.c |  8 ++++++++
 src/syscall.h |  1 +
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/setup.c b/src/setup.c
index 01cb151..52f3557 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -120,20 +120,20 @@ int io_uring_ring_dontfork(struct io_uring *ring)
 		return -EINVAL;
 
 	len = *ring->sq.kring_entries * sizeof(struct io_uring_sqe);
-	ret = madvise(ring->sq.sqes, len, MADV_DONTFORK);
-	if (ret == -1)
-		return -errno;
+	ret = liburing_madvise(ring->sq.sqes, len, MADV_DONTFORK);
+	if (uring_unlikely(ret))
+		return ret;
 
 	len = ring->sq.ring_sz;
-	ret = madvise(ring->sq.ring_ptr, len, MADV_DONTFORK);
-	if (ret == -1)
-		return -errno;
+	ret = liburing_madvise(ring->sq.ring_ptr, len, MADV_DONTFORK);
+	if (uring_unlikely(ret))
+		return ret;
 
 	if (ring->cq.ring_ptr != ring->sq.ring_ptr) {
 		len = ring->cq.ring_sz;
-		ret = madvise(ring->cq.ring_ptr, len, MADV_DONTFORK);
-		if (ret == -1)
-			return -errno;
+		ret = liburing_madvise(ring->cq.ring_ptr, len, MADV_DONTFORK);
+		if (uring_unlikely(ret))
+			return ret;
 	}
 
 	return 0;
diff --git a/src/syscall.c b/src/syscall.c
index cb48a94..44861f6 100644
--- a/src/syscall.c
+++ b/src/syscall.c
@@ -133,3 +133,11 @@ int liburing_munmap(void *addr, size_t length)
 	ret = munmap(addr, length);
 	return (ret < 0) ? -errno : ret;
 }
+
+int liburing_madvise(void *addr, size_t length, int advice)
+{
+	int ret;
+
+	ret = madvise(addr, length, advice);
+	return (ret < 0) ? -errno : ret;
+}
diff --git a/src/syscall.h b/src/syscall.h
index feccf67..32381ce 100644
--- a/src/syscall.h
+++ b/src/syscall.h
@@ -29,5 +29,6 @@ int ____sys_io_uring_register(int fd, unsigned int opcode, const void *arg,
 void *liburing_mmap(void *addr, size_t length, int prot, int flags, int fd,
 		    off_t offset);
 int liburing_munmap(void *addr, size_t length);
+int liburing_madvise(void *addr, size_t length, int advice);
 
 #endif
-- 
2.30.2


  parent reply	other threads:[~2021-09-29 10:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 10:16 [PATCHSET v1 RFC liburing 0/6] Implement the kernel style return value Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 1/6] src/syscall: " Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 2/6] Add kernel error header `src/kernel_err.h` Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 3/6] Add `liburing_mmap()` and `liburing_munmap()` Ammar Faizi
2021-09-29 10:16 ` Ammar Faizi [this message]
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 5/6] Add `liburing_getrlimit()` and `liburing_setrlimit()` Ammar Faizi
2021-09-29 10:16 ` [PATCHSET v1 RFC liburing 6/6] src/{queue,register,setup}: Remove `#include <errno.h>` Ammar Faizi
2021-09-29 10:21 ` [PATCHSET v1 RFC liburing 0/6] Implement the kernel style return value Ammar Faizi
2021-10-01  6:44   ` Louvian Lyndal
2021-10-01  7:36     ` Ammar Faizi

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 \
    --in-reply-to=20210929101606.62822-5-ammar.faizi@students.amikom.ac.id \
    [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