public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Caleb Sander Mateos <csander@purestorage.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org,
	Uday Shankar <ushankar@purestorage.com>
Subject: Re: [PATCH V5 10/21] ublk: add new feature UBLK_F_BATCH_IO
Date: Sun, 7 Dec 2025 21:58:23 +0800	[thread overview]
Message-ID: <aTWH_37UUY5zLvJu@fedora> (raw)
In-Reply-To: <CADUfDZpN+QWKzhRnS9y1Hvn-jgQ2kd+6GxX5YyNU8gi4sCmpaA@mail.gmail.com>

On Sun, Dec 07, 2025 at 12:16:35AM -0800, Caleb Sander Mateos wrote:
> On Tue, Dec 2, 2025 at 4:21 AM Ming Lei <ming.lei@redhat.com> wrote:
> >
> > Add new feature UBLK_F_BATCH_IO which replaces the following two
> > per-io commands:
> >
> >         - UBLK_U_IO_FETCH_REQ
> >
> >         - UBLK_U_IO_COMMIT_AND_FETCH_REQ
> >
> > with three per-queue batch io uring_cmd:
> >
> >         - UBLK_U_IO_PREP_IO_CMDS
> >
> >         - UBLK_U_IO_COMMIT_IO_CMDS
> >
> >         - UBLK_U_IO_FETCH_IO_CMDS
> >
> > Then ublk can deliver batch io commands to ublk server in single
> > multishort uring_cmd, also allows to prepare & commit multiple
> > commands in batch style via single uring_cmd, communication cost is
> > reduced a lot.
> >
> > This feature also doesn't limit task context any more for all supported
> > commands, so any allowed uring_cmd can be issued in any task context.
> > ublk server implementation becomes much easier.
> >
> > Meantime load balance becomes much easier to support with this feature.
> > The command `UBLK_U_IO_FETCH_IO_CMDS` can be issued from multiple task
> > contexts, so each task can adjust this command's buffer length or number
> > of inflight commands for controlling how much load is handled by current
> > task.
> >
> > Later, priority parameter will be added to command `UBLK_U_IO_FETCH_IO_CMDS`
> > for improving load balance support.
> >
> > UBLK_U_IO_NEED_GET_DATA isn't supported in batch io yet, but it may be
> > enabled in future via its batch pair.
> >
> > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > ---
> >  drivers/block/ublk_drv.c      | 53 +++++++++++++++++++++++++++++------
> >  include/uapi/linux/ublk_cmd.h | 16 +++++++++++
> >  2 files changed, 61 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 3865edabe1e6..034420e8df55 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -74,7 +74,8 @@
> >                 | UBLK_F_AUTO_BUF_REG \
> >                 | UBLK_F_QUIESCE \
> >                 | UBLK_F_PER_IO_DAEMON \
> > -               | UBLK_F_BUF_REG_OFF_DAEMON)
> > +               | UBLK_F_BUF_REG_OFF_DAEMON \
> > +               | UBLK_F_BATCH_IO)
> >
> >  #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> >                 | UBLK_F_USER_RECOVERY_REISSUE \
> > @@ -331,12 +332,12 @@ static void ublk_batch_dispatch(struct ublk_queue *ubq,
> >
> >  static inline bool ublk_dev_support_batch_io(const struct ublk_device *ub)
> >  {
> > -       return false;
> > +       return ub->dev_info.flags & UBLK_F_BATCH_IO;
> >  }
> >
> >  static inline bool ublk_support_batch_io(const struct ublk_queue *ubq)
> >  {
> > -       return false;
> > +       return ubq->flags & UBLK_F_BATCH_IO;
> >  }
> >
> >  static inline void ublk_io_lock(struct ublk_io *io)
> > @@ -3462,6 +3463,35 @@ static int ublk_validate_batch_fetch_cmd(struct ublk_batch_io_data *data,
> >         return 0;
> >  }
> >
> > +static int ublk_handle_non_batch_cmd(struct io_uring_cmd *cmd,
> > +                                    unsigned int issue_flags)
> > +{
> > +       const struct ublksrv_io_cmd *ub_cmd = io_uring_sqe_cmd(cmd->sqe);
> > +       struct ublk_device *ub = cmd->file->private_data;
> > +       unsigned tag = READ_ONCE(ub_cmd->tag);
> > +       unsigned q_id = READ_ONCE(ub_cmd->q_id);
> > +       unsigned index = READ_ONCE(ub_cmd->addr);
> > +       struct ublk_queue *ubq;
> > +       struct ublk_io *io;
> > +
> > +       if (cmd->cmd_op == UBLK_U_IO_UNREGISTER_IO_BUF)
> > +               return ublk_unregister_io_buf(cmd, ub, index, issue_flags);
> > +
> > +       if (q_id >= ub->dev_info.nr_hw_queues)
> > +               return -EINVAL;
> > +
> > +       if (tag >= ub->dev_info.queue_depth)
> > +               return -EINVAL;
> > +
> > +       if (cmd->cmd_op != UBLK_U_IO_REGISTER_IO_BUF)
> > +               return -EOPNOTSUPP;
> > +
> > +       ubq = ublk_get_queue(ub, q_id);
> > +       io = &ubq->ios[tag];
> > +       return ublk_register_io_buf(cmd, ub, q_id, tag, io, index,
> > +                       issue_flags);
> > +}
> > +
> >  static int ublk_ch_batch_io_uring_cmd(struct io_uring_cmd *cmd,
> >                                        unsigned int issue_flags)
> >  {
> > @@ -3509,7 +3539,8 @@ static int ublk_ch_batch_io_uring_cmd(struct io_uring_cmd *cmd,
> >                 ret = ublk_handle_batch_fetch_cmd(&data);
> >                 break;
> >         default:
> > -               ret = -EOPNOTSUPP;
> > +               ret = ublk_handle_non_batch_cmd(cmd, issue_flags);
> 
> It looks like the non-batch commands still perform the if
> (data.header.q_id >= ub->dev_info.nr_hw_queues) check in
> ublk_ch_batch_io_uring_cmd() even though they use struct
> ublksrv_io_cmd instead of struct ublk_batch_io. I think it would be
> preferable to move that check to ublk_check_batch_cmd() and
> ublk_handle_batch_fetch_cmd().

Yes, will fix it in next version.

> 
> > +               break;
> >         }
> >  out:
> >         return ret;
> > @@ -4179,10 +4210,9 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)
> >          */
> >         ub->dev_info.flags &= UBLK_F_ALL;
> >
> > -       ub->dev_info.flags |= UBLK_F_CMD_IOCTL_ENCODE |
> > -               UBLK_F_URING_CMD_COMP_IN_TASK |
> > -               UBLK_F_PER_IO_DAEMON |
> > -               UBLK_F_BUF_REG_OFF_DAEMON;
> 
> Why are these reported features removed? This will break ublk servers
> that check for these features in the ublk device flags.

oops, it is really one accident.


Thanks,
Ming


  reply	other threads:[~2025-12-07 13:58 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 12:18 [PATCH V5 00/21] ublk: add UBLK_F_BATCH_IO Ming Lei
2025-12-02 12:18 ` [PATCH V5 01/21] ublk: define ublk_ch_batch_io_fops for the coming feature F_BATCH_IO Ming Lei
2025-12-02 12:18 ` [PATCH V5 02/21] ublk: prepare for not tracking task context for command batch Ming Lei
2025-12-02 12:18 ` [PATCH V5 03/21] ublk: add new batch command UBLK_U_IO_PREP_IO_CMDS & UBLK_U_IO_COMMIT_IO_CMDS Ming Lei
2025-12-02 12:18 ` [PATCH V5 04/21] ublk: handle UBLK_U_IO_PREP_IO_CMDS Ming Lei
2025-12-02 12:18 ` [PATCH V5 05/21] ublk: handle UBLK_U_IO_COMMIT_IO_CMDS Ming Lei
2025-12-04  3:11   ` Caleb Sander Mateos
2025-12-02 12:19 ` [PATCH V5 06/21] ublk: add io events fifo structure Ming Lei
2025-12-04  3:16   ` Caleb Sander Mateos
2025-12-02 12:19 ` [PATCH V5 07/21] ublk: add batch I/O dispatch infrastructure Ming Lei
2025-12-04  3:38   ` Caleb Sander Mateos
2025-12-02 12:19 ` [PATCH V5 08/21] ublk: add UBLK_U_IO_FETCH_IO_CMDS for batch I/O processing Ming Lei
2025-12-07  7:38   ` Caleb Sander Mateos
2025-12-07 13:54     ` Ming Lei
2025-12-08 17:03       ` Caleb Sander Mateos
2025-12-07 13:56     ` Ming Lei
2025-12-08 17:04       ` Caleb Sander Mateos
2025-12-02 12:19 ` [PATCH V5 09/21] ublk: abort requests filled in event kfifo Ming Lei
2025-12-07  7:44   ` Caleb Sander Mateos
2025-12-02 12:19 ` [PATCH V5 10/21] ublk: add new feature UBLK_F_BATCH_IO Ming Lei
2025-12-07  8:16   ` Caleb Sander Mateos
2025-12-07 13:58     ` Ming Lei [this message]
2025-12-02 12:19 ` [PATCH V5 11/21] ublk: document " Ming Lei
2025-12-07  8:22   ` Caleb Sander Mateos
2025-12-07 15:03     ` Ming Lei
2025-12-08 21:10       ` Caleb Sander Mateos
2025-12-02 12:19 ` [PATCH V5 12/21] ublk: implement batch request completion via blk_mq_end_request_batch() Ming Lei
2025-12-02 12:19 ` [PATCH V5 13/21] selftests: ublk: fix user_data truncation for tgt_data >= 256 Ming Lei
2025-12-02 12:19 ` [PATCH V5 14/21] selftests: ublk: replace assert() with ublk_assert() Ming Lei
2025-12-02 12:19 ` [PATCH V5 15/21] selftests: ublk: add ublk_io_buf_idx() for returning io buffer index Ming Lei
2025-12-02 12:19 ` [PATCH V5 16/21] selftests: ublk: add batch buffer management infrastructure Ming Lei
2025-12-02 12:19 ` [PATCH V5 17/21] selftests: ublk: handle UBLK_U_IO_PREP_IO_CMDS Ming Lei
2025-12-02 12:19 ` [PATCH V5 18/21] selftests: ublk: handle UBLK_U_IO_COMMIT_IO_CMDS Ming Lei
2025-12-02 12:19 ` [PATCH V5 19/21] selftests: ublk: handle UBLK_U_IO_FETCH_IO_CMDS Ming Lei
2025-12-02 12:19 ` [PATCH V5 20/21] selftests: ublk: add --batch/-b for enabling F_BATCH_IO Ming Lei
2025-12-02 12:19 ` [PATCH V5 21/21] selftests: ublk: support arbitrary threads/queues combination Ming Lei

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=aTWH_37UUY5zLvJu@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ushankar@purestorage.com \
    /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