public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 4/7] examples/zc: add a hugetlb option
Date: Tue, 21 Feb 2023 01:05:55 +0000	[thread overview]
Message-ID: <5173d9761815d23800c1b32e95e9f6ebfe10433b.1676941370.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Benchmark hugetlb sends

Signed-off-by: Pavel Begunkov <[email protected]>
---
 examples/send-zerocopy.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index 6092af9..3a80d3d 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -35,6 +35,8 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/mman.h>
+#include <linux/mman.h>
 
 #include "liburing.h"
 
@@ -46,6 +48,7 @@ static bool cfg_fixed_files = 1;
 static bool cfg_zc = 1;
 static int  cfg_nr_reqs = 8;
 static bool cfg_fixed_buf = 1;
+static bool cfg_hugetlb = 0;
 
 static int  cfg_family		= PF_UNSPEC;
 static int  cfg_payload_len;
@@ -55,7 +58,8 @@ static int  cfg_runtime_ms	= 4200;
 static socklen_t cfg_alen;
 static struct sockaddr_storage cfg_dst_addr;
 
-static char payload[IP_MAXPACKET] __attribute__((aligned(4096)));
+static char payload_buf[IP_MAXPACKET] __attribute__((aligned(4096)));
+static char *payload;
 
 /*
  * Implementation of error(3), prints an error message and exits.
@@ -277,7 +281,7 @@ static void usage(const char *filepath)
 
 static void parse_opts(int argc, char **argv)
 {
-	const int max_payload_len = sizeof(payload) -
+	const int max_payload_len = IP_MAXPACKET -
 				    sizeof(struct ipv6hdr) -
 				    sizeof(struct tcphdr) -
 				    40 /* max tcp options */;
@@ -289,7 +293,7 @@ static void parse_opts(int argc, char **argv)
 
 	cfg_payload_len = max_payload_len;
 
-	while ((c = getopt(argc, argv, "46D:p:s:t:n:z:b:k")) != -1) {
+	while ((c = getopt(argc, argv, "46D:p:s:t:n:z:b:l:")) != -1) {
 		switch (c) {
 		case '4':
 			if (cfg_family != PF_UNSPEC)
@@ -324,6 +328,9 @@ static void parse_opts(int argc, char **argv)
 		case 'b':
 			cfg_fixed_buf = strtoul(optarg, NULL, 0);
 			break;
+		case 'l':
+			cfg_hugetlb = strtoul(optarg, NULL, 0);
+			break;
 		}
 	}
 
@@ -344,6 +351,17 @@ int main(int argc, char **argv)
 
 	parse_opts(argc, argv);
 
+	payload = payload_buf;
+	if (cfg_hugetlb) {
+		payload = mmap(NULL, 2*1024*1024, PROT_READ | PROT_WRITE,
+				MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_2MB | MAP_ANONYMOUS,
+				-1, 0);
+		if (payload == MAP_FAILED) {
+			fprintf(stderr, "hugetlb alloc failed\n");
+			return 1;
+		}
+	}
+
 	cfg_test = argv[argc - 1];
 	if (!strcmp(cfg_test, "tcp"))
 		do_test(cfg_family, SOCK_STREAM, 0);
-- 
2.39.1


  parent reply	other threads:[~2023-02-21  1:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21  1:05 [PATCH liburing 0/7] test sends with huge pages Pavel Begunkov
2023-02-21  1:05 ` [PATCH liburing 1/7] tests/send: don't use a constant for page size Pavel Begunkov
2023-02-21  1:05 ` [PATCH liburing 2/7] send: improve buffer iteration Pavel Begunkov
2023-02-21  1:05 ` [PATCH liburing 3/7] send: test send with hugetlb Pavel Begunkov
2023-02-21  1:05 ` Pavel Begunkov [this message]
2023-02-21  1:05 ` [PATCH liburing 5/7] test/send: don't use SO_ZEROCOPY if not available Pavel Begunkov
2023-02-21  1:05 ` [PATCH liburing 6/7] tests/send: improve error reporting Pavel Begunkov
2023-02-21  1:05 ` [PATCH liburing 7/7] tests/send: sends with offsets Pavel Begunkov
2023-02-22 16:54 ` [PATCH liburing 0/7] test sends with huge pages 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=5173d9761815d23800c1b32e95e9f6ebfe10433b.1676941370.git.asml.silence@gmail.com \
    [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