public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: prevent sq_thread from spinning when it should stop
@ 2020-02-21 15:42 Stefano Garzarella
  2020-02-21 16:16 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Garzarella @ 2020-02-21 15:42 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-fsdevel, linux-kernel, Alexander Viro, Hannes Reinecke,
	io-uring

This patch drops 'cur_mm' before calling cond_resched(), to prevent
the sq_thread from spinning even when the user process is finished.

Before this patch, if the user process ended without closing the
io_uring fd, the sq_thread continues to spin until the
'sq_thread_idle' timeout ends.

In the worst case where the 'sq_thread_idle' parameter is bigger than
INT_MAX, the sq_thread will spin forever.

Fixes: 6c271ce2f1d5 ("io_uring: add submission polling")
Signed-off-by: Stefano Garzarella <[email protected]>
---

Hi Jens,
I'm also sending a test to liburing for this case.

Cheers,
Stefano
---
 fs/io_uring.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 5a826017ebb8..f902f77964ef 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -5138,6 +5138,18 @@ static int io_sq_thread(void *data)
 		 * to enter the kernel to reap and flush events.
 		 */
 		if (!to_submit || ret == -EBUSY) {
+			/*
+			 * Drop cur_mm before scheduling, we can't hold it for
+			 * long periods (or over schedule()). Do this before
+			 * adding ourselves to the waitqueue, as the unuse/drop
+			 * may sleep.
+			 */
+			if (cur_mm) {
+				unuse_mm(cur_mm);
+				mmput(cur_mm);
+				cur_mm = NULL;
+			}
+
 			/*
 			 * We're polling. If we're within the defined idle
 			 * period, then let us spin without work before going
@@ -5152,18 +5164,6 @@ static int io_sq_thread(void *data)
 				continue;
 			}
 
-			/*
-			 * Drop cur_mm before scheduling, we can't hold it for
-			 * long periods (or over schedule()). Do this before
-			 * adding ourselves to the waitqueue, as the unuse/drop
-			 * may sleep.
-			 */
-			if (cur_mm) {
-				unuse_mm(cur_mm);
-				mmput(cur_mm);
-				cur_mm = NULL;
-			}
-
 			prepare_to_wait(&ctx->sqo_wait, &wait,
 						TASK_INTERRUPTIBLE);
 
-- 
2.24.1


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

* Re: [PATCH] io_uring: prevent sq_thread from spinning when it should stop
  2020-02-21 15:42 [PATCH] io_uring: prevent sq_thread from spinning when it should stop Stefano Garzarella
@ 2020-02-21 16:16 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2020-02-21 16:16 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: linux-fsdevel, linux-kernel, Alexander Viro, Hannes Reinecke,
	io-uring

On 2/21/20 8:42 AM, Stefano Garzarella wrote:
> This patch drops 'cur_mm' before calling cond_resched(), to prevent
> the sq_thread from spinning even when the user process is finished.
> 
> Before this patch, if the user process ended without closing the
> io_uring fd, the sq_thread continues to spin until the
> 'sq_thread_idle' timeout ends.
> 
> In the worst case where the 'sq_thread_idle' parameter is bigger than
> INT_MAX, the sq_thread will spin forever.

Thanks, applied.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-02-21 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-21 15:42 [PATCH] io_uring: prevent sq_thread from spinning when it should stop Stefano Garzarella
2020-02-21 16:16 ` Jens Axboe

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