From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, David Wei <dw@davidwei.uk>
Subject: [PATCH liburing v2 4/4] examples/zcrx: add refill queue allocation modes
Date: Mon, 21 Apr 2025 08:25:32 +0100 [thread overview]
Message-ID: <694d179e262574db3e74d08809d722583af007f6.1745220124.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1745220124.git.asml.silence@gmail.com>
Refill queue creating is backed by the region api, which can either be
user or kernel allocated. Add an option to switch between the modes.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
examples/zcrx.c | 46 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/examples/zcrx.c b/examples/zcrx.c
index e5c3c6ec..40a4f0ad 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -39,6 +39,13 @@
#include "liburing.h"
#include "helpers.h"
+enum {
+ RQ_ALLOC_USER,
+ RQ_ALLOC_KERNEL,
+
+ __RQ_ALLOC_MAX,
+};
+
static long page_size;
#define AREA_SIZE (8192 * page_size)
#define SEND_SIZE (512 * 4096)
@@ -56,6 +63,7 @@ static const char *cfg_ifname;
static int cfg_queue_id = -1;
static bool cfg_verify_data = false;
static size_t cfg_size = 0;
+static unsigned cfg_rq_alloc_mode = RQ_ALLOC_USER;
static struct sockaddr_in6 cfg_addr;
static void *area_ptr;
@@ -80,6 +88,7 @@ static void setup_zcrx(struct io_uring *ring)
{
unsigned int ifindex;
unsigned int rq_entries = 4096;
+ unsigned rq_flags = 0;
int ret;
ifindex = if_nametoindex(cfg_ifname);
@@ -96,19 +105,22 @@ static void setup_zcrx(struct io_uring *ring)
t_error(1, 0, "mmap(): zero copy area");
ring_size = get_refill_ring_size(rq_entries);
- ring_ptr = mmap(NULL,
- ring_size,
- PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE,
- 0,
- 0);
- if (ring_ptr == MAP_FAILED)
- t_error(1, 0, "mmap(): refill ring");
+
+ ring_ptr = NULL;
+ if (cfg_rq_alloc_mode == RQ_ALLOC_USER) {
+ ring_ptr = mmap(NULL, ring_size,
+ PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE,
+ 0, 0);
+ if (ring_ptr == MAP_FAILED)
+ t_error(1, 0, "mmap(): refill ring");
+ rq_flags |= IORING_MEM_REGION_TYPE_USER;
+ }
struct io_uring_region_desc region_reg = {
.size = ring_size,
.user_addr = (__u64)(unsigned long)ring_ptr,
- .flags = IORING_MEM_REGION_TYPE_USER,
+ .flags = rq_flags,
};
struct io_uring_zcrx_area_reg area_reg = {
@@ -129,6 +141,15 @@ static void setup_zcrx(struct io_uring *ring)
if (ret)
t_error(1, 0, "io_uring_register_ifq(): %d", ret);
+ if (cfg_rq_alloc_mode == RQ_ALLOC_KERNEL) {
+ ring_ptr = mmap(NULL, ring_size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_POPULATE,
+ ring->ring_fd, region_reg.mmap_offset);
+ if (ring_ptr == MAP_FAILED)
+ t_error(1, 0, "mmap(): refill ring");
+ }
+
rq_ring.khead = (unsigned int *)((char *)ring_ptr + reg.offsets.head);
rq_ring.ktail = (unsigned int *)((char *)ring_ptr + reg.offsets.tail);
rq_ring.rqes = (struct io_uring_zcrx_rqe *)((char *)ring_ptr + reg.offsets.rqes);
@@ -292,7 +313,7 @@ static void parse_opts(int argc, char **argv)
if (argc <= 1)
usage(argv[0]);
- while ((c = getopt(argc, argv, "vp:i:q:s:")) != -1) {
+ while ((c = getopt(argc, argv, "vp:i:q:s:r:")) != -1) {
switch (c) {
case 'p':
cfg_port = strtoul(optarg, NULL, 0);
@@ -309,6 +330,11 @@ static void parse_opts(int argc, char **argv)
case 'v':
cfg_verify_data = true;
break;
+ case 'r':
+ cfg_rq_alloc_mode = strtoul(optarg, NULL, 0);
+ if (cfg_rq_alloc_mode >= __RQ_ALLOC_MAX)
+ t_error(1, 0, "invalid RQ allocation mode");
+ break;
}
}
--
2.48.1
next prev parent reply other threads:[~2025-04-21 7:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-21 7:25 [PATCH liburing v2 0/4] zcrx refill queue allocation modes Pavel Begunkov
2025-04-21 7:25 ` [PATCH liburing v2 1/4] examples/zcrx: consolidate add_recvzc variants Pavel Begunkov
2025-04-21 7:25 ` [PATCH liburing v2 2/4] examples/zcrx: rework size limiting Pavel Begunkov
2025-04-21 7:25 ` [PATCH liburing v2 3/4] examples/zcrx: constants for request types Pavel Begunkov
2025-04-21 7:25 ` Pavel Begunkov [this message]
2025-04-21 15:26 ` [PATCH liburing v2 0/4] zcrx refill queue allocation modes 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 \
--in-reply-to=694d179e262574db3e74d08809d722583af007f6.1745220124.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=dw@davidwei.uk \
--cc=io-uring@vger.kernel.org \
/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