All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring: account overflows even with IORING_SETUP_CQ_NODROP
@ 2019-11-08 15:51 Jens Axboe
  2019-11-09  9:59 ` Pavel Begunkov
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2019-11-08 15:51 UTC (permalink / raw)
  To: io-uring

It's useful for the application to know if the kernel had to dip into
using the backlog to prevent overflows. Let's keep on accounting any
overflow in cq_ring->overflow, even if we handled it correctly. As it's
impossible to get dropped events with IORING_SETUP_CQ_NODROP, overflow
with CQ_NODROP enabled simply provides a hint to the application that it
may reconsider using a bigger ring.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

Since this hasn't been released yet, we can tweak the behavior a bit. I
think it makes sense to still account the overflows, even if we handled
it correctly. If the application doesn't care, it simply doesn't need to
look at cq_ring->overflow if it is using CQ_NODROP. But it may care, as
it is less efficient than a suitably sized ring.

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 94ec44caac00..aa3b6149dfe9 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -666,10 +666,10 @@ static void io_cqring_overflow(struct io_ring_ctx *ctx, struct io_kiocb *req,
 			       long res)
 	__must_hold(&ctx->completion_lock)
 {
-	if (!(ctx->flags & IORING_SETUP_CQ_NODROP)) {
-		WRITE_ONCE(ctx->rings->cq_overflow,
-				atomic_inc_return(&ctx->cached_cq_overflow));
-	} else {
+	WRITE_ONCE(ctx->rings->cq_overflow,
+			atomic_inc_return(&ctx->cached_cq_overflow));
+
+	if (ctx->flags & IORING_SETUP_CQ_NODROP) {
 		refcount_inc(&req->refs);
 		req->result = res;
 		list_add_tail(&req->list, &ctx->cq_overflow_list);

-- 
Jens Axboe


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

* Re: [PATCH] io_uring: account overflows even with IORING_SETUP_CQ_NODROP
  2019-11-08 15:51 [PATCH] io_uring: account overflows even with IORING_SETUP_CQ_NODROP Jens Axboe
@ 2019-11-09  9:59 ` Pavel Begunkov
  2019-11-09 14:09   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2019-11-09  9:59 UTC (permalink / raw)
  To: Jens Axboe, io-uring


[-- Attachment #1.1: Type: text/plain, Size: 1913 bytes --]

On 08/11/2019 18:51, Jens Axboe wrote:
> It's useful for the application to know if the kernel had to dip into
> using the backlog to prevent overflows. Let's keep on accounting any
> overflow in cq_ring->overflow, even if we handled it correctly. As it's
> impossible to get dropped events with IORING_SETUP_CQ_NODROP, overflow
> with CQ_NODROP enabled simply provides a hint to the application that it
> may reconsider using a bigger ring.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> ---
> 
> Since this hasn't been released yet, we can tweak the behavior a bit. I
> think it makes sense to still account the overflows, even if we handled
> it correctly. If the application doesn't care, it simply doesn't need to
> look at cq_ring->overflow if it is using CQ_NODROP. But it may care, as
> it is less efficient than a suitably sized ring.
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 94ec44caac00..aa3b6149dfe9 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -666,10 +666,10 @@ static void io_cqring_overflow(struct io_ring_ctx *ctx, struct io_kiocb *req,
>  			       long res)
>  	__must_hold(&ctx->completion_lock)
>  {
> -	if (!(ctx->flags & IORING_SETUP_CQ_NODROP)) {
> -		WRITE_ONCE(ctx->rings->cq_overflow,
> -				atomic_inc_return(&ctx->cached_cq_overflow));
> -	} else {
> +	WRITE_ONCE(ctx->rings->cq_overflow,
> +			atomic_inc_return(&ctx->cached_cq_overflow));
> +
> +	if (ctx->flags & IORING_SETUP_CQ_NODROP) {

We used cq_overflow to fix __io_sequence_defer().
This breaks the assumption:
cached_cq_tail + cached_cq_overflow == 
	total number of handled completions

First, we account overflow, and then add it to cq_ring
(i.e. cached_cq_tail++) in io_cqring_overflow_flush()


>  		refcount_inc(&req->refs);
>  		req->result = res;
>  		list_add_tail(&req->list, &ctx->cq_overflow_list);
> 

-- 
Pavel Begunkov




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] io_uring: account overflows even with IORING_SETUP_CQ_NODROP
  2019-11-09  9:59 ` Pavel Begunkov
@ 2019-11-09 14:09   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2019-11-09 14:09 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 11/9/19 2:59 AM, Pavel Begunkov wrote:
> On 08/11/2019 18:51, Jens Axboe wrote:
>> It's useful for the application to know if the kernel had to dip into
>> using the backlog to prevent overflows. Let's keep on accounting any
>> overflow in cq_ring->overflow, even if we handled it correctly. As it's
>> impossible to get dropped events with IORING_SETUP_CQ_NODROP, overflow
>> with CQ_NODROP enabled simply provides a hint to the application that it
>> may reconsider using a bigger ring.
>>
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>>
>> ---
>>
>> Since this hasn't been released yet, we can tweak the behavior a bit. I
>> think it makes sense to still account the overflows, even if we handled
>> it correctly. If the application doesn't care, it simply doesn't need to
>> look at cq_ring->overflow if it is using CQ_NODROP. But it may care, as
>> it is less efficient than a suitably sized ring.
>>
>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>> index 94ec44caac00..aa3b6149dfe9 100644
>> --- a/fs/io_uring.c
>> +++ b/fs/io_uring.c
>> @@ -666,10 +666,10 @@ static void io_cqring_overflow(struct io_ring_ctx *ctx, struct io_kiocb *req,
>>   			       long res)
>>   	__must_hold(&ctx->completion_lock)
>>   {
>> -	if (!(ctx->flags & IORING_SETUP_CQ_NODROP)) {
>> -		WRITE_ONCE(ctx->rings->cq_overflow,
>> -				atomic_inc_return(&ctx->cached_cq_overflow));
>> -	} else {
>> +	WRITE_ONCE(ctx->rings->cq_overflow,
>> +			atomic_inc_return(&ctx->cached_cq_overflow));
>> +
>> +	if (ctx->flags & IORING_SETUP_CQ_NODROP) {
> 
> We used cq_overflow to fix __io_sequence_defer().
> This breaks the assumption:
> cached_cq_tail + cached_cq_overflow ==
> 	total number of handled completions
> 
> First, we account overflow, and then add it to cq_ring
> (i.e. cached_cq_tail++) in io_cqring_overflow_flush()

Yeah, I realized that later, and also the fact that it makes it awkward
to use in a program because of that. I dropped this patch, thanks
for taking a look at it!

-- 
Jens Axboe


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

end of thread, other threads:[~2019-11-09 14:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 15:51 [PATCH] io_uring: account overflows even with IORING_SETUP_CQ_NODROP Jens Axboe
2019-11-09  9:59 ` Pavel Begunkov
2019-11-09 14:09   ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.