Re: [PATCH 08/15] io_uring: don't sleep when polling for I/O

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 5/12/21 6:15 AM, Christoph Hellwig wrote:
There is no point in sleeping for the expected I/O completion timeout
in the io_uring async polling model as we never poll for a specific
I/O.  Split the boolean spin argument to blk_poll into a set of flags
to control sleeping and the oneshot behavior separately.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
  block/blk-mq.c           | 18 ++++++++----------
  drivers/nvme/host/core.c |  2 +-
  fs/block_dev.c           |  8 ++++----
  fs/io_uring.c            | 14 +++++++-------
  fs/iomap/direct-io.c     |  6 +++---
  include/linux/blkdev.h   |  6 +++++-
  include/linux/fs.h       |  2 +-
  include/linux/iomap.h    |  2 +-
  mm/page_io.c             |  2 +-
  9 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index ac0b517c5503..164e39d34bf6 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3873,7 +3873,7 @@ static bool blk_mq_poll_hybrid(struct request_queue *q, blk_qc_t qc)
  }
static int blk_mq_poll_classic(struct request_queue *q, blk_qc_t cookie,
-		bool spin)
+		unsigned int flags)
  {
  	struct blk_mq_hw_ctx *hctx = blk_qc_to_hctx(q, cookie);
  	long state = current->state;
@@ -3896,7 +3896,7 @@ static int blk_mq_poll_classic(struct request_queue *q, blk_qc_t cookie,
  		if (current->state == TASK_RUNNING)
  			return 1;
- if (ret < 0 || !spin)
+		if (ret < 0 || (flags & BLK_POLL_ONESHOT))
  			break;
  		cpu_relax();
  	} while (!need_resched());
@@ -3909,15 +3909,13 @@ static int blk_mq_poll_classic(struct request_queue *q, blk_qc_t cookie,
   * blk_poll - poll for IO completions
   * @q:  the queue
   * @cookie: cookie passed back at IO submission time
- * @spin: whether to spin for completions
+ * @flags: BLK_POLL_* flags that control the behavior
   *
   * Description:
   *    Poll for completions on the passed in queue. Returns number of
- *    completed entries found. If @spin is true, then blk_poll will continue
- *    looping until at least one completion is found, unless the task is
- *    otherwise marked running (or we need to reschedule).
+ *    completed entries found.
   */
-int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin)
+int blk_poll(struct request_queue *q, blk_qc_t cookie, unsigned int flags)
  {
  	if (cookie == BLK_QC_T_NONE ||
  	    !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
@@ -3926,12 +3924,12 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin)
  	if (current->plug)
  		blk_flush_plug_list(current->plug, false);
- /* If specified not to spin, we also should not sleep. */
-	if (spin && q->poll_nsec != BLK_MQ_POLL_CLASSIC) {
+	if (!(flags & BLK_POLL_NOSLEEP) &&
+	    q->poll_nsec != BLK_MQ_POLL_CLASSIC) {
  		if (blk_mq_poll_hybrid(q, cookie))
  			return 1;
  	}
-	return blk_mq_poll_classic(q, cookie, spin);
+	return blk_mq_poll_classic(q, cookie, flags);

I think that the combination of oneshot and nosleep flags to replace
a boolen spin is a little hard to follow (especially that spin doesn't
mean spinning without sleeping).

Maybe we should break it to:
1. replace spin to flags with ONESHOT passed from io_uring (direct
   replacement)
2. add NOSLEEP passed from io_uring as there is no need for it.

Just a suggestion though that would help (me at least) to follow
this more easily.



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux