summaryrefslogtreecommitdiff
path: root/io_uring/alloc_cache.h
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2022-07-07 23:16:20 +0300
committerJens Axboe <axboe@kernel.dk>2022-07-25 03:39:17 +0300
commit9b797a37c4bd83b03cedcfbd15852b836f5e562c (patch)
treef01382c4665ad9276dd632b69a8ca9429f26f979 /io_uring/alloc_cache.h
parent9da7471ed10dab52410062be74896a6c0aa1bf3a (diff)
downloadlinux-9b797a37c4bd83b03cedcfbd15852b836f5e562c.tar.xz
io_uring: add abstraction around apoll cache
In preparation for adding limits, and one more user, abstract out the core bits of the allocation+free cache. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/alloc_cache.h')
-rw-r--r--io_uring/alloc_cache.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/io_uring/alloc_cache.h b/io_uring/alloc_cache.h
new file mode 100644
index 000000000000..98f2374c37c7
--- /dev/null
+++ b/io_uring/alloc_cache.h
@@ -0,0 +1,41 @@
+#ifndef IOU_ALLOC_CACHE_H
+#define IOU_ALLOC_CACHE_H
+
+struct io_cache_entry {
+ struct hlist_node node;
+};
+
+static inline void io_alloc_cache_put(struct io_alloc_cache *cache,
+ struct io_cache_entry *entry)
+{
+ hlist_add_head(&entry->node, &cache->list);
+}
+
+static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache)
+{
+ if (!hlist_empty(&cache->list)) {
+ struct hlist_node *node = cache->list.first;
+
+ hlist_del(node);
+ return container_of(node, struct io_cache_entry, node);
+ }
+
+ return NULL;
+}
+
+static inline void io_alloc_cache_init(struct io_alloc_cache *cache)
+{
+ INIT_HLIST_HEAD(&cache->list);
+}
+
+static inline void io_alloc_cache_free(struct io_alloc_cache *cache,
+ void (*free)(struct io_cache_entry *))
+{
+ while (!hlist_empty(&cache->list)) {
+ struct hlist_node *node = cache->list.first;
+
+ hlist_del(node);
+ free(container_of(node, struct io_cache_entry, node));
+ }
+}
+#endif