mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-29 09:13:38 +00:00
efba1a9e65
Having cache entries linked using the hlist format brings no benefit, and also requires an unnecessary extra pointer address per cache entry. Use the internal io_wq_work_node single-linked list for the internal alloc caches (async_msghdr and async_poll) This is required to be able to use KASAN on cache entries, since we do not need to touch unused (and poisoned) cache entries when adding more entries to the list. Suggested-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Breno Leitao <leitao@debian.org> Link: https://lore.kernel.org/r/20230223164353.2839177-2-leitao@debian.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
57 lines
1.1 KiB
C
57 lines
1.1 KiB
C
#ifndef IOU_ALLOC_CACHE_H
|
|
#define IOU_ALLOC_CACHE_H
|
|
|
|
/*
|
|
* Don't allow the cache to grow beyond this size.
|
|
*/
|
|
#define IO_ALLOC_CACHE_MAX 512
|
|
|
|
struct io_cache_entry {
|
|
struct io_wq_work_node node;
|
|
};
|
|
|
|
static inline bool io_alloc_cache_put(struct io_alloc_cache *cache,
|
|
struct io_cache_entry *entry)
|
|
{
|
|
if (cache->nr_cached < IO_ALLOC_CACHE_MAX) {
|
|
cache->nr_cached++;
|
|
wq_stack_add_head(&entry->node, &cache->list);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache)
|
|
{
|
|
if (cache->list.next) {
|
|
struct io_cache_entry *entry;
|
|
|
|
entry = container_of(cache->list.next, struct io_cache_entry, node);
|
|
cache->list.next = cache->list.next->next;
|
|
cache->nr_cached--;
|
|
return entry;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static inline void io_alloc_cache_init(struct io_alloc_cache *cache)
|
|
{
|
|
cache->list.next = NULL;
|
|
cache->nr_cached = 0;
|
|
}
|
|
|
|
static inline void io_alloc_cache_free(struct io_alloc_cache *cache,
|
|
void (*free)(struct io_cache_entry *))
|
|
{
|
|
while (1) {
|
|
struct io_cache_entry *entry = io_alloc_cache_get(cache);
|
|
|
|
if (!entry)
|
|
break;
|
|
free(entry);
|
|
}
|
|
cache->nr_cached = 0;
|
|
}
|
|
#endif
|