Commit Graph

19 Commits

Author SHA1 Message Date
Jeff Moyer f1ebf01f03 io_uring/alloc_cache: switch to array based caching
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 414d0f45c316221acbf066658afdbae5b354a5cc
Author: Jens Axboe <axboe@kernel.dk>
Date:   Wed Mar 20 15:19:44 2024 -0600

    io_uring/alloc_cache: switch to array based caching
    
    Currently lists are being used to manage this, but best practice is
    usually to have these in an array instead as that it cheaper to manage.
    
    Outside of that detail, games are also played with KASAN as the list
    is inside the cached entry itself.
    
    Finally, all users of this need a struct io_cache_entry embedded in
    their struct, which is union'ized with something else in there that
    isn't used across the free -> realloc cycle.
    
    Get rid of all of that, and simply have it be an array. This will not
    change the memory used, as we're just trading an 8-byte member entry
    for the per-elem array size.
    
    This reduces the overhead of the recycled allocations, and it reduces
    the amount of code code needed to support recycling to about half of
    what it currently is.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 16:56:44 -05:00
Jeff Moyer 8842cece02 io_uring/net: move connect to always using async data
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit e2ea5a7069133c01fe3dbda95d77af7f193a1a52
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Mar 18 20:37:22 2024 -0600

    io_uring/net: move connect to always using async data
    
    While doing that, get rid of io_async_connect and just use the generic
    io_async_msghdr. Both of them have a struct sockaddr_storage in there,
    and while io_async_msghdr is bigger, if the same type can be used then
    the netmsg_cache can get reused for connect as well.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 16:52:44 -05:00
Jeff Moyer 5853eedcc0 io_uring/net: add iovec recycling
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 75191341785eef51f87ff54b0ed9dfbd5a72e7c2
Author: Jens Axboe <axboe@kernel.dk>
Date:   Sat Mar 16 15:33:53 2024 -0600

    io_uring/net: add iovec recycling
    
    Right now the io_async_msghdr is recycled to avoid the overhead of
    allocating+freeing it for every request. But the iovec is not included,
    hence that will be allocated and freed for each transfer regardless.
    This commit enables recyling of the iovec between io_async_msghdr
    recycles. This avoids alloc+free for each one if an iovec is used, and
    on top of that, it extends the cache hot nature of msg to the iovec as
    well.
    
    Also enables KASAN for the iovec entries, so that reuse can be detected
    even while they are in the cache.
    
    The io_async_msghdr also shrinks from 376 -> 288 bytes, an 88 byte
    saving (or ~23% smaller), as the fast_iovec entry is dropped from 8
    entries to a single entry. There's no point keeping a big fast iovec
    entry, if iovecs aren't being allocated and freed continually.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 16:46:44 -05:00
Jeff Moyer 34fd898903 io_uring/net: get rid of ->prep_async() for send side
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 50220d6ac8ff31eb065fba818e960f549fb89d4d
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Mar 18 08:09:47 2024 -0600

    io_uring/net: get rid of ->prep_async() for send side
    
    Move the io_async_msghdr out of the issue path and into prep handling,
    e it's now done unconditionally and hence does not need to be part
    of the issue path. This means any usage of io_sendrecv_prep_async() and
    io_sendmsg_prep_async(), and hence the forced async setup path is now
    unified with the normal prep setup.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 16:43:44 -05:00
Jeff Moyer 8ffe89e94d io_uring/net: get rid of ->prep_async() for receive side
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit c6f32c7d9e09bf1368447e9a29e869193ecbb756
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Mar 18 07:36:03 2024 -0600

    io_uring/net: get rid of ->prep_async() for receive side
    
    Move the io_async_msghdr out of the issue path and into prep handling,
    since it's now done unconditionally and hence does not need to be part
    of the issue path. This reduces the footprint of the multishot fast
    path of multiple invocations of ->issue() per prep, and also means that
    using ->prep_async() can be dropped for recvmsg asthis is now done via
    setup on the prep side.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 16:42:44 -05:00
Jeff Moyer 8620a3c4b1 io_uring/net: switch io_recv() to using io_async_msghdr
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 4a3223f7bfda14c532856152b12aace525cf8079
Author: Jens Axboe <axboe@kernel.dk>
Date:   Tue Mar 5 15:39:16 2024 -0700

    io_uring/net: switch io_recv() to using io_async_msghdr
    
    No functional changes in this patch, just in preparation for carrying
    more state than what is available now, if necessary.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 16:38:44 -05:00
Jeff Moyer 3417772578 io_uring: Add KASAN support for alloc_caches
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit e1fe7ee885dc0712e982ee465d9f8b96254c30c1
Author: Breno Leitao <leitao@debian.org>
Date:   Thu Feb 23 08:43:53 2023 -0800

    io_uring: Add KASAN support for alloc_caches
    
    Add support for KASAN in the alloc_caches (apoll and netmsg_cache).
    Thus, if something touches the unused caches, it will raise a KASAN
    warning/exception.
    
    It poisons the object when the object is put to the cache, and unpoisons
    it when the object is gotten or freed.
    
    Signed-off-by: Breno Leitao <leitao@debian.org>
    Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
    Link: https://lore.kernel.org/r/20230223164353.2839177-2-leitao@debian.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:28 -04:00
Jeff Moyer 69ed0cb748 io_uring/net: zerocopy sendmsg
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 493108d95f1464ccd101d4e5cfa7e93f1fc64d47
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Sep 21 12:17:54 2022 +0100

    io_uring/net: zerocopy sendmsg
    
    Add a zerocopy version of sendmsg.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/6aabc4bdfc0ec78df6ec9328137e394af9d4e7ef.1663668091.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:23:57 -04:00
Jeff Moyer 7d04818099 io_uring/net: combine fail handlers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit c4c0009e0b56ef9920020bcade1e45be52653bae
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Sep 21 12:17:53 2022 +0100

    io_uring/net: combine fail handlers
    
    Merge io_send_zc_fail() into io_sendrecv_fail(), saves a few lines of
    code and some headache for following patch.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/e0eba1d577413aef5602cd45f588b9230207082d.1663668091.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:23:57 -04:00
Jeff Moyer b5c1eccc26 io_uring/net: rename io_sendzc()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit b0e9b5517eb12fa80c72e205fe28534c2e2f39b9
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Sep 21 12:17:52 2022 +0100

    io_uring/net: rename io_sendzc()
    
    Simple renaming of io_sendzc*() functions in preparatio to adding
    a zerocopy sendmsg variant.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/265af46829e6076dd220011b1858dc3151969226.1663668091.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:23:57 -04:00
Jeff Moyer 4bdf424e42 io_uring/net: support non-zerocopy sendto
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 516e82f0e043a1a0e8d00800ed0ffe2137cf0e7e
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Sep 21 12:17:51 2022 +0100

    io_uring/net: support non-zerocopy sendto
    
    We have normal sends, but what is missing is sendto-like requests. Add
    sendto() capabilities to IORING_OP_SEND by passing in addr just as we do
    for IORING_OP_SEND_ZC.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/69fbd8b2cb830e57d1bf9ec351e9bf95c5b77e3f.1663668091.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:23:56 -04:00
Jeff Moyer fd543b3e34 io_uring/net: don't lose partial send_zc on fail
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 5693bcce892d7b8b15a7a92b011d3d40a023b53c
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Sep 21 12:17:49 2022 +0100

    io_uring/net: don't lose partial send_zc on fail
    
    Partial zc send may end up in io_req_complete_failed(), which not only
    would return invalid result but also mask out the notification leading
    to lifetime issues.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/5673285b5e83e6ceca323727b4ddaa584b5cc91e.1663668091.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:23:56 -04:00
Jeff Moyer dd4be430aa io_uring/net: don't lose partial send/recv on fail
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 7e6b638ed501cced4e472298d6b08dd16346f3a6
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Sep 21 12:17:48 2022 +0100

    io_uring/net: don't lose partial send/recv on fail
    
    Just as with rw, partial send/recv may end up in
    io_req_complete_failed() and loose the result, make sure we return the
    number of bytes processed.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/a4ff95897b5419356fca9ea55db91ac15b2975f9.1663668091.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:23:55 -04:00
Jeff Moyer b2fa46daef io_uring/net: simplify zerocopy send user API
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit b48c312be05e83b55a4d58bf61f80b4a3288fb7e
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Sep 1 11:54:04 2022 +0100

    io_uring/net: simplify zerocopy send user API
    
    Following user feedback, this patch simplifies zerocopy send API. One of
    the main complaints is that the current API is difficult with the
    userspace managing notification slots, and then send retries with error
    handling make it even worse.
    
    Instead of keeping notification slots change it to the per-request
    notifications model, which posts both completion and notification CQEs
    for each request when any data has been sent, and only one CQE if it
    fails. All notification CQEs will have IORING_CQE_F_NOTIF set and
    IORING_CQE_F_MORE in completion CQEs indicates whether to wait a
    notification or not.
    
    IOSQE_CQE_SKIP_SUCCESS is disallowed with zerocopy sends for now.
    
    This is less flexible, but greatly simplifies the user API and also the
    kernel implementation. We reuse notif helpers in this patch, but in the
    future there won't be need for keeping two requests.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/95287640ab98fc9417370afb16e310677c63e6ce.1662027856.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:22:58 -04:00
Jeff Moyer adda922e38 io_uring/net: save address for sendzc async execution
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 581711c46612c1fd7f98960f9ad53f04fdb89853
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Aug 24 13:07:43 2022 +0100

    io_uring/net: save address for sendzc async execution
    
    We usually copy all bits that a request needs from the userspace for
    async execution, so the userspace can keep them on the stack. However,
    send zerocopy violates this pattern for addresses and may reloads it
    e.g. from io-wq. Save the address if any in ->async_data as usual.
    
    Reported-by: Stefan Metzmacher <metze@samba.org>
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/d7512d7aa9abcd36e9afe1a4d292a24cb2d157e5.1661342812.git.asml.silence@gmail.com
    [axboe: fold in incremental fix]
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-05-05 15:22:55 -04:00
Jeff Moyer 7d666a408d io_uring: wire send zc request type
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 06a5464be84e4ae48394d34441baf34bf9706827
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Tue Jul 12 21:52:43 2022 +0100

    io_uring: wire send zc request type
    
    Add a new io_uring opcode IORING_OP_SENDZC. The main distinction from
    IORING_OP_SEND is that the user should specify a notification slot
    index in sqe::notification_idx and the buffers are safe to reuse only
    when the used notification is flushed and completes.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/a80387c6a68ce9cf99b3b6ef6f71068468761fb7.1657643355.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 08:21:02 -04:00
Jeff Moyer 3658149696 io_uring: support multishot in recvmsg
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 9bb66906f23e50d6db1e11f7498b72dfca1982a2
Author: Dylan Yudaken <dylany@fb.com>
Date:   Thu Jul 14 04:02:58 2022 -0700

    io_uring: support multishot in recvmsg
    
    Similar to multishot recv, this will require provided buffers to be
    used. However recvmsg is much more complex than recv as it has multiple
    outputs. Specifically flags, name, and control messages.
    
    Support this by introducing a new struct io_uring_recvmsg_out with 4
    fields. namelen, controllen and flags match the similar out fields in
    msghdr from standard recvmsg(2), payloadlen is the length of the payload
    following the header.
    This struct is placed at the start of the returned buffer. Based on what
    the user specifies in struct msghdr, the next bytes of the buffer will be
    name (the next msg_namelen bytes), and then control (the next
    msg_controllen bytes). The payload will come at the end. The return value
    in the CQE is the total used size of the provided buffer.
    
    Signed-off-by: Dylan Yudaken <dylany@fb.com>
    Link: https://lore.kernel.org/r/20220714110258.1336200-4-dylany@fb.com
    [axboe: style fixups, see link]
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 07:36:02 -04:00
Jeff Moyer 9eaf9409ea io_uring: add netmsg cache
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 43e0bbbd0b0e30d232fd8e9e908125b5c49a9fbc
Author: Jens Axboe <axboe@kernel.dk>
Date:   Thu Jul 7 14:30:09 2022 -0600

    io_uring: add netmsg cache
    
    For recvmsg/sendmsg, if they don't complete inline, we currently need
    to allocate a struct io_async_msghdr for each request. This is a
    somewhat large struct.
    
    Hook up sendmsg/recvmsg to use the io_alloc_cache. This reduces the
    alloc + free overhead considerably, yielding 4-5% of extra performance
    running netbench.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 07:29:02 -04:00
Jeff Moyer 38ad21ddaf io_uring: split network related opcodes into its own file
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit f9ead18c10589a351f395ac5aa107360f2f6ce53
Author: Jens Axboe <axboe@kernel.dk>
Date:   Wed May 25 06:25:13 2022 -0600

    io_uring: split network related opcodes into its own file
    
    While at it, convert the handlers to just use io_eopnotsupp_prep()
    if CONFIG_NET isn't set.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 05:26:02 -04:00