diff mbox series

[v3] io_uring: defer alloc_hint update to io_file_bitmap_set()

Message ID 20220528015109.48039-1-xiaoguang.wang@linux.alibaba.com (mailing list archive)
State New
Headers show
Series [v3] io_uring: defer alloc_hint update to io_file_bitmap_set() | expand

Commit Message

Xiaoguang Wang May 28, 2022, 1:51 a.m. UTC
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 <xiaoguang.wang@linux.alibaba.com>
---
v3:
  Revert io_file_bitmap_set() type changes.
V2:
  Delete unnecessary check against to alloc_hint.
---
 fs/io_uring.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Jens Axboe May 28, 2022, 2:14 a.m. UTC | #1
On Sat, 28 May 2022 09:51:09 +0800, Xiaoguang Wang wrote:
> 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().
> 
> [...]

Applied, thanks!

[1/1] io_uring: defer alloc_hint update to io_file_bitmap_set()
      commit: e2d547c6e3caa4b6278bcb30686e1faf6777b3f6

Best regards,
diff mbox series

Patch

diff --git a/fs/io_uring.c b/fs/io_uring.c
index ff50e5f1753d..8f476e8760bf 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -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;
 
@@ -9654,8 +9650,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)