Skip to content

Commit

Permalink
io_uring: add ring freeing helper
Browse files Browse the repository at this point in the history
We do rings and sqes separately, move them into a helper that does both
the freeing and clearing of the memory.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed May 16, 2023
1 parent e27cef8 commit 9c189ee
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions io_uring/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,14 @@ static void io_mem_free(void *ptr)
free_compound_page(page);
}

static void io_rings_free(struct io_ring_ctx *ctx)
{
io_mem_free(ctx->rings);
io_mem_free(ctx->sq_sqes);
ctx->rings = NULL;
ctx->sq_sqes = NULL;
}

static void *io_mem_alloc(size_t size)
{
gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN | __GFP_COMP;
Expand Down Expand Up @@ -2852,8 +2860,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
mmdrop(ctx->mm_account);
ctx->mm_account = NULL;
}
io_mem_free(ctx->rings);
io_mem_free(ctx->sq_sqes);
io_rings_free(ctx);

percpu_ref_exit(&ctx->refs);
free_uid(ctx->user);
Expand Down Expand Up @@ -3682,15 +3689,13 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
else
size = array_size(sizeof(struct io_uring_sqe), p->sq_entries);
if (size == SIZE_MAX) {
io_mem_free(ctx->rings);
ctx->rings = NULL;
io_rings_free(ctx);
return -EOVERFLOW;
}

ptr = io_mem_alloc(size);
if (IS_ERR(ptr)) {
io_mem_free(ctx->rings);
ctx->rings = NULL;
io_rings_free(ctx);
return PTR_ERR(ptr);
}

Expand Down

0 comments on commit 9c189ee

Please sign in to comment.