Skip to content

Commit

Permalink
io_uring: add helper to free all request caches
Browse files Browse the repository at this point in the history
We have three different ones, put it in a helper for easy calling. This
is in preparation for doing it outside of ring freeing as well. With
that in mind, also ensure that we do the proper locking for safe calling
from a context where the ring it still live.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jens Axboe committed Feb 13, 2021
1 parent 68e68ee commit 9a4fdbd
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -8693,10 +8693,27 @@ static void io_req_cache_free(struct list_head *list, struct task_struct *tsk)
}
}

static void io_ring_ctx_free(struct io_ring_ctx *ctx)
static void io_req_caches_free(struct io_ring_ctx *ctx, struct task_struct *tsk)
{
struct io_submit_state *submit_state = &ctx->submit_state;

mutex_lock(&ctx->uring_lock);

if (submit_state->free_reqs)
kmem_cache_free_bulk(req_cachep, submit_state->free_reqs,
submit_state->reqs);

io_req_cache_free(&submit_state->comp.free_list, NULL);

spin_lock_irq(&ctx->completion_lock);
io_req_cache_free(&submit_state->comp.locked_free_list, NULL);
spin_unlock_irq(&ctx->completion_lock);

mutex_unlock(&ctx->uring_lock);
}

static void io_ring_ctx_free(struct io_ring_ctx *ctx)
{
/*
* Some may use context even when all refs and requests have been put,
* and they are free to do so while still holding uring_lock, see
Expand All @@ -8715,10 +8732,6 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
ctx->mm_account = NULL;
}

if (submit_state->free_reqs)
kmem_cache_free_bulk(req_cachep, submit_state->free_reqs,
submit_state->reqs);

#ifdef CONFIG_BLK_CGROUP
if (ctx->sqo_blkcg_css)
css_put(ctx->sqo_blkcg_css);
Expand All @@ -8742,9 +8755,8 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
percpu_ref_exit(&ctx->refs);
free_uid(ctx->user);
put_cred(ctx->creds);
io_req_caches_free(ctx, NULL);
kfree(ctx->cancel_hash);
io_req_cache_free(&ctx->submit_state.comp.free_list, NULL);
io_req_cache_free(&ctx->submit_state.comp.locked_free_list, NULL);
kfree(ctx);
}

Expand Down

0 comments on commit 9a4fdbd

Please sign in to comment.