From: Stefano Garzarella <sgarzare@redhat.com>
To: David Carlier <devnexen@gmail.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 1/2] vsock: report pending receive data to io_uring
Date: Tue, 22 Sep 2026 15:56:19 +0200 [thread overview]
Message-ID: <arKF7P9gqq7ehX-k@sgarzare-redhat> (raw)
In-Reply-To: <20260920194710.1114748-2-devnexen@gmail.com>
On Sun, Sep 20, 2026 at 08:47:09PM +0100, David Carlier wrote:
>AF_VSOCK stream receives never fill msghdr.msg_inq, so io_uring cannot set
>IORING_CQE_F_SOCK_NONEMPTY and retries a multishot receive even after the
>queue has been drained.
>
>Fill the hint at the common receive exit using the transport callback that
>SIOCINQ already uses, and report 1 once the connection is finished so the
>caller performs the receive which observes EOF, as TCP does after a FIN.
>
>A vsock loopback ping-pong with io_uring multishot receive drops entries
>into __vsock_connectible_recvmsg from 1.97 to 1.00 per delivered message,
>and receiver CPU time by about 3% (25 runs of 50000 messages, p=0.006).
>
>Signed-off-by: David Carlier <devnexen@gmail.com>
>---
> net/vmw_vsock/af_vsock.c | 39 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index f840498b58af..63309708c916 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -2543,6 +2543,38 @@ static int __vsock_seqpacket_recvmsg(struct sock *sk, struct msghdr *msg,
> return err;
> }
>
>+/* Bytes a following receive can consume, 1 if it would only see EOF, or a
>+ * negative value to leave the caller's hint alone.
>+ *
>+ * Called under the socket lock after a nonnegative stream receive, so a NULL
>+ * transport implies SOCK_DONE.
>+ */
>+static int vsock_inq_hint(struct sock *sk)
can we add "stream" in the name so it's clear that is stream only?
(e.g. vsock_stream_inq_hint)
>+{
>+ struct vsock_sock *vsk = vsock_sk(sk);
>+ s64 data;
>+
>+ if ((sk->sk_shutdown & RCV_SHUTDOWN) ||
>+ (sock_flag(sk, SOCK_DONE) && sk->sk_state != TCP_ESTABLISHED))
>+ return 1;
>+
>+ if (!vsk->transport)
>+ return 1;
Can we squash this in the previous block?
>+
>+ data = vsock_stream_has_data(vsk);
>+ if (data < 0)
>+ return -1;
>+ if (data > 0)
>+ return (int)min_t(s64, data, INT_MAX);
nit: IMO we can remove the int cast.
>+
>+ /* Empty but finished: keep the caller reading so it sees EOF. */
>+ if (sock_flag(sk, SOCK_DONE) ||
>+ (READ_ONCE(vsk->peer_shutdown) & SEND_SHUTDOWN))
>+ return 1;
>+
>+ return 0;
>+}
>+
> int
> __vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
> int flags)
>@@ -2606,6 +2638,13 @@ __vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
> err = __vsock_seqpacket_recvmsg(sk, msg, len, flags);
>
> out:
>+ if (msg->msg_get_inq && err >= 0 && sk->sk_type == SOCK_STREAM) {
Why only STREAM?
A comment here and in the commit would be nice.
>+ int inq = vsock_inq_hint(sk);
>+
>+ if (inq >= 0)
Why assigning only >= 0 values?
Thanks,
Stefano
>+ msg->msg_inq = inq;
>+ }
>+
> release_sock(sk);
> return err;
> }
>--
>2.55.0
>
next prev parent reply other threads:[~2026-09-22 13:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 19:47 [PATCH net-next 0/2] vsock: receive queue hint for io_uring David Carlier
2026-09-20 19:47 ` [PATCH net-next 1/2] vsock: report pending receive data to io_uring David Carlier
2026-09-22 13:56 ` Stefano Garzarella [this message]
2026-09-22 20:31 ` David CARLIER
2026-09-20 19:47 ` [PATCH net-next 2/2] vsock/test: cover receive queue hints David Carlier
2026-09-22 14:49 ` Stefano Garzarella
2026-09-22 17:34 ` Bobby Eshleman
2026-09-22 20:37 ` David CARLIER
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=arKF7P9gqq7ehX-k@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=davem@davemloft.net \
--cc=devnexen@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
/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
all inboxes | Powered by JetHome®