1. 22 Apr, 2024 3 commits
    • Jens Axboe's avatar
      io_uring/kbuf: add helpers for getting/peeking multiple buffers · 35c8711c
      Jens Axboe authored
      Our provided buffer interface only allows selection of a single buffer.
      Add an API that allows getting/peeking multiple buffers at the same time.
      
      This is only implemented for the ring provided buffers. It could be added
      for the legacy provided buffers as well, but since it's strongly
      encouraged to use the new interface, let's keep it simpler and just
      provide it for the new API. The legacy interface will always just select
      a single buffer.
      
      There are two new main functions:
      
      io_buffers_select(), which selects up as many buffers as it can. The
      caller supplies the iovec array, and io_buffers_select() may allocate a
      bigger array if the 'out_len' being passed in is non-zero and bigger
      than what fits in the provided iovec. Buffers grabbed with this helper
      are permanently assigned.
      
      io_buffers_peek(), which works like io_buffers_select(), except they can
      be recycled, if needed. Callers using either of these functions should
      call io_put_kbufs() rather than io_put_kbuf() at completion time. The
      peek interface must be called with the ctx locked from peek to
      completion.
      
      This add a bit state for the request:
      
      - REQ_F_BUFFERS_COMMIT, which means that the the buffers have been
        peeked and should be committed to the buffer ring head when they are
        put as part of completion. Prior to this, req->buf_list was cleared to
        NULL when committed.
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      35c8711c
    • Jens Axboe's avatar
      io_uring/net: add provided buffer support for IORING_OP_SEND · ac5f71a3
      Jens Axboe authored
      It's pretty trivial to wire up provided buffer support for the send
      side, just like how it's done the receive side. This enables setting up
      a buffer ring that an application can use to push pending sends to,
      and then have a send pick a buffer from that ring.
      
      One of the challenges with async IO and networking sends is that you
      can get into reordering conditions if you have more than one inflight
      at the same time. Consider the following scenario where everything is
      fine:
      
      1) App queues sendA for socket1
      2) App queues sendB for socket1
      3) App does io_uring_submit()
      4) sendA is issued, completes successfully, posts CQE
      5) sendB is issued, completes successfully, posts CQE
      
      All is fine. Requests are always issued in-order, and both complete
      inline as most sends do.
      
      However, if we're flooding socket1 with sends, the following could
      also result from the same sequence:
      
      1) App queues sendA for socket1
      2) App queues sendB for socket1
      3) App does io_uring_submit()
      4) sendA is issued, socket1 is full, poll is armed for retry
      5) Space frees up in socket1, this triggers sendA retry via task_work
      6) sendB is issued, completes successfully, posts CQE
      7) sendA is retried, completes successfully, posts CQE
      
      Now we've sent sendB before sendA, which can make things unhappy. If
      both sendA and sendB had been using provided buffers, then it would look
      as follows instead:
      
      1) App queues dataA for sendA, queues sendA for socket1
      2) App queues dataB for sendB queues sendB for socket1
      3) App does io_uring_submit()
      4) sendA is issued, socket1 is full, poll is armed for retry
      5) Space frees up in socket1, this triggers sendA retry via task_work
      6) sendB is issued, picks first buffer (dataA), completes successfully,
         posts CQE (which says "I sent dataA")
      7) sendA is retried, picks first buffer (dataB), completes successfully,
         posts CQE (which says "I sent dataB")
      
      Now we've sent the data in order, and everybody is happy.
      
      It's worth noting that this also opens the door for supporting multishot
      sends, as provided buffers would be a prerequisite for that. Those can
      trigger either when new buffers are added to the outgoing ring, or (if
      stalled due to lack of space) when space frees up in the socket.
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      ac5f71a3
    • Jens Axboe's avatar
      io_uring/net: add generic multishot retry helper · 3e747ded
      Jens Axboe authored
      This is just moving io_recv_prep_retry() higher up so it can get used
      for sends as well, and rename it to be generically useful for both
      sends and receives.
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      3e747ded
  2. 17 Apr, 2024 3 commits
  3. 15 Apr, 2024 34 commits