Skip to contentSkip to conversation

io_uring/rsrc: use io_cache_free() to free node allocated by io_rsrc_node_alloc()

PATCH Applied Jackie Liu 2 participants 3 messages Mar 31 io_uring

lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH 1/1 io_uring/rsrc: use io_cache_free() to free node allocated by io_rsrc_node_alloc()

From: Jackie Liu <[email protected]>

Replace kfree(node) with io_cache_free() in io_buffer_register_bvec() to match all other error paths that free nodes allocated via io_rsrc_node_alloc(). The node is allocated through io_cache_alloc() internally, so it should be returned to the cache via io_cache_free() for proper object reuse.

Fixes 27cb27b6d5ea ("io_uring: add support for kernel registered bvecs")
---
 io_uring/rsrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/rsrc.c +1 -1
index 4fa59bf89bba..c4a7b29a327c 100644
@@ -961,7 +961,7 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
 	 */
 	imu = io_alloc_imu(ctx, blk_rq_nr_phys_segments(rq));
 	if (!imu) {
-		kfree(node);
+		io_cache_free(&ctx->node_cache, node);
 		ret = -ENOMEM;
 		goto unlock;
 	}
Signature · 1 line
2.51.1
maintainer
#1 lore raw
Quoted 19 lines · Jackie Liu

From: Jackie Liu <[email protected]>

Replace kfree(node) with io_cache_free() in io_buffer_register_bvec() to match all other error paths that free nodes allocated via io_rsrc_node_alloc(). The node is allocated through io_cache_alloc() internally, so it should be returned to the cache via io_cache_free() for proper object reuse.

Fixes 27cb27b6d5ea ("io_uring: add support for kernel registered bvecs")
---
 io_uring/rsrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/rsrc.c +0 -0
index 4fa59bf89bba..c4a7b29a327c 100644

io_uring/rsrc.c int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq, · line 967

Quoted 8 lines
io_uring/rsrc.c +1 -1
@@ -961,7 +961,7 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
 	 */
 	imu = io_alloc_imu(ctx, blk_rq_nr_phys_segments(rq));
 	if (!imu) {
-		kfree(node);
+		io_cache_free(&ctx->node_cache, node);
 		ret = -ENOMEM;
 		goto unlock;
 	}

People have sent this before, but I usually just dismiss it with being an error path and it doesn't matter one bit if it stays in cache or just gets freed outright. But might make sense to apply it just for consistency's sake - and so I don't get it sent again!

Signature · 1 line
Jens Axboe
maintainer Applied
#2 lore raw
In reply to Jackie Liu
Quoted 8 lines · Jackie Liu

Replace kfree(node) with io_cache_free() in io_buffer_register_bvec() to match all other error paths that free nodes allocated via io_rsrc_node_alloc(). The node is allocated through io_cache_alloc() internally, so it should be returned to the cache via io_cache_free() for proper object reuse.

[...]

Applied, thanks!

[1/1] io_uring/rsrc: use io_cache_free() to free node allocated by io_rsrc_node_alloc()

      commit: 37912f1ea4ee2d8a4f36033fea4f44a044dd1cb9

Best regards,

Signature · 1 line
Jens Axboe