Skip to content
  1. Jun 16, 2021
    • Pavel Begunkov's avatar
      io_uring: refactor io_req_defer() · 76cc33d7
      Pavel Begunkov authored
      
      
      Rename io_req_defer() into io_drain_req() and refactor it uncoupling it
      from io_queue_sqe() error handling and preparing for coming
      optimisations. Also, prioritise non IOSQE_ASYNC path.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/4f17dd56e7fbe52d1866f8acd8efe3284d2bebcb.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      76cc33d7
    • Pavel Begunkov's avatar
      io_uring: move uring_lock location · 0499e582
      Pavel Begunkov authored
      
      
      ->uring_lock is prevalently used for submission, even though it protects
      many other things like iopoll, registeration, selected bufs, and more.
      And it's placed together with ->cq_wait poked on completion and CQ
      waiting sides. Move them apart, ->uring_lock goes to the submission
      data, and cq_wait to completion related chunk. The last one requires
      some reshuffling so everything needed by io_cqring_ev_posted*() is in
      one cacheline.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/dea5e845caee4c98aa0922b46d713154d81f7bd8.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      0499e582
    • Pavel Begunkov's avatar
      io_uring: wait heads renaming · 311997b3
      Pavel Begunkov authored
      
      
      We use several wait_queue_head's for different purposes, but namings are
      confusing. First rename ctx->cq_wait into ctx->poll_wait, because this
      one is used for polling an io_uring instance. Then rename ctx->wait into
      ctx->cq_wait, which is responsible for CQE waiting.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/47b97a097780c86c67b20b6ccc4e077523dce682.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      311997b3
    • Pavel Begunkov's avatar
      io_uring: clean up check_overflow flag · 5ed7a37d
      Pavel Begunkov authored
      
      
      There are no users of ->sq_check_overflow, only ->cq_check_overflow is
      used. Combine it and move out of completion related part of struct
      io_ring_ctx.
      
      A not so obvious benefit of it is fitting all completion side fields
      into a single cacheline. It was taking 2 lines before with 56B padding,
      and io_cqring_ev_posted*() were still touching both of them.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/25927394964df31d113e3c729416af573afff5f5.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      5ed7a37d
    • Pavel Begunkov's avatar
      io_uring: small io_submit_sqe() optimisation · 5e159204
      Pavel Begunkov authored
      
      
      submit_state.link is used only to assemble a link and not used for
      actual submission, so clear it before io_queue_sqe() in io_submit_sqe(),
      awhile it's hot and in caches and queueing doesn't spoil it. May also
      potentially help compiler with spilling or to do other optimisations.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/1579939426f3ad6b55af3005b1389bbbed7d780d.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      5e159204
    • Pavel Begunkov's avatar
      io_uring: optimise completion timeout flushing · f18ee4cf
      Pavel Begunkov authored
      
      
      io_commit_cqring() might be very hot and we definitely don't want to
      touch ->timeout_list there, because 1) it's shared with the submission
      side so might lead to cache bouncing and 2) may need to load an extra
      cache line, especially for IRQ completions.
      
      We're interested in it at the completion side only when there are
      offset-mode timeouts, which are not so popular. Replace
      list_empty(->timeout_list) hot path check with a new one-way flag, which
      is set when we prepare the first offset-mode timeout.
      
      note: the flag sits in the same line as briefly used after ->rings
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/e4892ec68b71a69f92ffbea4a1499be3ec0d463b.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      f18ee4cf
    • Pavel Begunkov's avatar
      io_uring: don't cache number of dropped SQEs · 15641e42
      Pavel Begunkov authored
      
      
      Kill ->cached_sq_dropped and wire DRAIN sequence number correction via
      ->cq_extra, which is there exactly for that purpose. User visible
      dropped counter will be populated by incrementing it instead of keeping
      a copy, similarly as it was done not so long ago with cq_overflow.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/088aceb2707a534d531e2770267c4498e0507cc1.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      15641e42
    • Pavel Begunkov's avatar
      io_uring: refactor io_get_sqe() · 17d3aeb3
      Pavel Begunkov authored
      
      
      The line of io_get_sqe() evaluating @head consists of too many
      operations including READ_ONCE(), it's not convenient for probing.
      Refactor it also improving readability.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/866ad6e4ef4851c7c61f6b0e08dbd0a8d1abce84.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      17d3aeb3
    • Pavel Begunkov's avatar
      io_uring: shuffle more fields into SQ ctx section · 7f1129d2
      Pavel Begunkov authored
      
      
      Since moving locked_free_* out of struct io_submit_state
      ctx->submit_state is accessed on submission side only, so move it into
      the submission section. Same goes for rsrc table pointers/nodes/etc.,
      they must be taken and checked during submission because sync'ed by
      uring_lock, so move them there as well.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/8a5899a50afc6ccca63249e716f580b246f3dec6.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      7f1129d2
    • Pavel Begunkov's avatar
      io_uring: move ctx->flags from SQ cacheline · b52ecf8c
      Pavel Begunkov authored
      
      
      ctx->flags are heavily used by both, completion and submission sides, so
      move it out from the ctx fields related to submissions. Instead, place
      it together with ctx->refs, because it's already cacheline-aligned and
      so pads lots of space, and both almost never change. Also, in most
      occasions they are accessed together as refs are taken at submission
      time and put back during completion.
      
      Do same with ctx->rings, where the pointer itself is never modified
      apart from ring init/free.
      
      Note: in percpu mode, struct percpu_ref doesn't modify the struct itself
      but takes indirection with ref->percpu_count_ptr.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/4c48c173e63d35591383ba2b87e8b8e8dfdbd23d.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      b52ecf8c
    • Pavel Begunkov's avatar
      io_uring: keep SQ pointers in a single cacheline · c7af47cf
      Pavel Begunkov authored
      
      
      sq_array and sq_sqes are always used together, however they are in
      different cachelines, where the borderline is right before
      cq_overflow_list is rather rarely touched. Move the fields together so
      it loads only one cacheline.
      
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/3ef2411a94874da06492506a8897eff679244f49.1623709150.git.asml.silence@gmail.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      c7af47cf
    • Colin Ian King's avatar
      io-wq: remove redundant initialization of variable ret · b1b2fc35
      Colin Ian King authored
      
      
      The variable ret is being initialized with a value that is never read, the
      assignment is redundant and can be removed.
      
      Addresses-Coverity: ("Unused value")
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Link: https://lore.kernel.org/r/20210615143424.60449-1-colin.king@canonical.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      b1b2fc35
    • Colin Ian King's avatar
      io_uring: Fix incorrect sizeof operator for copy_from_user call · fdd1dc31
      Colin Ian King authored
      Static analysis is warning that the sizeof being used is should be
      of *data->tags[i] and not data->tags[i]. Although these are the same
      size on 64 bit systems it is not a portable assumption to assume
      this is true for all cases.  Fix this by using a temporary pointer
      tag_slot to make the code a clearer.
      
      Addresses-Coverity: ("Sizeof not portable")
      Fixes: d878c816
      
       ("io_uring: hide rsrc tag copy into generic helpers")
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Reviewed-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/20210615130011.57387-1-colin.king@canonical.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      fdd1dc31
  2. Jun 14, 2021