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
static void io_futex_complete(struct io_kiocb *req, io_tw_token_t tw)
{
- struct io_futex_data *ifd = req->async_data;
struct io_ring_ctx *ctx = req->ctx;
io_tw_lock(ctx, tw);
- if (!io_alloc_cache_put(&ctx->futex_cache, ifd))
- kfree(ifd);
+ io_cache_free(&ctx->futex_cache, req->async_data);
__io_futex_complete(req, tw);
}
if (apoll->double_poll)
kfree(apoll->double_poll);
- if (!io_alloc_cache_put(&ctx->apoll_cache, apoll))
- kfree(apoll);
+ io_cache_free(&ctx->apoll_cache, apoll);
req->flags &= ~REQ_F_POLLED;
}
if (req->flags & IO_REQ_LINK_FLAGS)
static void io_free_imu(struct io_ring_ctx *ctx, struct io_mapped_ubuf *imu)
{
- if (imu->nr_bvecs > IO_CACHED_BVECS_SEGS ||
- !io_alloc_cache_put(&ctx->imu_cache, imu))
+ if (imu->nr_bvecs <= IO_CACHED_BVECS_SEGS)
+ io_cache_free(&ctx->imu_cache, imu);
+ else
kvfree(imu);
}
return IOU_OK;
}
-static void io_free_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
-{
- if (!io_alloc_cache_put(&ctx->node_cache, node))
- kfree(node);
-}
-
void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
{
if (node->tag)
break;
}
- io_free_node(ctx, node);
+ io_cache_free(&ctx->node_cache, node);
}
int io_sqe_files_unregister(struct io_ring_ctx *ctx)
if (ret) {
if (imu)
io_free_imu(ctx, imu);
- io_free_node(ctx, node);
+ io_cache_free(&ctx->node_cache, node);
node = ERR_PTR(ret);
}
kvfree(pages);