summaryrefslogtreecommitdiff
path: root/io_uring/io_uring.c
diff options
context:
space:
mode:
Diffstat (limited to 'io_uring/io_uring.c')
-rw-r--r--io_uring/io_uring.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 06772139b7da..0b3851a0db2b 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -241,11 +241,23 @@ static __cold void io_fallback_req_func(struct work_struct *work)
percpu_ref_put(&ctx->refs);
}
+static int io_alloc_hash_table(struct io_hash_table *table, unsigned bits)
+{
+ unsigned hash_buckets = 1U << bits;
+ size_t hash_size = hash_buckets * sizeof(table->hbs[0]);
+
+ table->hbs = kmalloc(hash_size, GFP_KERNEL);
+ if (!table->hbs)
+ return -ENOMEM;
+
+ table->hash_bits = bits;
+ init_hash_table(table, hash_buckets);
+ return 0;
+}
+
static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
{
struct io_ring_ctx *ctx;
- unsigned hash_buckets;
- size_t hash_size;
int hash_bits;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -261,16 +273,9 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
*/
hash_bits = ilog2(p->cq_entries) - 5;
hash_bits = clamp(hash_bits, 1, 8);
- hash_buckets = 1U << hash_bits;
- hash_size = hash_buckets * sizeof(struct io_hash_bucket);
-
- ctx->cancel_hash_bits = hash_bits;
- ctx->cancel_hash = kmalloc(hash_size, GFP_KERNEL);
- if (!ctx->cancel_hash)
+ if (io_alloc_hash_table(&ctx->cancel_table, hash_bits))
goto err;
- init_hash_table(ctx->cancel_hash, hash_buckets);
-
ctx->dummy_ubuf = kzalloc(sizeof(*ctx->dummy_ubuf), GFP_KERNEL);
if (!ctx->dummy_ubuf)
goto err;
@@ -311,7 +316,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
return ctx;
err:
kfree(ctx->dummy_ubuf);
- kfree(ctx->cancel_hash);
+ kfree(ctx->cancel_table.hbs);
kfree(ctx->io_bl);
xa_destroy(&ctx->io_bl_xa);
kfree(ctx);
@@ -2487,7 +2492,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
io_req_caches_free(ctx);
if (ctx->hash_map)
io_wq_put_hash(ctx->hash_map);
- kfree(ctx->cancel_hash);
+ kfree(ctx->cancel_table.hbs);
kfree(ctx->dummy_ubuf);
kfree(ctx->io_bl);
xa_destroy(&ctx->io_bl_xa);