From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH liburing 4/4] test/reg-wait: test kernel allocated regions
Date: Wed, 20 Nov 2024 23:39:51 +0000 [thread overview]
Message-ID: <f6bcae3813e2792e0f1b5d65e00de7f33d21574a.1731987026.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 68 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 57 insertions(+), 11 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index d59e51b..299fbf1 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -413,6 +413,31 @@ static void t_region_free(struct t_region *r)
munmap(r->ptr, r->size);
}
+static int t_region_create_kernel(struct t_region *r,
+ struct io_uring *ring)
+{
+ struct io_uring_region_desc rd = { .size = r->size, };
+ struct io_uring_mem_region_reg mr = {
+ .region_uptr = (__u64)(unsigned long)&rd,
+ .flags = IORING_MEM_REGION_REG_WAIT_ARG,
+ };
+ void *p;
+ int ret;
+
+ ret = io_uring_register_region(ring, &mr);
+ if (ret)
+ return ret;
+
+ p = mmap(NULL, r->size, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_POPULATE, ring->ring_fd, rd.mmap_offset);
+ if (p == MAP_FAILED)
+ return -EFAULT;
+
+ r->ptr = p;
+ r->user_mem = false;
+ return 0;
+}
+
static int t_region_create_user(struct t_region *r,
struct io_uring *ring,
bool huge)
@@ -446,17 +471,36 @@ static int t_region_create_user(struct t_region *r,
return 0;
}
+struct test_param {
+ size_t size;
+ bool huge_page;
+ bool kern_buf;
+};
+
static int test_region_buffer_types(void)
{
const size_t huge_size = 1024 * 1024 * 2;
- const size_t map_sizes[] = { page_size, page_size * 2, page_size * 16,
- huge_size, 2 * huge_size};
+ struct test_param params[] = {
+ { .size = page_size },
+ /* forcing vmap */
+ { .size = page_size * 2 },
+ { .size = page_size * 16 },
+ /* huge page w/o vmap */
+ { .size = huge_size, .huge_page = true },
+ /* huge page w/ vmap */
+ { .size = huge_size * 2, .huge_page = true },
+ { .size = page_size, .kern_buf = true },
+ /* likely to be a compound page */
+ { .size = page_size * 2, .kern_buf = true },
+ { .size = page_size * 8, .kern_buf = true },
+ /* kernel allocation + vmap */
+ { .size = page_size * 512, .kern_buf = true },
+ };
struct io_uring ring;
- int sz_idx, ret;
+ int i, ret;
- for (sz_idx = 0; sz_idx < ARRAY_SIZE(map_sizes); sz_idx++) {
- size_t size = map_sizes[sz_idx];
- struct t_region r = { .size = size, };
+ for (i = 0; i < ARRAY_SIZE(params); i++) {
+ struct t_region r = { .size = params[i].size, };
ret = io_uring_queue_init(8, &ring, IORING_SETUP_R_DISABLED);
if (ret) {
@@ -464,12 +508,15 @@ static int test_region_buffer_types(void)
return ret;
}
- ret = t_region_create_user(&r, &ring, size >= huge_size);
+ if (params[i].kern_buf)
+ ret = t_region_create_kernel(&r, &ring);
+ else
+ ret = t_region_create_user(&r, &ring, params[i].huge_page);
if (ret) {
io_uring_queue_exit(&ring);
if (ret == -ENOMEM || ret == -EINVAL)
continue;
- fprintf(stderr, "t_region_create_user failed\n");
+ fprintf(stderr, "t_region_create_user failed, idx %i\n", i);
return 1;
}
@@ -479,10 +526,9 @@ static int test_region_buffer_types(void)
return ret;
}
- ret = test_offsets(&ring, r.ptr, size, false);
+ ret = test_offsets(&ring, r.ptr, r.size, false);
if (ret) {
- fprintf(stderr, "test_offsets failed, size %lu\n",
- (unsigned long)size);
+ fprintf(stderr, "test_offsets failed, idx %i\n", i);
return 1;
}
--
2.46.0
prev parent reply other threads:[~2024-11-20 23:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
2024-11-20 23:39 ` [PATCH liburing 1/4] tests/reg-wait: test registering RO memory Pavel Begunkov
2024-11-20 23:39 ` [PATCH liburing 2/4] test/reg-wait: basic test + probing of kernel regions Pavel Begunkov
2024-11-20 23:39 ` [PATCH liburing 3/4] test/reg-wait: add allocation abstraction Pavel Begunkov
2024-11-20 23:39 ` Pavel Begunkov [this message]
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=f6bcae3813e2792e0f1b5d65e00de7f33d21574a.1731987026.git.asml.silence@gmail.com \
[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