From: Stefan Hajnoczi <stefanha@redhat.com>
To: "Jiang Wang ." <jiang.wang@bytedance.com>
Cc: cong.wang@bytedance.com,
Xiongchun Duan <duanxiongchun@bytedance.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
cohuck@redhat.com, virtualization@lists.linux-foundation.org,
xieyongji@bytedance.com,
Arseny Krasnov <arseny.krasnov@kaspersky.com>,
asias@redhat.com
Subject: Re: [External] Re: [RFC PATCH] virtio-vsock: add description for datagram type
Date: Tue, 30 Mar 2021 11:42:04 +0100 [thread overview]
Message-ID: <YGMAfBLzcaCMwLJK@stefanha-x1.localdomain> (raw)
In-Reply-To: <CAP_N_Z-v5ZFKO0SNeZre=F6q_+aQohHVQ1fg9oXbfboZgv_xeQ@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 3344 bytes --]
On Mon, Mar 29, 2021 at 04:22:28PM -0700, Jiang Wang . wrote:
> On Mon, Mar 29, 2021 at 2:26 AM Stefan Hajnoczi <stefanha@redhat.com> wrote:
> >
> > On Fri, Mar 26, 2021 at 04:40:09PM -0700, Jiang Wang . wrote:
> > > I thought about this and discussed it with my colleague Cong Wang.
> > > One idea is to make current asynchronous send_pkt flow to be synchronous,
> > > then if the virtqueue is full, the function can return ENOMEM all the way back
> > > to the caller and the caller can check the return value of sendmsg
> > > and slow down when necessary.
> > >
> > > In the spec, we can put something like, if the virtqueue is full, the caller
> > > should be notified with an error etc.
> > >
> > > In terms of implementation, that means we will remove the current
> > > send_pkt_work for both stream and dgram sockets. Currently, the
> > > code path uses RCU and a work queue, then grab a mutex in the
> > > work queue function. Since we cannot grab mutex when in rcu
> > > critical section, we have to change RCU to a normal reference
> > > counting mechanism. I think this is doable. The drawback is
> > > that the reference counting in general spends a little more
> > > cycles than the RCU, so there is a small price to pay. Another
> > > option is to use Sleepable RCU and remove the work queue.
> > >
> > > What do you guys think?
> >
> > I think the tx code path is like this because of reliable delivery.
> > Maybe a separate datagram rx/tx code path would be simpler?
>
> I thought about this too. dgram can have a separate rx/tx
> path from stream types. In this case, the the_virtio_vsock
> will still be shared because the virtqueues have to be in one
> structure. Then the_virtio_vsock will be protected by a rcu
> and a reference counting ( or a sleepable RCU ).
>
> In vhost_vsock_dev_release, it will wait for both rcu and another
> one to be finished and then free the memory. I think this is
> doable. Let me know if there is a better way to do it.
> Btw, I think dgram tx code path will be quite different from
> stream, but dgram rx path will be similar to stream type.
>
> > Take the datagram tx virtqueue lock, try to add the packet into the
> > virtqueue, and return -ENOBUFS if the virtqueue is full. Then use the
> > datagram socket's sndbuf accounting to prevent queuing up too many
> > packets. When a datagram tx virtqueue buffer is used by the device,
> > select queued packets for transmission.
>
> I am not sure about the last sentence. In the new design, there will
> be no other queued packets for dgram (except those in the virtqueue).
> When dgram tx virtqueue is freed by the device, the driver side
> just needs to free some space. No need
> to trigger more transmission.
This approach drops packets when the virtqueue is full. In order to get
close to UDP semantics I think the following is necessary:
1. Packets are placed directly into the tx virtqueue when possible.
2. Packets are queued up to sndbuf bytes if the tx virtqueue is full.
3. When a full tx virtqueue gets some free space again there is an
algorithm that selects from among the queued sockets.
This is how unreliably delivery can be somewhat fair between competing
threads. I thought you were trying to achieve this (it's similar to what
UDP does)?
Stefan
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 183 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2021-03-30 10:42 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 21:56 [RFC PATCH] virtio-vsock: add description for datagram type jiang.wang
2021-03-17 15:44 ` Stefan Hajnoczi
2021-03-18 17:59 ` [External] " Jiang Wang .
2021-03-22 16:50 ` Stefan Hajnoczi
2021-03-22 23:02 ` Jiang Wang .
2021-03-22 23:10 ` Michael S. Tsirkin
2021-03-23 2:23 ` Jiang Wang .
2021-03-23 8:53 ` Stefan Hajnoczi
2021-03-26 23:40 ` Jiang Wang .
2021-03-29 9:25 ` Stefan Hajnoczi
2021-03-29 23:22 ` Jiang Wang .
2021-03-30 10:42 ` Stefan Hajnoczi [this message]
2021-03-30 18:30 ` Jiang Wang .
2021-03-30 15:32 ` Stefano Garzarella
2021-03-30 18:34 ` Jiang Wang .
2021-03-31 1:02 ` Jiang Wang .
2021-03-31 6:42 ` Stefano Garzarella
[not found] ` <CAA68J_bQHzFXnsLpCqZ3waPW1NGz+hnu2OXfAG4XOLemLOX9DQ@mail.gmail.com>
2021-04-26 16:07 ` Stefan Hajnoczi
[not found] ` <CAA68J_Z=1uf5rLCpQeH+m9YmsYGsbJgf2VtRJjQrBd_jTdUYuA@mail.gmail.com>
2021-05-13 16:04 ` Stefan Hajnoczi
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=YGMAfBLzcaCMwLJK@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=arseny.krasnov@kaspersky.com \
--cc=asias@redhat.com \
--cc=cohuck@redhat.com \
--cc=cong.wang@bytedance.com \
--cc=duanxiongchun@bytedance.com \
--cc=jiang.wang@bytedance.com \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xieyongji@bytedance.com \
/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