From 0d83b8a9f180436a84fbdeb575696b0c3ae0ac0c Mon Sep 17 00:00:00 2001 From: Caleb Sander Mateos Date: Tue, 4 Mar 2025 12:48:12 -0700 Subject: io_uring: introduce io_cache_free() helper Add a helper function io_cache_free() that returns an allocation to a io_alloc_cache, falling back on kfree() if the io_alloc_cache is full. This is the inverse of io_cache_alloc(), which takes an allocation from an io_alloc_cache and falls back on kmalloc() if the cache is empty. Convert 4 callers to use the helper. Signed-off-by: Caleb Sander Mateos Suggested-by: Li Zetao Link: https://lore.kernel.org/r/20250304194814.2346705-1-csander@purestorage.com Signed-off-by: Jens Axboe --- io_uring/alloc_cache.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'io_uring/alloc_cache.h') diff --git a/io_uring/alloc_cache.h b/io_uring/alloc_cache.h index 0dd17d8ba93a..7f68eff2e7f3 100644 --- a/io_uring/alloc_cache.h +++ b/io_uring/alloc_cache.h @@ -68,4 +68,10 @@ static inline void *io_cache_alloc(struct io_alloc_cache *cache, gfp_t gfp) return io_cache_alloc_new(cache, gfp); } +static inline void io_cache_free(struct io_alloc_cache *cache, void *obj) +{ + if (!io_alloc_cache_put(cache, obj)) + kfree(obj); +} + #endif -- cgit v1.2.3