Commit Graph

3 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 a2b237b6f9 io_uring: add support for vectored futex waits
JIRA: https://issues.redhat.com/browse/RHEL-27755

commit 8f350194d5cfd7016d4cd44e433df0faa4d4a703
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Jun 12 19:04:32 2023 -0600

    io_uring: add support for vectored futex waits
    
    This adds support for IORING_OP_FUTEX_WAITV, which allows registering a
    notification for a number of futexes at once. If one of the futexes are
    woken, then the request will complete with the index of the futex that got
    woken as the result. This is identical to what the normal vectored futex
    waitv operation does.
    
    Use like IORING_OP_FUTEX_WAIT, except sqe->addr must now contain a
    pointer to a struct futex_waitv array, and sqe->off must now contain the
    number of elements in that array. As flags are passed in the futex_vector
    array, and likewise for the value and futex address(es), sqe->addr2
    and sqe->addr3 are also reserved for IORING_OP_FUTEX_WAITV.
    
    For cancelations, FUTEX_WAITV does not rely on the futex_unqueue()
    return value as we're dealing with multiple futexes. Instead, a separate
    per io_uring request atomic is used to claim ownership of the request.
    
    Waiting on N futexes could be done with IORING_OP_FUTEX_WAIT as well,
    but that punts a lot of the work to the application:
    
    1) Application would need to submit N IORING_OP_FUTEX_WAIT requests,
       rather than just a single IORING_OP_FUTEX_WAITV.
    
    2) When one futex is woken, application would need to cancel the
       remaining N-1 requests that didn't trigger.
    
    While this is of course doable, having a single vectored futex wait
    makes for much simpler application code.
    
    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 09:51:34 -04:00
Jeff Moyer f33d7fd070 io_uring: add support for futex wake and wait
JIRA: https://issues.redhat.com/browse/RHEL-27755

commit 194bb58c6090e39bd7d9b9c888a079213628e1f6
Author: Jens Axboe <axboe@kernel.dk>
Date:   Thu Jun 8 11:57:40 2023 -0600

    io_uring: add support for futex wake and wait
    
    Add support for FUTEX_WAKE/WAIT primitives.
    
    IORING_OP_FUTEX_WAKE is mix of FUTEX_WAKE and FUTEX_WAKE_BITSET, as
    it does support passing in a bitset.
    
    Similary, IORING_OP_FUTEX_WAIT is a mix of FUTEX_WAIT and
    FUTEX_WAIT_BITSET.
    
    For both of them, they are using the futex2 interface.
    
    FUTEX_WAKE is straight forward, as those can always be done directly from
    the io_uring submission without needing async handling. For FUTEX_WAIT,
    things are a bit more complicated. If the futex isn't ready, then we
    rely on a callback via futex_queue->wake() when someone wakes up the
    futex. From that calback, we queue up task_work with the original task,
    which will post a CQE and wake it, if necessary.
    
    Cancelations are supported, both from the application point-of-view,
    but also to be able to cancel pending waits if the ring exits before
    all events have occurred. The return value of futex_unqueue() is used
    to gate who wins the potential race between cancelation and futex
    wakeups. Whomever gets a 'ret == 1' return from that claims ownership
    of the io_uring futex request.
    
    This is just the barebones wait/wake support. PI or REQUEUE support is
    not added at this point, unclear if we might look into that later.
    
    Likewise, explicit timeouts are not supported either. It is expected
    that users that need timeouts would do so via the usual io_uring
    mechanism to do that using linked timeouts.
    
    The SQE format is as follows:
    
    `addr`          Address of futex
    `fd`            futex2(2) FUTEX2_* flags
    `futex_flags`   io_uring specific command flags. None valid now.
    `addr2`         Value of futex
    `addr3`         Mask to wake/wait
    
    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 09:50:34 -04:00