public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH for-next] io_uring: remove ctx referencing from complete_post
@ 2021-09-15 11:04 Pavel Begunkov
  2021-09-15 13:00 ` Hao Xu
  2021-09-16  1:53 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel Begunkov @ 2021-09-15 11:04 UTC (permalink / raw)
  To: Jens Axboe, io-uring

Now completions are done from task context, that means that it's either
the task itself, task_work or io-wq worker. In all those cases the ctx
will be staying alive by mutexing, explicit referencing or req
references by iowq. Remove extra ctx pinning from
io_req_complete_post().

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 511fb8052ae9..c23f3218d52b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1816,17 +1816,11 @@ static void io_req_complete_post(struct io_kiocb *req, long res,
 		io_put_task(req->task, 1);
 		list_add(&req->inflight_entry, &ctx->locked_free_list);
 		ctx->locked_free_nr++;
-	} else {
-		if (!percpu_ref_tryget(&ctx->refs))
-			req = NULL;
+		percpu_ref_put(&ctx->refs);
 	}
 	io_commit_cqring(ctx);
 	spin_unlock(&ctx->completion_lock);
-
-	if (req) {
-		io_cqring_ev_posted(ctx);
-		percpu_ref_put(&ctx->refs);
-	}
+	io_cqring_ev_posted(ctx);
 }
 
 static inline bool io_req_needs_clean(struct io_kiocb *req)
-- 
2.33.0


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

* Re: [PATCH for-next] io_uring: remove ctx referencing from complete_post
  2021-09-15 11:04 [PATCH for-next] io_uring: remove ctx referencing from complete_post Pavel Begunkov
@ 2021-09-15 13:00 ` Hao Xu
  2021-09-15 13:07   ` Pavel Begunkov
  2021-09-16  1:53 ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Hao Xu @ 2021-09-15 13:00 UTC (permalink / raw)
  To: Pavel Begunkov, Jens Axboe, io-uring

在 2021/9/15 下午7:04, Pavel Begunkov 写道:
> Now completions are done from task context, that means that it's either
> the task itself, task_work or io-wq worker. In all those cases the ctx
system-wq as well, not sure if that matters.
> will be staying alive by mutexing, explicit referencing or req
> references by iowq. Remove extra ctx pinning from
> io_req_complete_post().

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

* Re: [PATCH for-next] io_uring: remove ctx referencing from complete_post
  2021-09-15 13:00 ` Hao Xu
@ 2021-09-15 13:07   ` Pavel Begunkov
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2021-09-15 13:07 UTC (permalink / raw)
  To: Hao Xu, Jens Axboe, io-uring

On 9/15/21 2:00 PM, Hao Xu wrote:
> 在 2021/9/15 下午7:04, Pavel Begunkov 写道:
>> Now completions are done from task context, that means that it's either
>> the task itself, task_work or io-wq worker. In all those cases the ctx
> system-wq as well, not sure if that matters.

Yep, missed in the description.
fwiw, io_fallback_req_func() explicitly pins ctx.


>> will be staying alive by mutexing, explicit referencing or req
>> references by iowq. Remove extra ctx pinning from
>> io_req_complete_post().

-- 
Pavel Begunkov

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

* Re: [PATCH for-next] io_uring: remove ctx referencing from complete_post
  2021-09-15 11:04 [PATCH for-next] io_uring: remove ctx referencing from complete_post Pavel Begunkov
  2021-09-15 13:00 ` Hao Xu
@ 2021-09-16  1:53 ` Jens Axboe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2021-09-16  1:53 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 9/15/21 5:04 AM, Pavel Begunkov wrote:
> Now completions are done from task context, that means that it's either
> the task itself, task_work or io-wq worker. In all those cases the ctx
> will be staying alive by mutexing, explicit referencing or req
> references by iowq. Remove extra ctx pinning from
> io_req_complete_post().

Applied, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2021-09-16  1:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-15 11:04 [PATCH for-next] io_uring: remove ctx referencing from complete_post Pavel Begunkov
2021-09-15 13:00 ` Hao Xu
2021-09-15 13:07   ` Pavel Begunkov
2021-09-16  1:53 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox