summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-11-07 10:19:48 -0700
committerJens Axboe <axboe@kernel.dk>2021-11-07 18:53:27 -0700
commit06139aa1b856020b298fc51df8e8052e8c67c534 (patch)
treefeb73e1baa9a34539a5f5fd87ebdea8bb1263b6d
parentc3ee754b5aefef8a2e966b0d461145ebabafc33f (diff)
downloadliburing-huge.tar.gz
liburing-huge.tar.bz2
setup: cleanup memory accountinghuge
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/setup.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/setup.c b/src/setup.c
index 47d4612..6be968a 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -190,21 +190,22 @@ static int io_uring_alloc_huge(unsigned entries, struct io_uring_params *p,
{
unsigned long page_size = get_page_size();
unsigned sq_entries, cq_entries;
- size_t ring_mem, sqes_mem;
- int ret, mem_used = 0;
+ size_t mem_used;
void *ptr;
+ int ret;
ret = get_sq_cq_entries(entries, p, &sq_entries, &cq_entries);
if (ret)
return ret;
- sqes_mem = sq_entries * sizeof(struct io_uring_sqe);
- sqes_mem = (sqes_mem + page_size - 1) & ~(page_size - 1);
- ring_mem = cq_entries * sizeof(struct io_uring_cqe);
- ring_mem += sq_entries * sizeof(unsigned);
+ mem_used = sq_entries * sizeof(struct io_uring_sqe);
+ mem_used = (mem_used + page_size - 1) & ~(page_size - 1);
+ mem_used += cq_entries * sizeof(struct io_uring_cqe);
+ mem_used += (sq_entries + cq_entries) * sizeof(unsigned);
+ mem_used = (mem_used + page_size - 1) & ~(page_size - 1);
if (buf) {
- if (sqes_mem + ring_mem > buf_size)
+ if (mem_used > buf_size)
return -ENOMEM;
ptr = buf;
} else {
@@ -218,7 +219,12 @@ static int io_uring_alloc_huge(unsigned entries, struct io_uring_params *p,
sq->sqes = ptr;
memset(ptr, 0, buf_size);
- if (sqes_mem + ring_mem <= buf_size) {
+ if (mem_used <= buf_size) {
+ size_t sqes_mem;
+
+ sqes_mem = sq_entries * sizeof(struct io_uring_sqe);
+ sqes_mem = (sqes_mem + page_size - 1) & ~(page_size - 1);
+
sq->ring_ptr = (void *) sq->sqes + sqes_mem;
/* clear ring sizes, we have just one mmap() to undo */
cq->ring_sz = 0;
@@ -237,13 +243,6 @@ static int io_uring_alloc_huge(unsigned entries, struct io_uring_params *p,
cq->ring_sz = 0;
}
- /* add up memory used */
- mem_used += sqes_mem;
- mem_used += sq_entries * sizeof(unsigned int);
- mem_used += cq_entries * sizeof(unsigned int);
- /* round to full page */
- mem_used = (mem_used + page_size - 1) & ~(page_size - 1);
-
cq->ring_ptr = (void *) sq->ring_ptr;
p->sq_off.user_addr = (unsigned long) sq->sqes;
p->cq_off.user_addr = (unsigned long) sq->ring_ptr;