1 #ifndef IOU_ALLOC_CACHE_H
2 #define IOU_ALLOC_CACHE_H
5 * Don't allow the cache to grow beyond this size.
7 #define IO_ALLOC_CACHE_MAX 512
9 struct io_cache_entry {
10 struct io_wq_work_node node;
13 static inline bool io_alloc_cache_put(struct io_alloc_cache *cache,
14 struct io_cache_entry *entry)
16 if (cache->nr_cached < cache->max_cached) {
18 wq_stack_add_head(&entry->node, &cache->list);
19 kasan_mempool_poison_object(entry);
25 static inline bool io_alloc_cache_empty(struct io_alloc_cache *cache)
27 return !cache->list.next;
30 static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache)
32 if (cache->list.next) {
33 struct io_cache_entry *entry;
35 entry = container_of(cache->list.next, struct io_cache_entry, node);
36 kasan_mempool_unpoison_object(entry, cache->elem_size);
37 cache->list.next = cache->list.next->next;
45 static inline void io_alloc_cache_init(struct io_alloc_cache *cache,
46 unsigned max_nr, size_t size)
48 cache->list.next = NULL;
50 cache->max_cached = max_nr;
51 cache->elem_size = size;
54 static inline void io_alloc_cache_free(struct io_alloc_cache *cache,
55 void (*free)(struct io_cache_entry *))
58 struct io_cache_entry *entry = io_alloc_cache_get(cache);