diff mbox series

[1/1] io_uring: fix poll/netmsg alloc caches

Message ID 0126812afc5845096c987c1003e2ec078eefcd8a.1680172256.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series [1/1] io_uring: fix poll/netmsg alloc caches | expand

Commit Message

Pavel Begunkov March 30, 2023, 10:31 a.m. UTC
We increase cache->nr_cached when we free into the cache but don't
decrease when we take from it, so in some time we'll get an empty
cache with cache->nr_cached larger than IO_ALLOC_CACHE_MAX, that fails
io_alloc_cache_put() and effectively disables caching.

Fixes: 9b797a37c4bd8 ("io_uring: add abstraction around apoll cache")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/alloc_cache.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Jens Axboe March 30, 2023, 12:54 p.m. UTC | #1
On 3/30/23 4:31 AM, Pavel Begunkov wrote:
> We increase cache->nr_cached when we free into the cache but don't
> decrease when we take from it, so in some time we'll get an empty
> cache with cache->nr_cached larger than IO_ALLOC_CACHE_MAX, that fails
> io_alloc_cache_put() and effectively disables caching.

This should go into 6.3 and be marked for stable, but it's against
the for-next branch. I have hand applied it as:

https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-6.3&id=fd30d1cdcc4ff405fc54765edf2e11b03f2ed4f3
diff mbox series

Patch

diff --git a/io_uring/alloc_cache.h b/io_uring/alloc_cache.h
index 3aba7b356320..2fbecaa3a1ba 100644
--- a/io_uring/alloc_cache.h
+++ b/io_uring/alloc_cache.h
@@ -31,6 +31,7 @@  static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *c
 		entry = container_of(cache->list.next, struct io_cache_entry, node);
 		kasan_unpoison_range(entry, cache->elem_size);
 		cache->list.next = cache->list.next->next;
+		cache->nr_cached--;
 		return entry;
 	}