Skip to content

Commit

Permalink
io_uring: defer alloc_hint update to io_file_bitmap_set()
Browse files Browse the repository at this point in the history
io_file_bitmap_get() returns a free bitmap slot, but if it isn't
used later, such as io_queue_rsrc_removal() returns error, in this
case, we should not update alloc_hint at all, which still should
be considered as a valid candidate for next io_file_bitmap_get()
calls.

To fix this issue, only update alloc_hint in io_file_bitmap_set().

Signed-off-by: Xiaoguang Wang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Xiaoguang Wang authored and axboe committed May 31, 2022
1 parent 8c71fe7 commit 4278a0d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -5419,15 +5419,11 @@ static int io_file_bitmap_get(struct io_ring_ctx *ctx)
unsigned long nr = ctx->nr_user_files;
int ret;

if (table->alloc_hint >= nr)
table->alloc_hint = 0;

do {
ret = find_next_zero_bit(table->bitmap, nr, table->alloc_hint);
if (ret != nr) {
table->alloc_hint = ret + 1;
if (ret != nr)
return ret;
}

if (!table->alloc_hint)
break;

Expand Down Expand Up @@ -9682,8 +9678,7 @@ static inline void io_file_bitmap_set(struct io_file_table *table, int bit)
{
WARN_ON_ONCE(test_bit(bit, table->bitmap));
__set_bit(bit, table->bitmap);
if (bit == table->alloc_hint)
table->alloc_hint++;
table->alloc_hint = bit + 1;
}

static inline void io_file_bitmap_clear(struct io_file_table *table, int bit)
Expand Down

0 comments on commit 4278a0d

Please sign in to comment.