From: Stefan Hajnoczi <[email protected]>
To: Ming Lei <[email protected]>
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: Re: Resizing io_uring SQ/CQ?
Date: Fri, 10 Mar 2023 11:39:21 -0500 [thread overview]
Message-ID: <20230310163921.GA484401@fedora> (raw)
In-Reply-To: <[email protected]>
[-- Attachment #1: Type: text/plain, Size: 5070 bytes --]
On Fri, Mar 10, 2023 at 11:14:04PM +0800, Ming Lei wrote:
> On Fri, Mar 10, 2023 at 08:44:00AM -0500, Stefan Hajnoczi wrote:
> > On Thu, Mar 09, 2023 at 07:58:31PM -0700, Jens Axboe wrote:
> > > On 3/9/23 6:38?PM, Ming Lei wrote:
> > > > On Thu, Mar 09, 2023 at 08:48:08AM -0500, Stefan Hajnoczi wrote:
> > > >> Hi,
> > > >> For block I/O an application can queue excess SQEs in userspace when the
> > > >> SQ ring becomes full. For network and IPC operations that is not
> > > >> possible because deadlocks can occur when socket, pipe, and eventfd SQEs
> > > >> cannot be submitted.
> > > >
> > > > Can you explain a bit the deadlock in case of network application? io_uring
> > > > does support to queue many network SQEs via IOSQE_IO_LINK, at least for
> > > > send.
> > > >
> > > >>
> > > >> Sometimes the application does not know how many SQEs/CQEs are needed upfront
> > > >> and that's when we face this challenge.
> > > >
> > > > When running out of SQEs, the application can call io_uring_enter() to submit
> > > > queued SQEs immediately without waiting for get events, then once
> > > > io_uring_enter() returns, you get free SQEs for moving one.
> > > >
> > > >>
> > > >> A simple solution is to call io_uring_setup(2) with a higher entries
> > > >> value than you'll ever need. However, if that value is exceeded then
> > > >> we're back to the deadlock scenario and that worries me.
> > > >
> > > > Can you please explain the deadlock scenario?
> > >
> > > I'm also curious of what these deadlocks are. As Ming says, you
> > > generally never run out of SQEs as you can always just submit what you
> > > have pending and now you have a full queue size worth of them available
> > > again.
> > >
> > > I do think resizing the CQ ring may have some merit, as for networking
> > > you may want to start smaller and resize it if you run into overflows as
> > > those will be less efficient. But I'm somewhat curious on the reasonings
> > > for wanting to resize the SQ ring?
> >
> > Hi Ming and Jens,
> > Thanks for the response. I'll try to explain why I worry about
> > deadlocks.
> >
> > Imagine an application has an I/O operation that must complete in order
> > to make progress. If io_uring_enter(2) fails then the application is
> > unable to submit that critical I/O.
> >
> > The io_uring_enter(2) man page says:
> >
> > EBUSY If the IORING_FEAT_NODROP feature flag is set, then EBUSY will
> > be returned if there were overflow entries,
> > IORING_ENTER_GETEVENTS flag is set and not all of the overflow
> > entries were able to be flushed to the CQ ring.
> >
> > Without IORING_FEAT_NODROP the application is attempting to
> > overcommit the number of requests it can have pending. The
> > application should wait for some completions and try again. May
> > occur if the application tries to queue more requests than we
> > have room for in the CQ ring, or if the application attempts to
> > wait for more events without having reaped the ones already
> > present in the CQ ring.
> >
> > Some I/O operations can take forever (e.g. reading an eventfd), so there
> > is no guarantee that the I/Os already in flight will complete. If in
> > flight I/O operations accumulate to the point where io_uring_enter(2)
> > returns with EBUSY then the application is starved and unable to submit
>
> The man page said clearly that EBUSY will be returned if there were overflow
> CQE entries. But here, no in-flight IOs are completed and no CQEs actually in
> CQ ring, so how can the -EBUSY be triggered?
>
> Also I don't see any words about the following description:
>
> -EBUSY will be returned if many enough in-flight IOs are accumulated,
>
> So care to explain it a bit?
Thanks, Ming. I think it's because I wasn't considering IORING_FEAT_NODROP!
Can you confirm that io_uring_enter() with IORING_FEAT_NODROP always
succeeds in submitting more requests (except for out-of-memory) provided
the application keeps consuming the CQ ring? If yes, then
IORING_FEAT_NODROP solves the issue on Linux 5.5 and later.
Regarding the non-IORING_FEAT_NODROP case, I think the deadlock issue
exists:
Without IORING_FEAT_NODROP the application is attempting to overcommit
the number of requests it can have pending.
A general statement that does not mention the CQ ring.
The application should wait for some completions and try again.
Doesn't help in the deadlock scenario because we must submit one more
I/O in order for existing I/Os to start completing.
May occur if the application tries to queue more requests than we
have room for in the CQ ring,
I interpreted this to mean that once there are cq_entries I/Os in
flight, then io_uring_enter(2) may return with EBUSY if you attempt to
submit more I/Os. Is that right?
or if the application attempts to wait for more events without having
reaped the ones already present in the CQ ring.
This doesn't apply to the deadlock scenario.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2023-03-10 16:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 13:48 Resizing io_uring SQ/CQ? Stefan Hajnoczi
2023-03-10 1:38 ` Ming Lei
2023-03-10 2:58 ` Jens Axboe
2023-03-10 3:42 ` Vito Caputo
2023-03-10 13:44 ` Stefan Hajnoczi
2023-03-10 15:14 ` Ming Lei
2023-03-10 16:39 ` Stefan Hajnoczi [this message]
2023-03-10 16:56 ` Stefan Hajnoczi
2023-03-15 15:18 ` Jens Axboe
2023-03-15 15:15 ` Stefan Hajnoczi
2023-03-15 15:19 ` Jens Axboe
2023-03-15 19:01 ` Stefan Hajnoczi
2023-03-15 19:10 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230310163921.GA484401@fedora \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox