Commit 8b1dfd34 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe
Browse files

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: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/993926ed0d614ba9a76b2a85bebae2babcb13983.1655371007.git.asml.silence@gmail.com


Reviewed-by: default avatarHao Xu <howeyxu@tencent.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 4a07723f
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -244,6 +244,8 @@ static __cold void io_fallback_req_func(struct work_struct *work)
static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
{
{
	struct io_ring_ctx *ctx;
	struct io_ring_ctx *ctx;
	unsigned hash_buckets;
	size_t hash_size;
	int hash_bits;
	int hash_bits;


	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
	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)
	 */
	 */
	hash_bits = ilog2(p->cq_entries) - 5;
	hash_bits = ilog2(p->cq_entries) - 5;
	hash_bits = clamp(hash_bits, 1, 8);
	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_bits = hash_bits;
	ctx->cancel_hash =
	ctx->cancel_hash = kmalloc(hash_size, GFP_KERNEL);
		kmalloc((1U << hash_bits) * sizeof(struct io_hash_bucket),
			GFP_KERNEL);
	if (!ctx->cancel_hash)
	if (!ctx->cancel_hash)
		goto err;
		goto err;


	init_hash_table(ctx->cancel_hash, 1U << hash_bits);
	init_hash_table(ctx->cancel_hash, hash_buckets);


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