Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: physicalmtea@gmail.com
Cc: stefanha@redhat.com, sgarzare@redhat.com, mst@redhat.com,
	jasowangio@gmail.com, eperezma@redhat.com,
	xuanzhuo@linux.alibaba.com, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, virtualization@lists.linux.dev,
	kvm@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v3 3/4] vsock/virtio: coalesce RX write-space notifications in lock batches
Date: Wed, 14 Oct 2026 06:33:01 +0000	[thread overview]
Message-ID: <179195958167.434549.3993403899530916978@kernel.org> (raw)
In-Reply-To: <20261013063112.168321-4-physicalmtea@gmail.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch is presented purely as a performance optimisation but
  gives no numbers.
- [Low] Retained for the separate validation policy; my baseline decision
  is that this is not a real defect.
- [Low] The patch changes the behaviour of three interfaces without
  updating their comments.

--

vsock/virtio: coalesce RX write-space notifications in lock batches

This commit stops calling sk_write_space() for every packet in a virtio
vsock RX lock batch. It records one pending notification and delivers it
through the saved default callback before release_sock(). The default
callback is saved in __vsock_create(), and sockets whose sk_write_space
has been replaced are no longer eligible for batching.

> Each received packet updates peer credit and calls sk_write_space() when
> send space is available. A writer cannot use the newly advertised credit
> until the socket lock is released, so repeated callbacks within one lock
> batch cannot let it make progress sooner.

[Severity: Low]
This shows that the change is safe, but are there any numbers showing it
helps? Neither this commit message nor the other three in the series
gives throughput, CPU or wakeup-count data, or names a workload where
per-packet sk_write_space() costs something measurable.

The change does have costs. Every struct vsock_sock gets a new function
pointer, including VMCI and Hyper-V sockets, but only the virtio RX batch
path reads it. virtio_transport_recv_pkt_batchable() gets one more
admission condition. The wakeup moves to
virtio_transport_rx_batch_finish().

The callback being coalesced is also cheap when nobody is waiting.
sock_def_write_space() only calls sock_writeable(), skwq_has_sleeper()
and sk_wake_async_rcu().

Documentation/process/submitting-patches.rst says:

  Quantify optimizations and trade-offs. If you claim improvements in
  performance ... include numbers that back them up. But also describe
  non-obvious costs.

Could the commit message include measurements that justify the extra
per-socket field?

> diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
> index 5549298c1ec6b..9d8ae62209eda 100644
> --- a/include/net/af_vsock.h
> +++ b/include/net/af_vsock.h
> @@ -63,6 +63,8 @@ struct vsock_sock {
>  	u32 peer_shutdown;
>  	bool sent_request;
>  	bool ignore_connecting_rst;
> +	/* Initial callback, used to identify replacements. */
> +	void (*default_write_space)(struct sock *sk);

[Severity: Low]
This comment only describes the identification role.
virtio_transport_rx_batch_finish() also calls this pointer to deliver
deferred notifications. Should the comment say that too?

Two other comments are also unchanged by this patch.

The comment above the exported virtio_transport_rx_batch_finish() still
reads:

  For a non-empty batch, the caller must hold the socket lock acquired with
  lock_sock(). This function releases the lock and the batch's lookup
  reference.

It does not say that a write-space callback now runs from this function
while the socket lock is still held. At the end of the series it also
runs a data-ready callback after release_sock(), and the comment is
still the same.

The comment above virtio_transport_recv_pkt_locked() documents
@batchable and the return value, but not the new @batch parameter:

  The caller holds sk's socket lock.  Set @batchable if the socket can remain
  locked for another ordinary STREAM/RW packet.  Return true if the caller
  must free @skb.

A non-NULL @batch suppresses the immediate sk->sk_write_space() call and
defers it to batch finish. Could these comments be updated to match?

[ ... ]

> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> index bfe40ecf0b2f0..d6ebfde880db6 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c

[ ... ]

> @@ -1860,8 +1862,12 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t,
>  	if (vsk->local_addr.svm_cid != VMADDR_CID_ANY)
>  		vsk->local_addr.svm_cid = dst->svm_cid;
>  
> -	if (space_available)
> -		sk->sk_write_space(sk);
> +	if (space_available) {
> +		if (batch)
> +			batch->write_space_pending = true;
> +		else
> +			sk->sk_write_space(sk);
> +	}

[ ... ]

> @@ -1954,15 +1960,20 @@ EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt);
>   */
>  void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch)
>  {
> +	bool write_space_pending = batch->write_space_pending;
>  	struct sock *sk = batch->sk;
>  
>  	batch->sk = NULL;
>  	batch->pkts = 0;
>  	batch->bytes = 0;
> +	batch->write_space_pending = false;
>  
>  	if (!sk)
>  		return;
>  
> +	if (write_space_pending)
> +		vsock_sk(sk)->default_write_space(sk);

[Severity: Low]
Is it intended to call the saved default callback here rather than the
current sk->sk_write_space?

sock_map_update_elem() from BPF takes only bh_lock_sock(). It can
therefore attach a psock while the RX batch holds lock_sock(). In that
case sk_psock_start_verdict() does:

	WRITE_ONCE(sk->sk_write_space, sk_psock_write_space);

A notification latched for a packet admitted before the attach would
then skip sk_psock_write_space(), which is what schedules psock->work.

>From a closer look, this may be harmless:

- virtio_transport_sock_has_psock() is checked at every packet
  boundary, and the psock is published before sk_write_space is
  replaced. So only a packet admitted before that point can leave a
  pending notification. That is the same outcome as the pre-series case
  where the attach lands just after that packet's own sk_write_space()
  call.

- The next packet fails admission and takes the non-batched path, which
  calls the new sk_psock_write_space().

- sk_psock_backlog() reschedules itself with
  schedule_delayed_work(&psock->work, 1) on -EAGAIN. It is also
  scheduled on enqueue, so psock TX should not stall.

- sk_psock_write_space() forwards to psock->saved_write_space, so
  user-space writers get the same wakeup either way.

If that reasoning holds, would a short comment explaining why it is safe
to bypass a callback installed mid-batch help future readers?

> +
>  	release_sock(sk);
>  	sock_put(sk);
>  }

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261013063112.168321-1-physicalmtea%40gmail.com

  reply	other threads:[~2026-10-14  6:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  6:31 [PATCH net-next v3 0/4] vsock/virtio: reduce RX per-packet socket overhead Jia Jia
2026-10-13  6:31 ` [PATCH net-next v3 1/4] vsock/virtio: split socket lookup from locked RX processing Jia Jia
2026-10-13  6:31 ` [PATCH net-next v3 2/4] vsock/virtio: amortize RX socket locking for stream packets Jia Jia
2026-10-14  6:33   ` netdev-bot+sashiko
2026-10-13  6:31 ` [PATCH net-next v3 3/4] vsock/virtio: coalesce RX write-space notifications in lock batches Jia Jia
2026-10-14  6:33   ` netdev-bot+sashiko [this message]
2026-10-13  6:31 ` [PATCH net-next v3 4/4] vsock/virtio: defer RX readable notifications until batch unlock Jia Jia
2026-10-14  6:33   ` netdev-bot+sashiko

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=179195958167.434549.3993403899530916978@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=horms@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=physicalmtea@gmail.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.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