Skip to content

Commit 528407b

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: consolidate node caching
We store one pre-allocated rsrc node in ->rsrc_backup_node, merge it with ->rsrc_node_cache. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/6d5410e51ccd29be7a716be045b51d6b371baef6.1681210788.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 786788a commit 528407b

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

include/linux/io_uring_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ struct io_ring_ctx {
326326
struct io_restriction restrictions;
327327

328328
/* slow path rsrc auxilary data, used by update/register */
329-
struct io_rsrc_node *rsrc_backup_node;
330329
struct io_mapped_ubuf *dummy_ubuf;
331330
struct io_rsrc_data *file_data;
332331
struct io_rsrc_data *buf_data;

io_uring/alloc_cache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ static inline bool io_alloc_cache_put(struct io_alloc_cache *cache,
2323
return false;
2424
}
2525

26+
static inline bool io_alloc_cache_empty(struct io_alloc_cache *cache)
27+
{
28+
return !cache->list.next;
29+
}
30+
2631
static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache)
2732
{
2833
if (cache->list.next) {

io_uring/io_uring.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,8 +2852,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
28522852
/* there are no registered resources left, nobody uses it */
28532853
if (ctx->rsrc_node)
28542854
io_rsrc_node_destroy(ctx, ctx->rsrc_node);
2855-
if (ctx->rsrc_backup_node)
2856-
io_rsrc_node_destroy(ctx, ctx->rsrc_backup_node);
28572855

28582856
WARN_ON_ONCE(!list_empty(&ctx->rsrc_ref_list));
28592857

io_uring/rsrc.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void io_rsrc_node_switch(struct io_ring_ctx *ctx,
230230
struct io_rsrc_data *data_to_kill)
231231
__must_hold(&ctx->uring_lock)
232232
{
233-
WARN_ON_ONCE(!ctx->rsrc_backup_node);
233+
WARN_ON_ONCE(io_alloc_cache_empty(&ctx->rsrc_node_cache));
234234
WARN_ON_ONCE(data_to_kill && !ctx->rsrc_node);
235235

236236
if (data_to_kill) {
@@ -245,18 +245,20 @@ void io_rsrc_node_switch(struct io_ring_ctx *ctx,
245245
ctx->rsrc_node = NULL;
246246
}
247247

248-
if (!ctx->rsrc_node) {
249-
ctx->rsrc_node = ctx->rsrc_backup_node;
250-
ctx->rsrc_backup_node = NULL;
251-
}
248+
if (!ctx->rsrc_node)
249+
ctx->rsrc_node = io_rsrc_node_alloc(ctx);
252250
}
253251

254252
int io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
255253
{
256-
if (ctx->rsrc_backup_node)
257-
return 0;
258-
ctx->rsrc_backup_node = io_rsrc_node_alloc(ctx);
259-
return ctx->rsrc_backup_node ? 0 : -ENOMEM;
254+
if (io_alloc_cache_empty(&ctx->rsrc_node_cache)) {
255+
struct io_rsrc_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
256+
257+
if (!node)
258+
return -ENOMEM;
259+
io_alloc_cache_put(&ctx->rsrc_node_cache, &node->cache);
260+
}
261+
return 0;
260262
}
261263

262264
__cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,

0 commit comments

Comments
 (0)