• Pavel Begunkov's avatar
    io_uring: add option to skip CQE posting · 04c76b41
    Pavel Begunkov authored
    Emitting a CQE is expensive from the kernel perspective. Often, it's
    also not convenient for the userspace, spends some cycles on processing
    and just complicates the logic. A similar problems goes for linked
    requests, where we post an CQE for each request in the link.
    
    Introduce a new flags, IOSQE_CQE_SKIP_SUCCESS, trying to help with it.
    When set and a request completed successfully, it won't generate a CQE.
    When fails, it produces an CQE, but all following linked requests will
    be CQE-less, regardless whether they have IOSQE_CQE_SKIP_SUCCESS or not.
    The notion of "fail" is the same as for link failing-cancellation, where
    it's opcode dependent, and _usually_ result >= 0 is a success, but not
    always.
    
    Linked timeouts are a bit special. When the requests it's linked to was
    not attempted to be executed, e.g. failing linked requests, it follows
    the description above. Otherwise, whether a linked timeout will post a
    completion or not solely depends on IOSQE_CQE_SKIP_SUCCESS of that
    linked timeout request. Linked timeout never "fail" during execution, so
    for them it's unconditional. It's expected for users to not really care
    about the result of it but rely solely on the result of the master
    request. Another reason for such a treatment is that it's racy, and the
    timeout callback may be running awhile the master request posts its
    completion.
    
    use case 1:
    If one doesn't care about results of some requests, e.g. normal
    timeouts, just set IOSQE_CQE_SKIP_SUCCESS. Error result will still be
    posted and need to be handled.
    
    use case 2:
    Set IOSQE_CQE_SKIP_SUCCESS for all requests of a link but the last,
    and it'll post a completion only for the last one if everything goes
    right, otherwise there will be one only one CQE for the first failed
    request.
    Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/0220fbe06f7cf99e6fc71b4297bb1cb6c0e89c2c.1636559119.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
    04c76b41
io_uring.c 275 KB