io_uring: poll rework
It's not possible to go forward with the current state of io_uring polling, we need a more straightforward and easier synchronisation. There are a lot of problems with how it is at the moment, including missing events on rewait. The main idea here is to introduce a notion of request ownership while polling, no one but the owner can modify any part but ->poll_refs of struct io_kiocb, that grants us protection against all sorts of races. Main users of such exclusivity are poll task_work handler, so before queueing a tw one should have/acquire ownership, which will be handed off to the tw handler. The other user is __io_arm_poll_handler() do initial poll arming. It starts taking the ownership, so tw handlers won't be run until it's released later in the function after vfs_poll. note: also prevents races in __io_queue_proc(). Poll wake/etc. may not be able to get ownership, then they need to increase the poll refcount and the task_work should notice it and retry if necessary, see io_poll_check_events(). There is also IO_POLL_CANCEL_FLAG flag to notify that we want to kill request. It makes cancellations more reliable, enables double multishot polling, fixes double poll rewait, fixes missing poll events and fixes another bunch of races. Even though it adds some overhead for new refcounting, and there are a couple of nice performance wins: - no req->refs refcounting for poll requests anymore - if the data is already there (once measured for some test to be 1-2% of all apoll requests), it removes it doesn't add atomics and removes spin_lock/unlock pair. - works well with multishots, we don't do remove from queue / add to queue for each new poll event. Signed-off-by:Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/6b652927c77ed9580ea4330ac5612f0e0848c946.1639605189.git.asml.silence@gmail.com Signed-off-by:
Jens Axboe <axboe@kernel.dk>
-
mentioned in commit fe70198a
-
mentioned in commit 9a952b02
-
mentioned in commit 79212860
-
mentioned in commit d3f2c6d8
-
mentioned in commit 9cea40f8
-
mentioned in commit 186231a1
-
mentioned in commit b624b2a1
-
mentioned in commit 9825b7d1
-
mentioned in commit 756ab350
-
mentioned in commit 01d47310
-
mentioned in commit 74e564d7
-
mentioned in commit 6ff0d7e1
-
mentioned in commit d64796e9
-
mentioned in commit 039fcdc1
-
mentioned in commit 5f8c61fc
-
mentioned in commit 4c96fb94
-
mentioned in commit a593c743
-
mentioned in commit 80623fea
-
mentioned in commit b69575ff
-
mentioned in commit a02754b9
-
mentioned in commit e164fa4f
-
mentioned in commit 3ccf63d2
-
mentioned in commit 77cd40e2
-
mentioned in commit 413038c8
-
mentioned in commit 51e8fcb7
-
mentioned in commit bdea932d
-
mentioned in commit 37c96d89
-
mentioned in commit 7007a0fc
-
mentioned in commit a3aefd23
-
mentioned in commit be122f60
-
mentioned in commit d7810262
-
mentioned in commit 847114a9
-
mentioned in commit 863cca21
-
mentioned in commit 39ccec24
-
mentioned in commit 4bf595ec
-
mentioned in commit 0c702b8b
-
mentioned in commit daaebf33
-
mentioned in commit 9cd8e79d
-
mentioned in commit 76cf38fd
-
mentioned in commit c0febcbc
-
mentioned in commit 9612f40d
-
mentioned in commit 2302b4e7
-
mentioned in commit a573173d
-
mentioned in commit 0857225b
-
mentioned in commit 8b22241f
-
mentioned in commit 31309b2e
-
mentioned in commit 33888848
-
mentioned in commit a40464ae
-
mentioned in commit 539604ed
-
mentioned in commit e6d8e76f
-
mentioned in commit 6df09bf1
-
mentioned in commit 9af0eada
-
mentioned in commit ea3990b0
-
mentioned in commit 8297097d
-
mentioned in commit 8a8f430b
-
mentioned in commit 381c5a96
-
mentioned in commit ab735bfd
-
mentioned in commit 497f798e
-
mentioned in commit abec726d
-
mentioned in commit c0dee081
-
mentioned in commit 7e603b20
-
mentioned in commit 242ed498
-
mentioned in commit 30909f86
-
mentioned in commit 5a5dcf5c