Skip to content

Commit 8b1dfd3

Browse files
isilenceaxboe
authored andcommitted
io_uring: clean up io_ring_ctx_alloc
Add a variable for the number of hash buckets in io_ring_ctx_alloc(), makes it more readable. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/993926ed0d614ba9a76b2a85bebae2babcb13983.1655371007.git.asml.silence@gmail.com Reviewed-by: Hao Xu <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 4a07723 commit 8b1dfd3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

io_uring/io_uring.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ static __cold void io_fallback_req_func(struct work_struct *work)
244244
static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
245245
{
246246
struct io_ring_ctx *ctx;
247+
unsigned hash_buckets;
248+
size_t hash_size;
247249
int hash_bits;
248250

249251
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -259,15 +261,15 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
259261
*/
260262
hash_bits = ilog2(p->cq_entries) - 5;
261263
hash_bits = clamp(hash_bits, 1, 8);
264+
hash_buckets = 1U << hash_bits;
265+
hash_size = hash_buckets * sizeof(struct io_hash_bucket);
262266

263267
ctx->cancel_hash_bits = hash_bits;
264-
ctx->cancel_hash =
265-
kmalloc((1U << hash_bits) * sizeof(struct io_hash_bucket),
266-
GFP_KERNEL);
268+
ctx->cancel_hash = kmalloc(hash_size, GFP_KERNEL);
267269
if (!ctx->cancel_hash)
268270
goto err;
269271

270-
init_hash_table(ctx->cancel_hash, 1U << hash_bits);
272+
init_hash_table(ctx->cancel_hash, hash_buckets);
271273

272274
ctx->dummy_ubuf = kzalloc(sizeof(*ctx->dummy_ubuf), GFP_KERNEL);
273275
if (!ctx->dummy_ubuf)

0 commit comments

Comments
 (0)