[PATCH 2/4] io_uring/alloc_cache: mark cache success paths as likely

From: Caleb Sander Mateos

Date: Tue Nov 03 2026 - 16:14:12 EST


The point of a struct io_alloc_cache is to serve allocations from the
cache to avoid a call to kmalloc(). Only very high queue depth workloads
require more concurrent allocations than the fixed-size io_alloc_caches
can provide. So mark the success paths in io_alloc_cache_get() and
io_alloc_cache_put() as likely.

Signed-off-by: Caleb Sander Mateos <csander@xxxxxxxxxxxxxxx>
---
io_uring/alloc_cache.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/io_uring/alloc_cache.h b/io_uring/alloc_cache.h
index 962b6e2d04cc..aa007b380f1b 100644
--- a/io_uring/alloc_cache.h
+++ b/io_uring/alloc_cache.h
@@ -19,22 +19,22 @@ bool io_alloc_cache_init(struct io_alloc_cache *cache,
void *io_cache_alloc_new(struct io_alloc_cache *cache, gfp_t gfp);

static inline bool io_alloc_cache_put(struct io_alloc_cache *cache,
void *entry)
{
- if (cache->nr_cached < cache->max_cached) {
+ if (likely(cache->nr_cached < cache->max_cached)) {
if (!kasan_mempool_poison_object(entry))
return false;
cache->entries[cache->nr_cached++] = entry;
return true;
}
return false;
}

static inline void *io_alloc_cache_get(struct io_alloc_cache *cache)
{
- if (cache->nr_cached) {
+ if (likely(cache->nr_cached)) {
void *entry = cache->entries[--cache->nr_cached];

/*
* If KASAN is enabled, always clear the initial bytes that
* must be zeroed post alloc, in case any of them overlap
--
2.56.0