Message ID | 20250123105008.212752-1-sidong.yang@furiosa.ai (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | io-uring: futex: cache io_futex_data than kfree | expand |
On 1/23/25 3:50 AM, Sidong Yang wrote: > If futex_wait_setup() fails in io_futex_wait(), Old code just releases > io_futex_data. This patch tries to cache io_futex_data before kfree. It's not that the patch is incorrect, but: 1) This is an error path, surely we do not care about caching in that case. If it's often hit, then the application would be buggy. 2) If you're going to add an io_free_ifd() helper, then at least use it for the normal case too that still open-codes it.
On Thu, Jan 23, 2025 at 06:36:06AM -0700, Jens Axboe wrote: Hi, Jens. Thanks for review! > On 1/23/25 3:50 AM, Sidong Yang wrote: > > If futex_wait_setup() fails in io_futex_wait(), Old code just releases > > io_futex_data. This patch tries to cache io_futex_data before kfree. > > It's not that the patch is incorrect, but: > > 1) This is an error path, surely we do not care about caching in > that case. If it's often hit, then the application would be buggy. > > 2) If you're going to add an io_free_ifd() helper, then at least use it > for the normal case too that still open-codes it. Agreed, So this patch could be make it buggy. You can drop this patch. I'll find another task to work on. Thanks, Sidong > > -- > Jens Axboe >
On 1/23/25 6:15 PM, Sidong Yang wrote: > On Thu, Jan 23, 2025 at 06:36:06AM -0700, Jens Axboe wrote: > > Hi, Jens. > Thanks for review! > >> On 1/23/25 3:50 AM, Sidong Yang wrote: >>> If futex_wait_setup() fails in io_futex_wait(), Old code just releases >>> io_futex_data. This patch tries to cache io_futex_data before kfree. >> >> It's not that the patch is incorrect, but: >> >> 1) This is an error path, surely we do not care about caching in >> that case. If it's often hit, then the application would be buggy. >> >> 2) If you're going to add an io_free_ifd() helper, then at least use it >> for the normal case too that still open-codes it. > > Agreed, So this patch could be make it buggy. You can drop this patch. I'll > find another task to work on. It won't make it buggy, it's just a bit questionnable if it's worth doing. And if it is, then it should have io_free_ifd() being used in the other place that puts to the cache as well, to make it complete.
On Fri, Jan 24, 2025 at 06:37:13AM -0700, Jens Axboe wrote: > On 1/23/25 6:15 PM, Sidong Yang wrote: > > On Thu, Jan 23, 2025 at 06:36:06AM -0700, Jens Axboe wrote: > > > > Hi, Jens. > > Thanks for review! > > > >> On 1/23/25 3:50 AM, Sidong Yang wrote: > >>> If futex_wait_setup() fails in io_futex_wait(), Old code just releases > >>> io_futex_data. This patch tries to cache io_futex_data before kfree. > >> > >> It's not that the patch is incorrect, but: > >> > >> 1) This is an error path, surely we do not care about caching in > >> that case. If it's often hit, then the application would be buggy. > >> > >> 2) If you're going to add an io_free_ifd() helper, then at least use it > >> for the normal case too that still open-codes it. > > > > Agreed, So this patch could be make it buggy. You can drop this patch. I'll > > find another task to work on. > > It won't make it buggy, it's just a bit questionnable if it's worth > doing. And if it is, then it should have io_free_ifd() being used in the > other place that puts to the cache as well, to make it complete. I found that io_free_ifd() could be used in io_futex_complete(). It needs same routine that try to cache or kfree. Is it good to make v2 includes changing it? > > -- > Jens Axboe
diff --git a/io_uring/futex.c b/io_uring/futex.c index e29662f039e1..217a38498c36 100644 --- a/io_uring/futex.c +++ b/io_uring/futex.c @@ -262,6 +262,13 @@ static struct io_futex_data *io_alloc_ifd(struct io_ring_ctx *ctx) return kmalloc(sizeof(struct io_futex_data), GFP_NOWAIT); } +static void io_free_ifd(struct io_ring_ctx *ctx, struct io_futex_data *ifd) +{ + if (!io_alloc_cache_put(&ctx->futex_cache, ifd)) { + kfree(ifd); + } +} + int io_futexv_wait(struct io_kiocb *req, unsigned int issue_flags) { struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex); @@ -353,13 +360,13 @@ int io_futex_wait(struct io_kiocb *req, unsigned int issue_flags) return IOU_ISSUE_SKIP_COMPLETE; } + io_free_ifd(ctx, ifd); done_unlock: io_ring_submit_unlock(ctx, issue_flags); done: if (ret < 0) req_set_fail(req); io_req_set_res(req, ret, 0); - kfree(ifd); return IOU_OK; }
If futex_wait_setup() fails in io_futex_wait(), Old code just releases io_futex_data. This patch tries to cache io_futex_data before kfree. Signed-off-by: Sidong Yang <sidong.yang@furiosa.ai> --- io_uring/futex.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)