diff mbox series

[2/2] io_uring/msg_ring: use kmem_cache_free() to free request

Message ID 20240701144908.19602-3-axboe@kernel.dk (mailing list archive)
State New
Headers show
Series msg_ring fixes | expand

Commit Message

Jens Axboe July 1, 2024, 2:48 p.m. UTC
The change adding caching around the request allocated and freed for
data messages changed a kmem_cache_free() to a kfree(), which isn't
correct as the request came from slab in the first place. Fix that up
and use the right freeing function if the cache is already at its limit.

Fixes: 50cf5f3842af ("io_uring/msg_ring: add an alloc cache for io_kiocb entries")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/msg_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Gabriel Krisman Bertazi July 2, 2024, 3:17 p.m. UTC | #1
Jens Axboe <axboe@kernel.dk> writes:

> The change adding caching around the request allocated and freed for
> data messages changed a kmem_cache_free() to a kfree(), which isn't
> correct as the request came from slab in the first place. Fix that up
> and use the right freeing function if the cache is already at its limit.
>
> Fixes: 50cf5f3842af ("io_uring/msg_ring: add an alloc cache for io_kiocb entries")
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

Fwiw, kfree works fine for kmem_cache_alloc objects since 6.4, when SLOB
was removed.  Either way, it doesn't harm.

> ---
>  io_uring/msg_ring.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
> index c2171495098b..29fa9285a33d 100644
> --- a/io_uring/msg_ring.c
> +++ b/io_uring/msg_ring.c
> @@ -82,7 +82,7 @@ static void io_msg_tw_complete(struct io_kiocb *req, struct io_tw_state *ts)
>  		spin_unlock(&ctx->msg_lock);
>  	}
>  	if (req)
> -		kfree(req);
> +		kmem_cache_free(req_cachep, req);
>  	percpu_ref_put(&ctx->refs);
>  }
Jens Axboe July 2, 2024, 3:18 p.m. UTC | #2
On 7/2/24 9:17 AM, Gabriel Krisman Bertazi wrote:
> Jens Axboe <axboe@kernel.dk> writes:
> 
>> The change adding caching around the request allocated and freed for
>> data messages changed a kmem_cache_free() to a kfree(), which isn't
>> correct as the request came from slab in the first place. Fix that up
>> and use the right freeing function if the cache is already at its limit.
>>
>> Fixes: 50cf5f3842af ("io_uring/msg_ring: add an alloc cache for io_kiocb entries")
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> Fwiw, kfree works fine for kmem_cache_alloc objects since 6.4, when SLOB
> was removed.  Either way, it doesn't harm.

Right, it's more for consistency sake, it's not fixing a real bug.
diff mbox series

Patch

diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index c2171495098b..29fa9285a33d 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -82,7 +82,7 @@  static void io_msg_tw_complete(struct io_kiocb *req, struct io_tw_state *ts)
 		spin_unlock(&ctx->msg_lock);
 	}
 	if (req)
-		kfree(req);
+		kmem_cache_free(req_cachep, req);
 	percpu_ref_put(&ctx->refs);
 }