public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH liburing 0/2] huge page support for the zcrx examples
@ 2025-04-23 11:58 Pavel Begunkov
  2025-04-23 11:58 ` [PATCH liburing 1/2] examples/zcrx: fix final recvzc CQE handling Pavel Begunkov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pavel Begunkov @ 2025-04-23 11:58 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence, David Wei

Patch 1 is a fix, followed by adding an option to allocate the area
as huge pages.

Pavel Begunkov (2):
  examples/zcrx: fix final recvzc CQE handling
  examples/zcrx: add huge page backed areas

 examples/zcrx.c | 58 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 18 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH liburing 1/2] examples/zcrx: fix final recvzc CQE handling
  2025-04-23 11:58 [PATCH liburing 0/2] huge page support for the zcrx examples Pavel Begunkov
@ 2025-04-23 11:58 ` Pavel Begunkov
  2025-04-23 11:58 ` [PATCH liburing 2/2] examples/zcrx: add huge page backed areas Pavel Begunkov
  2025-04-23 20:00 ` [PATCH liburing 0/2] huge page support for the zcrx examples Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2025-04-23 11:58 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence, David Wei

The last CQE of a zcrx request, i.e. without IORING_CQE_F_MORE,
doesn't have a buffer attached, don't fall through to buffer handling.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 examples/zcrx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/zcrx.c b/examples/zcrx.c
index 40a4f0ad..3073c4c5 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -220,6 +220,7 @@ static void process_recvzc(struct io_uring __attribute__((unused)) *ring,
 			t_error(1, 0, "total receive size mismatch %lu / %lu",
 				received, cfg_size);
 		stop = true;
+		return;
 	}
 	if (cqe->res < 0)
 		t_error(1, 0, "recvzc(): %d", cqe->res);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH liburing 2/2] examples/zcrx: add huge page backed areas
  2025-04-23 11:58 [PATCH liburing 0/2] huge page support for the zcrx examples Pavel Begunkov
  2025-04-23 11:58 ` [PATCH liburing 1/2] examples/zcrx: fix final recvzc CQE handling Pavel Begunkov
@ 2025-04-23 11:58 ` Pavel Begunkov
  2025-04-23 20:00 ` [PATCH liburing 0/2] huge page support for the zcrx examples Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2025-04-23 11:58 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence, David Wei

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 examples/zcrx.c | 57 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 39 insertions(+), 18 deletions(-)

diff --git a/examples/zcrx.c b/examples/zcrx.c
index 3073c4c5..d31c5b36 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 #include <sys/un.h>
 #include <sys/wait.h>
+#include <linux/mman.h>
 
 #include "liburing.h"
 #include "helpers.h"
@@ -48,12 +49,17 @@ enum {
 
 static long page_size;
 #define AREA_SIZE (8192 * page_size)
-#define SEND_SIZE (512 * 4096)
 
 #define REQ_TYPE_SHIFT	3
 #define REQ_TYPE_MASK	((1UL << REQ_TYPE_SHIFT) - 1)
 
-enum request_type {
+enum {
+	AREA_TYPE_NORMAL,
+	AREA_TYPE_HUGE_PAGES,
+	__AREA_TYPE_MAX,
+};
+
+enum {
 	REQ_TYPE_ACCEPT		= 1,
 	REQ_TYPE_RX		= 2,
 };
@@ -64,6 +70,7 @@ 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 unsigned cfg_area_type = AREA_TYPE_NORMAL;
 static struct sockaddr_in6 cfg_addr;
 
 static void *area_ptr;
@@ -84,8 +91,31 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries)
 	return T_ALIGN_UP(ring_size, page_size);
 }
 
+static void zcrx_populate_area(struct io_uring_zcrx_area_reg *area_reg)
+{
+	unsigned flags = MAP_PRIVATE | MAP_ANONYMOUS;
+	unsigned prot = PROT_READ | PROT_WRITE;
+
+	if (cfg_area_type == AREA_TYPE_NORMAL) {
+		area_ptr = mmap(NULL, AREA_SIZE, prot,
+				flags, 0, 0);
+	} else if (cfg_area_type == AREA_TYPE_HUGE_PAGES) {
+		area_ptr = mmap(NULL, AREA_SIZE, prot,
+				flags | MAP_HUGETLB | MAP_HUGE_2MB, -1, 0);
+	}
+
+	if (area_ptr == MAP_FAILED)
+		t_error(1, 0, "mmap(): area allocation failed");
+
+	memset(area_reg, 0, sizeof(*area_reg));
+	area_reg->addr = (__u64)(unsigned long)area_ptr;
+	area_reg->len = AREA_SIZE;
+	area_reg->flags = 0;
+}
+
 static void setup_zcrx(struct io_uring *ring)
 {
+	struct io_uring_zcrx_area_reg area_reg;
 	unsigned int ifindex;
 	unsigned int rq_entries = 4096;
 	unsigned rq_flags = 0;
@@ -95,17 +125,7 @@ static void setup_zcrx(struct io_uring *ring)
 	if (!ifindex)
 		t_error(1, 0, "bad interface name: %s", cfg_ifname);
 
-	area_ptr = mmap(NULL,
-			AREA_SIZE,
-			PROT_READ | PROT_WRITE,
-			MAP_ANONYMOUS | MAP_PRIVATE,
-			0,
-			0);
-	if (area_ptr == MAP_FAILED)
-		t_error(1, 0, "mmap(): zero copy area");
-
 	ring_size = get_refill_ring_size(rq_entries);
-
 	ring_ptr = NULL;
 	if (cfg_rq_alloc_mode == RQ_ALLOC_USER) {
 		ring_ptr = mmap(NULL, ring_size,
@@ -123,11 +143,7 @@ static void setup_zcrx(struct io_uring *ring)
 		.flags = rq_flags,
 	};
 
-	struct io_uring_zcrx_area_reg area_reg = {
-		.addr = (__u64)(unsigned long)area_ptr,
-		.len = AREA_SIZE,
-		.flags = 0,
-	};
+	zcrx_populate_area(&area_reg);
 
 	struct io_uring_zcrx_ifq_reg reg = {
 		.if_idx = ifindex,
@@ -314,7 +330,7 @@ static void parse_opts(int argc, char **argv)
 	if (argc <= 1)
 		usage(argv[0]);
 
-	while ((c = getopt(argc, argv, "vp:i:q:s:r:")) != -1) {
+	while ((c = getopt(argc, argv, "vp:i:q:s:r:A:")) != -1) {
 		switch (c) {
 		case 'p':
 			cfg_port = strtoul(optarg, NULL, 0);
@@ -336,6 +352,11 @@ static void parse_opts(int argc, char **argv)
 			if (cfg_rq_alloc_mode >= __RQ_ALLOC_MAX)
 				t_error(1, 0, "invalid RQ allocation mode");
 			break;
+		case 'A':
+			cfg_area_type = strtoul(optarg, NULL, 0);
+			if (cfg_area_type >= __AREA_TYPE_MAX)
+				t_error(1, 0, "Invalid area type");
+			break;
 		}
 	}
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH liburing 0/2] huge page support for the zcrx examples
  2025-04-23 11:58 [PATCH liburing 0/2] huge page support for the zcrx examples Pavel Begunkov
  2025-04-23 11:58 ` [PATCH liburing 1/2] examples/zcrx: fix final recvzc CQE handling Pavel Begunkov
  2025-04-23 11:58 ` [PATCH liburing 2/2] examples/zcrx: add huge page backed areas Pavel Begunkov
@ 2025-04-23 20:00 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-04-23 20:00 UTC (permalink / raw)
  To: io-uring, Pavel Begunkov; +Cc: David Wei


On Wed, 23 Apr 2025 12:58:36 +0100, Pavel Begunkov wrote:
> Patch 1 is a fix, followed by adding an option to allocate the area
> as huge pages.
> 
> Pavel Begunkov (2):
>   examples/zcrx: fix final recvzc CQE handling
>   examples/zcrx: add huge page backed areas
> 
> [...]

Applied, thanks!

[1/2] examples/zcrx: fix final recvzc CQE handling
      commit: 5af333652abf0bb2c8eb764f4f5221d91a55d945
[2/2] examples/zcrx: add huge page backed areas
      commit: fea11fe9b37b7944d1fdafe6daebbb3eb8e7abd0

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-23 20:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 11:58 [PATCH liburing 0/2] huge page support for the zcrx examples Pavel Begunkov
2025-04-23 11:58 ` [PATCH liburing 1/2] examples/zcrx: fix final recvzc CQE handling Pavel Begunkov
2025-04-23 11:58 ` [PATCH liburing 2/2] examples/zcrx: add huge page backed areas Pavel Begunkov
2025-04-23 20:00 ` [PATCH liburing 0/2] huge page support for the zcrx examples Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox