IO-Uring Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/4] small random patches
@ 2020-06-21 10:09 Pavel Begunkov
  2020-06-21 10:09 ` [PATCH 1/4] io_uring: remove setting REQ_F_MUST_PUNT in rw Pavel Begunkov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Pavel Begunkov @ 2020-06-21 10:09 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

Nothing interesting, just killing some stuff first.
Based on top of io_uring-5.8 + 15 async-buf patches.

Pavel Begunkov (4):
  io_uring: remove setting REQ_F_MUST_PUNT in rw
  io_uring: remove REQ_F_MUST_PUNT
  io_uring: set @poll->file after @poll init
  io_uring: kill NULL checks for submit state

 fs/io_uring.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] io_uring: remove setting REQ_F_MUST_PUNT in rw
  2020-06-21 10:09 [PATCH 0/4] small random patches Pavel Begunkov
@ 2020-06-21 10:09 ` Pavel Begunkov
  2020-06-21 10:09 ` [PATCH 2/4] io_uring: remove REQ_F_MUST_PUNT Pavel Begunkov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2020-06-21 10:09 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

io_{read,write}() {
	...
copy_iov: // prep async
  	if (!(flags & REQ_F_NOWAIT) && !file_can_poll(file))
		flags |= REQ_F_MUST_PUNT;
}

REQ_F_MUST_PUNT there is pointless, because if it happens then
REQ_F_NOWAIT is known to be _not_ set, and the request will go
async path in __io_queue_sqe() anyway. file_can_poll() check
is also repeated in arm_poll*(), so don't need it.

Remove the mentioned assignment REQ_F_MUST_PUNT in preparation
for killing the flag.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 44614571e285..e7ce1608087f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2915,10 +2915,6 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
 						inline_vecs, &iter);
 			if (ret)
 				goto out;
-			/* any defer here is final, must blocking retry */
-			if (!(req->flags & REQ_F_NOWAIT) &&
-			    !file_can_poll(req->file))
-				req->flags |= REQ_F_MUST_PUNT;
 			/* if we can retry, do so with the callbacks armed */
 			if (io_rw_should_retry(req)) {
 				ret2 = io_iter_do_read(req, &iter);
@@ -3050,10 +3046,6 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
 						inline_vecs, &iter);
 			if (ret)
 				goto out_free;
-			/* any defer here is final, must blocking retry */
-			if (!(req->flags & REQ_F_NOWAIT) &&
-			    !file_can_poll(req->file))
-				req->flags |= REQ_F_MUST_PUNT;
 			return -EAGAIN;
 		}
 	}
-- 
2.24.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] io_uring: remove REQ_F_MUST_PUNT
  2020-06-21 10:09 [PATCH 0/4] small random patches Pavel Begunkov
  2020-06-21 10:09 ` [PATCH 1/4] io_uring: remove setting REQ_F_MUST_PUNT in rw Pavel Begunkov
@ 2020-06-21 10:09 ` Pavel Begunkov
  2020-06-21 10:09 ` [PATCH 3/4] io_uring: set @poll->file after @poll init Pavel Begunkov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2020-06-21 10:09 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

REQ_F_MUST_PUNT may seem looking good and clear, but it's the same
as not having REQ_F_NOWAIT set. That rather creates more confusion.
Moreover, it doesn't even affect any behaviour (e.g. see the patch
removing it from io_{read,write}).

Kill theg flag and update already outdated comments.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index e7ce1608087f..84b39109bc30 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -534,7 +534,6 @@ enum {
 	REQ_F_LINK_TIMEOUT_BIT,
 	REQ_F_TIMEOUT_BIT,
 	REQ_F_ISREG_BIT,
-	REQ_F_MUST_PUNT_BIT,
 	REQ_F_TIMEOUT_NOSEQ_BIT,
 	REQ_F_COMP_LOCKED_BIT,
 	REQ_F_NEED_CLEANUP_BIT,
@@ -582,8 +581,6 @@ enum {
 	REQ_F_TIMEOUT		= BIT(REQ_F_TIMEOUT_BIT),
 	/* regular file */
 	REQ_F_ISREG		= BIT(REQ_F_ISREG_BIT),
-	/* must be punted even for NONBLOCK */
-	REQ_F_MUST_PUNT		= BIT(REQ_F_MUST_PUNT_BIT),
 	/* no timeout sequence */
 	REQ_F_TIMEOUT_NOSEQ	= BIT(REQ_F_TIMEOUT_NOSEQ_BIT),
 	/* completion under lock */
@@ -2889,10 +2886,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
 	if (req->flags & REQ_F_LINK_HEAD)
 		req->result = io_size;
 
-	/*
-	 * If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
-	 * we know to async punt it even if it was opened O_NONBLOCK
-	 */
+	/* If the file doesn't support async, just async punt */
 	if (force_nonblock && !io_file_supports_async(req->file, READ))
 		goto copy_iov;
 
@@ -2986,10 +2980,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
 	if (req->flags & REQ_F_LINK_HEAD)
 		req->result = io_size;
 
-	/*
-	 * If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
-	 * we know to async punt it even if it was opened O_NONBLOCK
-	 */
+	/* If the file doesn't support async, just async punt */
 	if (force_nonblock && !io_file_supports_async(req->file, WRITE))
 		goto copy_iov;
 
@@ -3710,8 +3701,10 @@ static int io_close(struct io_kiocb *req, bool force_nonblock)
 
 	/* if the file has a flush method, be safe and punt to async */
 	if (close->put_file->f_op->flush && force_nonblock) {
+		/* was never set, but play safe */
+		req->flags &= ~REQ_F_NOWAIT;
 		/* avoid grabbing files - we don't need the files */
-		req->flags |= REQ_F_NO_FILE_TABLE | REQ_F_MUST_PUNT;
+		req->flags |= REQ_F_NO_FILE_TABLE;
 		return -EAGAIN;
 	}
 
@@ -4634,7 +4627,7 @@ static bool io_arm_poll_handler(struct io_kiocb *req)
 
 	if (!req->file || !file_can_poll(req->file))
 		return false;
-	if (req->flags & (REQ_F_MUST_PUNT | REQ_F_POLLED))
+	if (req->flags & REQ_F_POLLED)
 		return false;
 	if (!def->pollin && !def->pollout)
 		return false;
@@ -5837,8 +5830,7 @@ static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	 * We async punt it if the file wasn't marked NOWAIT, or if the file
 	 * doesn't support non-blocking read/write attempts
 	 */
-	if (ret == -EAGAIN && (!(req->flags & REQ_F_NOWAIT) ||
-	    (req->flags & REQ_F_MUST_PUNT))) {
+	if (ret == -EAGAIN && !(req->flags & REQ_F_NOWAIT)) {
 		if (io_arm_poll_handler(req)) {
 			if (linked_timeout)
 				io_queue_linked_timeout(linked_timeout);
-- 
2.24.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] io_uring: set @poll->file after @poll init
  2020-06-21 10:09 [PATCH 0/4] small random patches Pavel Begunkov
  2020-06-21 10:09 ` [PATCH 1/4] io_uring: remove setting REQ_F_MUST_PUNT in rw Pavel Begunkov
  2020-06-21 10:09 ` [PATCH 2/4] io_uring: remove REQ_F_MUST_PUNT Pavel Begunkov
@ 2020-06-21 10:09 ` Pavel Begunkov
  2020-06-21 10:09 ` [PATCH 4/4] io_uring: kill NULL checks for submit state Pavel Begunkov
  2020-06-22  3:06 ` [PATCH 0/4] small random patches Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2020-06-21 10:09 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

It's a good practice to modify fields of a struct after but not before
it was initialised. Even though io_init_poll_iocb() doesn't touch
poll->file, call it first.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 84b39109bc30..676911260f60 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4585,8 +4585,8 @@ static __poll_t __io_arm_poll_handler(struct io_kiocb *req,
 	struct io_ring_ctx *ctx = req->ctx;
 	bool cancel = false;
 
-	poll->file = req->file;
 	io_init_poll_iocb(poll, mask, wake_func);
+	poll->file = req->file;
 	poll->wait.private = req;
 
 	ipt->pt._key = mask;
-- 
2.24.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] io_uring: kill NULL checks for submit state
  2020-06-21 10:09 [PATCH 0/4] small random patches Pavel Begunkov
                   ` (2 preceding siblings ...)
  2020-06-21 10:09 ` [PATCH 3/4] io_uring: set @poll->file after @poll init Pavel Begunkov
@ 2020-06-21 10:09 ` Pavel Begunkov
  2020-06-22  3:06 ` [PATCH 0/4] small random patches Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2020-06-21 10:09 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

After recent changes, io_submit_sqes() always passes valid submit state,
so kill leftovers checking it for NULL.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 676911260f60..0bcf819e9661 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1371,11 +1371,7 @@ static struct io_kiocb *io_alloc_req(struct io_ring_ctx *ctx,
 	gfp_t gfp = GFP_KERNEL | __GFP_NOWARN;
 	struct io_kiocb *req;
 
-	if (!state) {
-		req = kmem_cache_alloc(req_cachep, gfp);
-		if (unlikely(!req))
-			goto fallback;
-	} else if (!state->free_reqs) {
+	if (!state->free_reqs) {
 		size_t sz;
 		int ret;
 
-- 
2.24.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] small random patches
  2020-06-21 10:09 [PATCH 0/4] small random patches Pavel Begunkov
                   ` (3 preceding siblings ...)
  2020-06-21 10:09 ` [PATCH 4/4] io_uring: kill NULL checks for submit state Pavel Begunkov
@ 2020-06-22  3:06 ` Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2020-06-22  3:06 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring, linux-kernel

On 6/21/20 4:09 AM, Pavel Begunkov wrote:
> Nothing interesting, just killing some stuff first.
> Based on top of io_uring-5.8 + 15 async-buf patches.
> 
> Pavel Begunkov (4):
>   io_uring: remove setting REQ_F_MUST_PUNT in rw
>   io_uring: remove REQ_F_MUST_PUNT
>   io_uring: set @poll->file after @poll init
>   io_uring: kill NULL checks for submit state
> 
>  fs/io_uring.c | 38 +++++++++-----------------------------
>  1 file changed, 9 insertions(+), 29 deletions(-)

Thanks, applied.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-21 10:09 [PATCH 0/4] small random patches Pavel Begunkov
2020-06-21 10:09 ` [PATCH 1/4] io_uring: remove setting REQ_F_MUST_PUNT in rw Pavel Begunkov
2020-06-21 10:09 ` [PATCH 2/4] io_uring: remove REQ_F_MUST_PUNT Pavel Begunkov
2020-06-21 10:09 ` [PATCH 3/4] io_uring: set @poll->file after @poll init Pavel Begunkov
2020-06-21 10:09 ` [PATCH 4/4] io_uring: kill NULL checks for submit state Pavel Begunkov
2020-06-22  3:06 ` [PATCH 0/4] small random patches Jens Axboe

IO-Uring Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/io-uring/0 io-uring/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 io-uring io-uring/ https://lore.kernel.org/io-uring \
		io-uring@vger.kernel.org
	public-inbox-index io-uring

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.io-uring


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git