* [PATCH] io_uring: fix ctx refcounting in io_submit_sqes()
@ 2020-04-05 21:08 Pavel Begunkov
2020-04-05 21:13 ` Pavel Begunkov
2020-04-05 22:24 ` Jens Axboe
0 siblings, 2 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-04-05 21:08 UTC (permalink / raw)
To: Jens Axboe, io-uring, linux-kernel
If io_get_req() fails, it drops a ref. Then, awhile keeping @submitted
unmodified, io_submit_sqes() breaks the loop and puts @nr - @submitted
refs. For each submitted req a ref is dropped in io_put_req() and
friends. So, for @nr taken refs there will be
(@nr - @submitted + @submitted + 1) dropped.
Remove ctx refcounting from io_get_req(), that at the same time makes
it clearer.
Fixes: 2b85edfc0c90 ("io_uring: batch getting pcpu references")
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 78ae8e8ed5bf..79bd22289d73 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1342,7 +1342,6 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
req = io_get_fallback_req(ctx);
if (req)
goto got_it;
- percpu_ref_put(&ctx->refs);
return NULL;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] io_uring: fix ctx refcounting in io_submit_sqes()
2020-04-05 21:08 [PATCH] io_uring: fix ctx refcounting in io_submit_sqes() Pavel Begunkov
@ 2020-04-05 21:13 ` Pavel Begunkov
2020-04-05 22:25 ` Jens Axboe
2020-04-05 22:24 ` Jens Axboe
1 sibling, 1 reply; 4+ messages in thread
From: Pavel Begunkov @ 2020-04-05 21:13 UTC (permalink / raw)
To: Jens Axboe, io-uring, linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 1163 bytes --]
On 06/04/2020 00:08, Pavel Begunkov wrote:
> If io_get_req() fails, it drops a ref. Then, awhile keeping @submitted
> unmodified, io_submit_sqes() breaks the loop and puts @nr - @submitted
> refs. For each submitted req a ref is dropped in io_put_req() and
> friends. So, for @nr taken refs there will be
> (@nr - @submitted + @submitted + 1) dropped.
>
> Remove ctx refcounting from io_get_req(), that at the same time makes
> it clearer.
It seems, nobody hit OOM, so it stayed unnoticed. And neither did I.
It could be a good idea to do fault-injection for testing.
>
> Fixes: 2b85edfc0c90 ("io_uring: batch getting pcpu references")
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
> fs/io_uring.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 78ae8e8ed5bf..79bd22289d73 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -1342,7 +1342,6 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
> req = io_get_fallback_req(ctx);
> if (req)
> goto got_it;
> - percpu_ref_put(&ctx->refs);
> return NULL;
> }
>
>
--
Pavel Begunkov
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] io_uring: fix ctx refcounting in io_submit_sqes()
2020-04-05 21:13 ` Pavel Begunkov
@ 2020-04-05 22:25 ` Jens Axboe
0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-04-05 22:25 UTC (permalink / raw)
To: Pavel Begunkov, io-uring, linux-kernel
On 4/5/20 3:13 PM, Pavel Begunkov wrote:
> On 06/04/2020 00:08, Pavel Begunkov wrote:
>> If io_get_req() fails, it drops a ref. Then, awhile keeping @submitted
>> unmodified, io_submit_sqes() breaks the loop and puts @nr - @submitted
>> refs. For each submitted req a ref is dropped in io_put_req() and
>> friends. So, for @nr taken refs there will be
>> (@nr - @submitted + @submitted + 1) dropped.
>>
>> Remove ctx refcounting from io_get_req(), that at the same time makes
>> it clearer.
>
> It seems, nobody hit OOM, so it stayed unnoticed. And neither did I.
> It could be a good idea to do fault-injection for testing.
Actually think we just hit this, was testing with memcached (as per fixes
posted recently), and a bug on the user side ended up with 196G of slab
and running into OOM off request allocation.
But yes, would be nice to have specific fault injection testing to
avoid finding these in prod testing.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] io_uring: fix ctx refcounting in io_submit_sqes()
2020-04-05 21:08 [PATCH] io_uring: fix ctx refcounting in io_submit_sqes() Pavel Begunkov
2020-04-05 21:13 ` Pavel Begunkov
@ 2020-04-05 22:24 ` Jens Axboe
1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-04-05 22:24 UTC (permalink / raw)
To: Pavel Begunkov, io-uring, linux-kernel
On 4/5/20 3:08 PM, Pavel Begunkov wrote:
> If io_get_req() fails, it drops a ref. Then, awhile keeping @submitted
> unmodified, io_submit_sqes() breaks the loop and puts @nr - @submitted
> refs. For each submitted req a ref is dropped in io_put_req() and
> friends. So, for @nr taken refs there will be
> (@nr - @submitted + @submitted + 1) dropped.
>
> Remove ctx refcounting from io_get_req(), that at the same time makes
> it clearer.
Applied, but also marked for 5.6 stable.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-04-05 22:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-05 21:08 [PATCH] io_uring: fix ctx refcounting in io_submit_sqes() Pavel Begunkov
2020-04-05 21:13 ` Pavel Begunkov
2020-04-05 22:25 ` Jens Axboe
2020-04-05 22:24 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox