Skip to content

Commit 4a07723

Browse files
isilenceaxboe
authored andcommitted
io_uring: limit the number of cancellation buckets
Don't allocate to many hash/cancellation buckets, there might be too many, clamp it to 8 bits, or 256 * 64B = 16KB. We don't usually have too many requests, and 256 buckets should be enough, especially since we do hash search only in the cancellation path. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/b9620c8072ba61a2d50eba894b89bd93a94a9abd.1655371007.git.asml.silence@gmail.com Reviewed-by: Hao Xu <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 4dfab8a commit 4a07723

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

io_uring/io_uring.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
254254

255255
/*
256256
* Use 5 bits less than the max cq entries, that should give us around
257-
* 32 entries per hash list if totally full and uniformly spread.
257+
* 32 entries per hash list if totally full and uniformly spread, but
258+
* don't keep too many buckets to not overconsume memory.
258259
*/
259-
hash_bits = ilog2(p->cq_entries);
260-
hash_bits -= 5;
261-
if (hash_bits <= 0)
262-
hash_bits = 1;
260+
hash_bits = ilog2(p->cq_entries) - 5;
261+
hash_bits = clamp(hash_bits, 1, 8);
262+
263263
ctx->cancel_hash_bits = hash_bits;
264264
ctx->cancel_hash =
265265
kmalloc((1U << hash_bits) * sizeof(struct io_hash_bucket),

0 commit comments

Comments
 (0)