summaryrefslogtreecommitdiffstats
path: root/io_uring/io_uring.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2022-06-16 10:22:10 +0100
committerJens Axboe <axboe@kernel.dk>2022-07-24 18:39:13 -0600
commite6f89be61410ff5a0e690d87d7a308e81f0f5a71 (patch)
treead02b7970896cd600e7aceae3800197316d16d2f /io_uring/io_uring.c
parenta2cdd5193218c557b4ee7828017cce83f251e99a (diff)
downloadlinux-e6f89be61410ff5a0e690d87d7a308e81f0f5a71.tar.bz2
io_uring: introduce a struct for hash table
Instead of passing around a pointer to hash buckets, add a bit of type safety and wrap it into a structure. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/d65bc3faba537ec2aca9eabf334394936d44bd28.1655371007.git.asml.silence@gmail.com Reviewed-by: Hao Xu <howeyxu@tencent.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
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);