From: Caleb Sander Mateos <csander@purestorage.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org
Subject: Re: [PATCH 4/4] io_uring/uring_cmd: implement ->sqe_copy() to avoid unnecessary copies
Date: Mon, 9 Jun 2025 14:54:38 -0700 [thread overview]
Message-ID: <CADUfDZr=EhcUuJuMC5-VW0hVCNUNwtjNbb19fkApdD7j2aSGMQ@mail.gmail.com> (raw)
In-Reply-To: <20250609173904.62854-5-axboe@kernel.dk>
On Mon, Jun 9, 2025 at 10:39 AM Jens Axboe <axboe@kernel.dk> wrote:
>
> uring_cmd currently copies the full SQE at prep time, just in case it
> needs it to be stable. However, for inline completions or requests that
> get queued up on the device side, there's no need to ever copy the SQE.
> This is particularly important, as various use cases of uring_cmd will
> be using 128b sized SQEs.
>
> Opt in to using ->sqe_copy() to let the core of io_uring decide when to
> copy SQEs. This callback will only be called if it is safe to do so.
>
> Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
> io_uring/opdef.c | 1 +
> io_uring/uring_cmd.c | 21 ++++++++++++---------
> io_uring/uring_cmd.h | 1 +
> 3 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/io_uring/opdef.c b/io_uring/opdef.c
> index 6e0882b051f9..287f9a23b816 100644
> --- a/io_uring/opdef.c
> +++ b/io_uring/opdef.c
> @@ -759,6 +759,7 @@ const struct io_cold_def io_cold_defs[] = {
> },
> [IORING_OP_URING_CMD] = {
> .name = "URING_CMD",
> + .sqe_copy = io_uring_cmd_sqe_copy,
> .cleanup = io_uring_cmd_cleanup,
> },
> [IORING_OP_SEND_ZC] = {
> diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> index e204f4941d72..a99dc2f9c4b5 100644
> --- a/io_uring/uring_cmd.c
> +++ b/io_uring/uring_cmd.c
> @@ -205,17 +205,20 @@ int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
> if (!ac)
> return -ENOMEM;
> ac->data.op_data = NULL;
> + ioucmd->sqe = sqe;
> + return 0;
> +}
> +
> +void io_uring_cmd_sqe_copy(struct io_kiocb *req)
> +{
> + struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
> + struct io_async_cmd *ac = req->async_data;
>
> - /*
> - * Unconditionally cache the SQE for now - this is only needed for
> - * requests that go async, but prep handlers must ensure that any
> - * sqe data is stable beyond prep. Since uring_cmd is special in
> - * that it doesn't read in per-op data, play it safe and ensure that
> - * any SQE data is stable beyond prep. This can later get relaxed.
> - */
> - memcpy(ac->sqes, sqe, uring_sqe_size(req->ctx));
> + /* already copied, nothing to do */
> + if (ioucmd->sqe == ac->sqes)
REQ_F_SQE_COPY should prevent this from ever happening, right? Could
we make it a WARN_ON()? Or drop it entirely?
Best,
Caleb
> + return;
> + memcpy(ac->sqes, ioucmd->sqe, uring_sqe_size(req->ctx));
> ioucmd->sqe = ac->sqes;
> - return 0;
> }
>
> int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
> diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h
> index e6a5142c890e..a6dad47afc6b 100644
> --- a/io_uring/uring_cmd.h
> +++ b/io_uring/uring_cmd.h
> @@ -11,6 +11,7 @@ struct io_async_cmd {
>
> int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags);
> int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
> +void io_uring_cmd_sqe_copy(struct io_kiocb *req);
> void io_uring_cmd_cleanup(struct io_kiocb *req);
>
> bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-06-09 21:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 17:36 [PATCHSET v4 0/4] uring_cmd copy avoidance Jens Axboe
2025-06-09 17:36 ` [PATCH 1/4] io_uring: add IO_URING_F_INLINE issue flag Jens Axboe
2025-06-09 21:53 ` Caleb Sander Mateos
2025-06-09 17:36 ` [PATCH 2/4] io_uring: add struct io_cold_def->sqe_copy() method Jens Axboe
2025-06-09 21:54 ` Caleb Sander Mateos
2025-06-10 13:32 ` Jens Axboe
2025-06-09 17:36 ` [PATCH 3/4] io_uring/uring_cmd: get rid of io_uring_cmd_prep_setup() Jens Axboe
2025-06-09 17:36 ` [PATCH 4/4] io_uring/uring_cmd: implement ->sqe_copy() to avoid unnecessary copies Jens Axboe
2025-06-09 21:54 ` Caleb Sander Mateos [this message]
2025-06-10 13:35 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2025-06-06 21:54 [PATCHSET v3 0/4] uring_cmd copy avoidance Jens Axboe
2025-06-06 21:54 ` [PATCH 4/4] io_uring/uring_cmd: implement ->sqe_copy() to avoid unnecessary copies Jens Axboe
2025-06-07 0:50 ` Caleb Sander Mateos
2025-06-05 19:40 [PATCHSET RFC v2 0/4] uring_cmd copy avoidance Jens Axboe
2025-06-05 19:40 ` [PATCH 4/4] io_uring/uring_cmd: implement ->sqe_copy() to avoid unnecessary copies Jens Axboe
2025-06-06 17:39 ` Caleb Sander Mateos
2025-06-06 21:05 ` Jens Axboe
2025-06-06 22:08 ` Jens Axboe
2025-06-06 22:09 ` Caleb Sander Mateos
2025-06-06 23:53 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADUfDZr=EhcUuJuMC5-VW0hVCNUNwtjNbb19fkApdD7j2aSGMQ@mail.gmail.com' \
--to=csander@purestorage.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox