πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26724

Re: [PATCH net-next v6 2/2] vsock/virtio: amortize RX socket locking for stream packets

#26724
From: Jia Jia
Date: Fri, 04 Dec 2026 04:15
495 lines
35898 bytes
>
> On Thu, Dec 03, 2026 at 11:30:40AM +0800, Jia Jia wrote:
> > >
> > > On Fri, Nov 27, 2026 at 06:27:00AM +0000, Jia Jia wrote:
> > > >The virtio-vsock RX worker looks up a socket and takes its lock for every
> > > >packet. Retain the connected lookup reference and socket lock across a
> > > >bounded run of STREAM/RW packets for one established native socket.
> > > >
> > > >Reuse the locked socket while packets match the same flow. Finish the
> > > >batch on a malformed packet, flow change, non-RW traffic, or a change to
> > > >the socket state, transport, protocol, sockmap state, or receive buffer
> > > >limits. A connected lookup miss falls back to the existing receive path,
> > > >which can still find a bound socket.
> > > >
> > > >Limit an uninterrupted socket-lock ownership interval to 64 packets and
> > > >64 KiB of payload. The payload limit is one
> > > >VIRTIO_VSOCK_MAX_PKT_BUF_SIZE. Small or zero-length packets still incur
> > > >per-packet work, so an independent packet limit is needed. The 64-packet
> > > >limit uses VHOST_NET_BATCH as a reference; it is a policy choice rather
> > > >than a protocol limit.
> > > >
> > > >Beyond these limits, a larger batch would only further amortize socket
> > > >lookup and lock/unlock operations, while virtqueue work, validation,
> > > >tracing, skb ownership, credit update, and queueing remain per-packet. I
> > > >therefore expect diminishing returns while the uninterrupted socket-lock
> > > >interval continues to grow, but I have not measured larger limits yet.
> > > >
> > > >Only the guest virtio RX worker is changed. The benchmark exercises the
> > > >host-sender-to-guest-receiver direction, where this worker is on the
> > > >receive path. I have not measured the corresponding worker and socket-lock
> > > >overhead in vhost-vsock or vsock_loopback, and they use different worker
> > > >and locking models. Leave those paths unchanged pending separate policy
> > > >and validation. I plan to evaluate vhost-vsock separately as follow-up
> > > >work.
> > > >
> > > >Performance:
> > > >
> > > >These results cover both patches in this series.
> > > >
> > > >Tested on a single-stream vsock connection (one Guest receiver thread on
> > > >CPU0, virtio-vsock IRQ on Guest CPU1, fresh QEMU Guest per state, with 16
> > > >accepted, balanced AB/BA pairs per payload). The host uses vhost-vsock.
> > > >
> > > >For throughput, vsock_perf runs on the host as the
> > > >sender, with a custom single-threaded Guest receiver pinned to Guest CPU0
> > > >using blocking recv(). The table uses a 64K buffer. The virtio-vsock
> > > >IRQ/RX worker is pinned to Guest CPU1. To normalize run times across
> > > >payloads into a bounded, deterministic window and avoid long runs being
> > > >skewed by host background noise or virtualization scheduling jitter,
> > > >transfer sizes scale proportionally with the request size (64B/64M,
> > > >256B/256M, etc.), capped at 2G for 4K-64K. The custom receiver keeps the
> > > >recv() size and count explicit; vsock_perf's receiver uses poll()+read().
> > > >
> > > >End-to-end RX throughput
> > > >(64K Guest recv() size, SO_RCVLOWAT=1; Gbit/s):
> > > >
> > > >  payload  baseline RX  series RX  throughput change (95% CI)
> > > >           (Gbit/s)     (Gbit/s)
> > > >  64B          0.1212      0.2555  +110.81% [+106.99%, +114.70%]
> > > >  256B         0.5551      1.0212  +83.95% [+79.94%, +88.06%]
> > > >  512B         1.0568      1.8761  +77.53% [+73.02%, +82.15%]
> > > >  1K           1.9260      3.1453  +63.31% [+58.58%, +68.17%]
> > > >  4K           3.5175      6.3239  +79.78% [+72.79%, +87.06%]
> > > >  8K           4.1183      5.6867  +38.08% [+31.06%, +45.48%]
> > > >  16K          5.0155      6.8346  +36.27% [+31.12%, +41.62%]
> > > >  64K          5.0541      5.8403  +15.56% [+11.12%, +20.17%]
> > > >
> > > >Fixed-syscall stress test
> > > >(receiver recv() size = sender write size; Gbit/s):
> > > >
> > > >  payload  baseline RX  series RX  throughput change (95% CI)
> > > >           (Gbit/s)     (Gbit/s)
> > > >  64B          0.1435      0.2750  +91.60% [+82.19%, +101.50%]
> > > >       recv() calls (baseline/series): 1048577/1048577
> > > >  256B         0.4218      0.9659  +129.00% [+110.65%, +148.95%]
> > > >       recv() calls (baseline/series): 1048577/1048577
> > > >  512B         0.8062      1.6979  +110.60% [+94.49%, +128.04%]
> > > >       recv() calls (baseline/series): 1048577/1048577
> > > >  1K           1.5116      2.9585  +95.72% [+85.22%, +106.82%]
> > > >       recv() calls (baseline/series): 1048577/1048577
> > > >  4K           2.9234      6.3365  +116.75% [+110.78%, +122.89%]
> > > >       recv() calls (baseline/series): 538537/525565
> > > >  8K           4.0430      7.1193  +76.09% [+69.04%, +83.44%]
> > > >       recv() calls (baseline/series): 276901/264412
> > > >  16K          4.9182      7.7688  +57.96% [+54.40%, +61.60%]
> > > >       recv() calls (baseline/series): 147674/132088
> > > >  64K          5.6683      7.1636  +26.38% [+20.49%, +32.56%]
> > > >       recv() calls (baseline/series): 50615/33343
> > > >
> > > >Signed-off-by: Jia Jia <physicalmtea@gmail.com>
> > > >---
> > > > include/linux/virtio_vsock.h                  |  23 ++
> > > > .../events/vsock_virtio_transport_common.h    |  40 +--
> > > > net/vmw_vsock/virtio_transport.c              |   7 +-
> > > > net/vmw_vsock/virtio_transport_common.c       | 268 +++++++++++++++++-
> > > > 4 files changed, 297 insertions(+), 41 deletions(-)
> > > >
> > > >diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
> > > >index f91704731057e..748633aa0cc81 100644
> > > >--- a/include/linux/virtio_vsock.h
> > > >+++ b/include/linux/virtio_vsock.h
> > > >@@ -282,6 +282,29 @@ void virtio_transport_destruct(struct vsock_sock *vsk);
> > > >
> > > > void virtio_transport_recv_pkt(struct virtio_transport *t,
> > > >                              struct sk_buff *skb, struct net *net);
> > > >+
> > > >+/*
> > > >+ * Initialize a batch to zero before use. A non-empty batch owns @sk's socket
> > > >+ * lock and the reference returned by vsock_find_connected_socket_net(). The
> > > >+ * caller retains both until it calls virtio_transport_rx_batch_finish(). An
> > > >+ * empty batch owns neither.
> > > >+ */
> > > >+struct virtio_transport_rx_batch {
> > > >+      struct sock *sk;
> > > >+      unsigned int pkts;
> > > >+      size_t bytes;
> > > >+};
> > > >+
> > > >+static inline bool
> > > >+virtio_transport_rx_batch_empty(const struct virtio_transport_rx_batch *batch)
> > > >+{
> > > >+      return !batch->sk;
> > > >+}
> > > >+
> > > >+void virtio_transport_recv_pkt_batch(struct virtio_transport *t,
> > > >+                                   struct sk_buff *skb, struct net *net,
> > > >+                                   struct virtio_transport_rx_batch *batch);
> > > >+void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch);
> > > > void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct sk_buff *skb);
> > > > u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 wanted);
> > > > void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit);
> > > >diff --git a/include/trace/events/vsock_virtio_transport_common.h b/include/trace/events/vsock_virtio_transport_common.h
> > > >index f1ebe36787c3d..53a4c9ec47dae 100644
> > > >--- a/include/trace/events/vsock_virtio_transport_common.h
> > > >+++ b/include/trace/events/vsock_virtio_transport_common.h
> > > >@@ -88,24 +88,12 @@ TRACE_EVENT(virtio_transport_alloc_pkt,
> > > >
> > > > TRACE_EVENT(virtio_transport_recv_pkt,
> > > >       TP_PROTO(
> > > >-               __u32 src_cid, __u32 src_port,
> > > >-               __u32 dst_cid, __u32 dst_port,
> > > >-               __u32 len,
> > > >-               __u16 type,
> > > >-               __u16 op,
> > > >-               __u32 flags,
> > > >-               __u32 buf_alloc,
> > > >-               __u32 fwd_cnt
> > > >+               const struct virtio_vsock_hdr *hdr,
> > > >+               const struct sockaddr_vm *src,
> > > >+               const struct sockaddr_vm *dst
> > > >       ),
> > > >       TP_ARGS(
> > > >-              src_cid, src_port,
> > > >-              dst_cid, dst_port,
> > > >-              len,
> > > >-              type,
> > > >-              op,
> > > >-              flags,
> > > >-              buf_alloc,
> > > >-              fwd_cnt
> > > >+              hdr, src, dst
> > > >       ),
> > > >       TP_STRUCT__entry(
> > > >               __field(__u32, src_cid)
> > > >@@ -120,16 +108,16 @@ TRACE_EVENT(virtio_transport_recv_pkt,
> > > >               __field(__u32, fwd_cnt)
> > > >       ),
> > > >       TP_fast_assign(
> > > >-              __entry->src_cid = src_cid;
> > > >-              __entry->src_port = src_port;
> > > >-              __entry->dst_cid = dst_cid;
> > > >-              __entry->dst_port = dst_port;
> > > >-              __entry->len = len;
> > > >-              __entry->type = type;
> > > >-              __entry->op = op;
> > > >-              __entry->flags = flags;
> > > >-              __entry->buf_alloc = buf_alloc;
> > > >-              __entry->fwd_cnt = fwd_cnt;
> > > >+              __entry->src_cid = src->svm_cid;
> > > >+              __entry->src_port = src->svm_port;
> > > >+              __entry->dst_cid = dst->svm_cid;
> > > >+              __entry->dst_port = dst->svm_port;
> > > >+              __entry->len = le32_to_cpu(hdr->len);
> > > >+              __entry->type = le16_to_cpu(hdr->type);
> > > >+              __entry->op = le16_to_cpu(hdr->op);
> > > >+              __entry->flags = le32_to_cpu(hdr->flags);
> > > >+              __entry->buf_alloc = le32_to_cpu(hdr->buf_alloc);
> > > >+              __entry->fwd_cnt = le32_to_cpu(hdr->fwd_cnt);
> > > >       ),
> > > >       TP_printk("%u:%u -> %u:%u len=%u type=%s op=%s flags=%#x "
> > > >                 "buf_alloc=%u fwd_cnt=%u",
> > > >diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> > > >index 4f9aa9c4c3aa5..9af85712bd387 100644
> > > >--- a/net/vmw_vsock/virtio_transport.c
> > > >+++ b/net/vmw_vsock/virtio_transport.c
> > > >@@ -633,6 +633,7 @@ static void virtio_transport_rx_work(struct work_struct *work)
> > > > {
> > > >       struct virtio_vsock *vsock =
> > > >               container_of(work, struct virtio_vsock, rx_work);
> > > >+      struct virtio_transport_rx_batch batch = {};
> > > >       struct virtqueue *vq;
> > > >
> > > >       mutex_lock(&vsock->rx_lock);
> > > >@@ -666,6 +667,7 @@ static void virtio_transport_rx_work(struct work_struct *work)
> > > >                       /* Drop short/long packets */
> > > >                       if (unlikely(len < sizeof(*hdr) ||
> > > >                                    len > virtio_vsock_skb_len(skb))) {
> > > >+                              virtio_transport_rx_batch_finish(&batch);
> > > >                               kfree_skb(skb);
> > > >                               continue;
> > > >                       }
> > > >@@ -673,6 +675,7 @@ static void virtio_transport_rx_work(struct work_struct *work)
> > > >                       hdr = virtio_vsock_hdr(skb);
> > > >                       payload_len = le32_to_cpu(hdr->len);
> > > >                       if (unlikely(payload_len > len - sizeof(*hdr))) {
> > > >+                              virtio_transport_rx_batch_finish(&batch);
> > > >                               kfree_skb(skb);
> > > >                               continue;
> > > >                       }
> > > >@@ -685,11 +688,13 @@ static void virtio_transport_rx_work(struct work_struct *work)
> > > >                       /* Force virtio-transport into global mode since it
> > > >                        * does not yet support local-mode namespacing.
> > > >                        */
> > > >-                      virtio_transport_recv_pkt(&virtio_transport, skb, NULL);
> > > >+                      virtio_transport_recv_pkt_batch(&virtio_transport, skb,
> > > >+                                                      NULL, &batch);
> > > >               }
> > > >       } while (!virtqueue_enable_cb(vq));
> > > >
> > > > out:
> > > >+      virtio_transport_rx_batch_finish(&batch);
> > > >       if (vsock->rx_buf_nr < vsock->rx_buf_max_nr / 2)
> > > >               virtio_vsock_rx_fill(vsock);
> > > > out_nofill:
> > > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> > > >index bebf63115b263..34d6864917bc9 100644
> > > >--- a/net/vmw_vsock/virtio_transport_common.c
> > > >+++ b/net/vmw_vsock/virtio_transport_common.c
> > > >@@ -33,6 +33,15 @@
> > > > #define MAX_COLLAPSE_LEN \
> > > >       SKB_MAX_ORDER(VIRTIO_VSOCK_SKB_HEADROOM, PAGE_ALLOC_COSTLY_ORDER)
> > > >
> > > >+/*
> > > >+ * Bound the interval that an RX worker owns a socket lock. One maximum packet
> > > >+ * buffer (64 KiB) bounds payload in one uninterrupted ownership interval.
> > > >+ * Small and zero-length packets need a packet limit to bound per-packet work;
> > > >+ * the 64-packet policy uses VHOST_NET_BATCH as a reference.
> > > >+ */
> > > >+#define VIRTIO_TRANSPORT_RX_BATCH_MAX_PKTS    64
> > > >+#define VIRTIO_TRANSPORT_RX_BATCH_MAX_BYTES   VIRTIO_VSOCK_MAX_PKT_BUF_SIZE
> > > >+
> > > > static void virtio_transport_cancel_close_work(struct vsock_sock *vsk,
> > > >                                              bool cancel_timeout);
> > > > static s64 virtio_transport_has_space(struct virtio_vsock_sock *vvs);
> > > >@@ -1787,10 +1796,70 @@ virtio_transport_find_socket(struct sockaddr_vm *src,
> > > >       return sk;
> > > > }
> > > >
> > > >+static bool
> > > >+virtio_transport_recv_pkt_set_owner(struct sk_buff *skb, struct sock *sk)
> > > >+{
> > > >+      if (skb_set_owner_sk_safe(skb, sk))
> > > >+              return true;
> > > >+
> > > >+      WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n");
> > > >+      return false;
> > > >+}
> > > >+
> > > >+static bool
> > > >+virtio_transport_sock_has_psock(const struct sock *sk)
> > > >+{
> > > >+      return (uintptr_t)rcu_access_pointer(__sk_user_data(sk)) &
> > > >+             SK_USER_DATA_PSOCK;
> > > >+}
> > > >+
> > > >+/* The caller holds sk's socket lock. */
> > > >+static bool
> > > >+virtio_transport_rx_batch_can_continue(struct virtio_transport *t,
> > > >+                                     struct sock *sk, u32 len)
> > > >+{
> > > >+      struct virtio_vsock_sock *vvs;
> > > >+      struct vsock_sock *vsk;
> > > >+
> > > >+      vsk = vsock_sk(sk);
> > > >+      vvs = vsk->trans;
> > > >+
> > > >+      /*
> > > >+       * Keep a connected lookup reference only for the native, established
> > > >+       * STREAM path. Sockets outside ESTABLISHED can change table membership;
> > > >+       * a completed or reassigned socket must resume the per-packet path.
> > > >+       */
> > > >+      if (sk->sk_state != TCP_ESTABLISHED ||
> > > >+          sk->sk_type != SOCK_STREAM ||
> > > >+          sock_flag(sk, SOCK_DONE) ||
> > > >+          vsk->transport != &t->transport || !vvs)
> > > >+              return false;
> > > >+
> > > >+      return (u64)vvs->buf_used + len <= vvs->buf_alloc;
> > >
> > > Should we remove this, since it will be checked in
> > > virtio_transport_inc_rx_pkt() in any case?
> > >
> >
> > I originally added this for the same kind of boundary
> > case discussed in v5. The v5 case checked the skb
> > metadata budget, while this checks the payload
> > against buf_alloc.
> >
> > Given that, this special handling probably isn't necessary,
> > so I'll remove it in the next version.
> >
> > > >+}
> > > >+
> > > >+/* The caller holds sk's socket lock. */
> > > >+static bool
> > > >+virtio_transport_rx_batch_can_receive(struct virtio_transport *t,
> > > >+                                    struct sock *sk, u32 len)
> > > >+{
> > > >+      if (!virtio_transport_rx_batch_can_continue(t, sk, len))
> > > >+              return false;
> > > >+
> > > >+      /*
> > > >+       * Sockmap can replace sk_prot and publish a psock without the socket lock.
> > > >+       * Check both at each packet boundary; a boundary that sees a replacement
> > > >+       * returns to the existing per-packet path.
> > > >+       */
> > > >+      return READ_ONCE(sk->sk_prot) == sk->sk_prot_creator &&
> > > >+             !virtio_transport_sock_has_psock(sk);
> > >
> > > Is this a leftover or we really need this check?
> > >
> >
> > Yes, virtio_transport_sock_has_psock() is no longer
> > needed either. I'll remove it in the next version. Thanks.
> >
> > > >+}
> > > >+
> > > > /*
> > > >- * The caller holds sk's socket lock.
> > > >+ * The caller holds sk's socket lock. Return false if socket/source validation
> > > >+ * rejects the packet.
> > > >  */
> > > >-static void
> > > >+static bool
> > > > virtio_transport_recv_pkt_locked(struct virtio_transport *t,
> > > >                                struct sk_buff *skb, struct sock *sk,
> > > >                                struct net *net)
> > > >@@ -1813,7 +1882,7 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t,
> > > >            !vsock_check_source(vsk, &t->transport, &src))) {
> > > >               (void)virtio_transport_reset_no_sock(t, skb, net);
> > > >               kfree_skb(skb);
> > > >-              return;
> > > >+              return false;
> > > >       }
> > > >
> > > >       space_available = virtio_transport_space_update(sk, skb);
> > > >@@ -1846,6 +1915,8 @@ virtio_transport_recv_pkt_locked(struct virtio_transport *t,
> > > >               kfree_skb(skb);
> > > >               break;
> > > >       }
> > > >+
> > > >+      return true;
> > > > }
> > > >
> > > > /* We are under the virtio-vsock's vsock->rx_lock or vhost-vsock's vq->mutex
> > > >@@ -1863,14 +1934,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
> > > >       vsock_addr_init(&dst, le64_to_cpu(hdr->dst_cid),
> > > >                       le32_to_cpu(hdr->dst_port));
> > > >
> > > >-      trace_virtio_transport_recv_pkt(src.svm_cid, src.svm_port,
> > > >-                                      dst.svm_cid, dst.svm_port,
> > > >-                                      le32_to_cpu(hdr->len),
> > > >-                                      le16_to_cpu(hdr->type),
> > > >-                                      le16_to_cpu(hdr->op),
> > > >-                                      le32_to_cpu(hdr->flags),
> > > >-                                      le32_to_cpu(hdr->buf_alloc),
> > > >-                                      le32_to_cpu(hdr->fwd_cnt));
> > > >+      trace_virtio_transport_recv_pkt(hdr, &src, &dst);
> > >
> > > Why we are doing these changes in this patch?
> > >
> >
> > In v5, I initially added a helper around this tracepoint for the new
> > batching call site. Bobby suggested refactoring the tracepoint directly
> > instead, since the helper was unnecessary. Since this patch has two call
> > sites for the tracepoint, I kept that refactoring.
>
> FTR, between the refactoring and my very first suggestion of not
> changing the trace calls at all, I still prefer my very first suggestion
> of not changing them.
>

Understood, Thanks

> >
> > > >
> > > >       if (!virtio_transport_valid_type(le16_to_cpu(hdr->type))) {
> > > >               (void)virtio_transport_reset_no_sock(t, skb, net);
> > > >@@ -1892,10 +1956,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
> > > >               goto free_pkt;
> > > >       }
> > > >
> > > >-      if (!skb_set_owner_sk_safe(skb, sk)) {
> > > >-              WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n");
> > > >+      if (!virtio_transport_recv_pkt_set_owner(skb, sk))
> > > >               goto free_pkt;
> > > >-      }
> > > >
> > > >       lock_sock(sk);
> > > >       virtio_transport_recv_pkt_locked(t, skb, sk, net);
> > > >@@ -1912,6 +1974,184 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
> > > > }
> > > > EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt);
> > > >
> > > >+/*
> > > >+ * Release an active RX batch. A non-empty batch holds the socket lock and the
> > > >+ * reference returned by vsock_find_connected_socket_net(). An empty batch
> > > >+ * holds neither.
> > > >+ */
> > > >+void virtio_transport_rx_batch_finish(struct virtio_transport_rx_batch *batch)
> > > >+{
> > > >+      struct sock *sk = batch->sk;
> > > >+
> > > >+      batch->sk = NULL;
> > > >+      batch->pkts = 0;
> > > >+      batch->bytes = 0;
> > > >+
> > > >+      if (!sk)
> > > >+              return;
> > > >+
> > > >+      release_sock(sk);
> > > >+      sock_put(sk);
> > > >+}
> > > >+EXPORT_SYMBOL_GPL(virtio_transport_rx_batch_finish);
> > > >+
> > > >+static bool
> > > >+virtio_transport_rx_batch_matches(const struct virtio_transport_rx_batch *batch,
> > > >+                                const struct sockaddr_vm *src,
> > > >+                                const struct sockaddr_vm *dst,
> > > >+                                struct net *net)
> > > >+{
> > > >+      struct vsock_sock *vsk = vsock_sk(batch->sk);
> > > >+
> > > >+      /* The connected table is keyed by peer address and local port. */
> > > >+      return vsock_addr_equals_addr(src, &vsk->remote_addr) &&
> > > >+             dst->svm_port == vsk->local_addr.svm_port &&
> > > >+             vsock_net_check_mode(sock_net(batch->sk), net);
> > > >+}
> > > >+
> > > >+static bool
> > > >+virtio_transport_rx_batch_can_add(const struct virtio_transport_rx_batch *batch,
> > > >+                                u32 len)
> > > >+{
> > > >+      if (batch->pkts >= VIRTIO_TRANSPORT_RX_BATCH_MAX_PKTS ||
> > > >+          batch->bytes >= VIRTIO_TRANSPORT_RX_BATCH_MAX_BYTES)
> > >
> > > Why putting a limit to the total bytes in a batch?
> > >
> >
> > My thinking is that the two limits bound different things: the 64-packet
> > limit bounds per-packet work for small or zero-length packets, while the
> > 64 K limit bounds how much data can be queued while the reader is unable
> > to acquire the socket lock.
> >
> > A single packet can carry up to 64K, so a packet-only limit could let one
> > batch cover up to 4M. Since the receive buffer can be enlarged, the
> > default 256K buffer is not a substitute for that bound. Keeping the byte
> > limit also bounds the delay before the reader can dequeue data and return
> > credit to the peer, since that cannot happen while the batch holds the
> > socket lock.
> >
> > I would therefore prefer to keep both limits.
>
> I'm still not sure I entirely understand this point. Bounding the byte
> count bounds the delay before a reader can dequeue data? Can you point
> to the part of the code that sees increased delay because of high byte
> counts? I think my mental model must be missing something.
>

You're right to question that. Looking closer at the RX path, for larger
packets, normal enqueue mainly does per-packet accounting and queuing,
while copying the payload to userspace happens in the reader after it
acquires the socket lock. So that doesn't justify a separate byte limit.

I also overlooked that virtio_vsock_rx_fill() posts buffers smaller than
4K (VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE) and vhost splits larger
packets tofit them, so my 4M (64 * 64K) estimate was wrong for this path.

I'll drop the 64K limit and keep only the 64-packet limit in v7.

Thanks again for pointing this out!

> Best,
> Bobby
Technical Details
Message-ID: <CAJwVaM+qHrSH3DMbKeSKXuLfAt9_ExTtA7E3+cDwjE0mkiZqig@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377049-linux-kernel-netdev=dewy.ru
References: <20261127062700.29387-1-physicalmtea@gmail.com> <20261127062700.29387-3-physicalmtea@gmail.com> <axAa3U8J1jviZ0y1@sgarzare-redhat> <CAJwVaM+pnmwSxhWkGWS73+4RSr04yUOHxrs3kBk8ZGKRJQ4-JQ@mail.gmail.com> <axGXfT2fya5jtZCt@devvm29614.prn0.facebook.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377049-linux-kernel-netdev=dewy.ru
From: physicalmtea@gmail.com (Jia Jia)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v6 2/2] vsock/virtio: amortize RX socket locking for stream packets
Date: Fri, 4 Dec 2026 12:15:47 +0800
Organization: Usenet Network
Message-ID: <CAJwVaM+qHrSH3DMbKeSKXuLfAt9_ExTtA7E3+cDwjE0mkiZqig@mail.gmail.com>
References: <20261127062700.29387-1-physicalmtea@gmail.com> <20261127062700.29387-3-physicalmtea@gmail.com> <axAa3U8J1jviZ0y1@sgarzare-redhat> <CAJwVaM+pnmwSxhWkGWS73+4RSr04yUOHxrs3kBk8ZGKRJQ4-JQ@mail.gmail.com> <axGXfT2fya5jtZCt@devvm29614.prn0.facebook.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: usenet.network; logging-data="2672369"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nvbV+f/16gj9nnpH+knoPRToiAE= sha256:pDNk0ebJGCPqyT3UcEhM+HXt6dbA72V0+f7zMIFaKTM= sha1:ROIo0C1rjJsENurAPrPCxWn5lm8= sha256:BLJtS3YmxhyLd06Ris6fRcuyHZxcR3Z7qLgolWw09JA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 91D7C117AF6; Fri,  4 Dec 2026 07:16:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.397
X-Spam-Status: No, score=-3.397 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VZCzsj6owiHu; Fri,  4 Dec 2026 07:16:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377049-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id E8671116D9F; Fri,  4 Dec 2026 07:16:34 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id F24D724DF5; Fri,  4 Dec 2026 04:16:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796357787; b=U+cMCthxZXh2pSD8Rlc+qmqVafKAXvj7Wpi8hFWOhlWNxqV50aPiklJZCaUwAgbmzh9O vrYhc2daKc/FvNQitKJ8O9revNX15Lk63KeIaVTTWWa82f2tfzB5v61qlZeBzdYbfM6AK UrjFmMDz57YoWGW7fid48P/rEg764BgPBRBzJJ6LrBoZ8JDpdcAMz/z9R5CDoO78Jj9i8 Ju9JI1dGuuZme193/D5977yic73clMlRsoPc0fIzGMYAzjOAKDC/+xptKvPtuLEtUgXCp UHv2W/e8leuqqRXZtrTQDqKlr/ZPVcMYmlgqj6KnnrGdsgYQHRAC9HjENuYaI6P5WZw==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796357787; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature: X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State: X-Gm-Gg:X-Received:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: References:In-Reply-To:From:Date:X-Gm-Features:Message-ID:Subject:To: Cc:Content-Type; bh=j2j64tcmDtrVgIwzq9YHlxUQ003rymOEZCw7FnuvwpM=; b=bP6PitnitTyshjeed+G4HTgGoll3Maylq4zrn9X2QhDqrEAbM+t8kgb0VVcXS9LygQjH oBx7Ssh2XFMNqckWK4xxkjv7FiztQilpUITWSFq+nqKb8oZGkaIjcz+dO9ssXDK1f1IQH +ZezACUea95qil7b1uQZJ63ENwmaRCDOx9qUfjdOASpyFMpsHPM2QiU/r8G3Tf04Z8oKj h5/9tJ7qCH3pnz/HmkBiaWcEHDmA/LZ0MXStWAnOY/XWfdC3G8N9ZzMA8kZ+jJYjfCyCz QmRnrN0F1Vm9QKVPVggQyYBbVmAAQvPr6cPMx9QzL/45y+LVq9iOqLCziET0hN+DZcw==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kTs5zRig; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB7E3606A684; Fri,  4 Dec 2026 04:16:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kTs5zRig
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.222.174
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796357786; b=DFPiDHPj7UP4VpQfZy7owU9NpF9Vq+soWMSxK+B5CpryxxZohx47xGCL/JuPKm/WzEbT J1YaJ+gLp5MhU5xXXHaCSUlpWZ0RuYMMAS87gZazb06GsPOXhg3vwPfyxHvAKHkC5vNq/ oG2kxBIDLtbqidWL7qwAAvdn95XopnuTD9ZRAsCgvk/8YGw7LlSPygrMPplt45JLpwM7P LpyN/hZ4moyFCA7Iet8tNregX3pUbvmha7pGsM8vK8glhjJUyETYbkgJJs4EuZN3o2fvp 0dq6tLW2J5HuqOqsrdZ2n1swFy3BnN/b4KtQ7DGISdrr+pgN7lwkMA9Jzb2OyxnJ6jw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796357786; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: MIME-Version:References:In-Reply-To:From:Date:X-Gm-Features: Message-ID:Subject:To:Cc:Content-Type; bh=j2j64tcmDtrVgIwzq9YHlxUQ003rymOEZCw7FnuvwpM=; b=KPJKIUSzteVXf0ttZF2eqL+k6n2kgHwZWKqgh0ZC94jwQEEQFGphd7jl9WaZASf3Ecf/ ++VhWUVqbfTLfTMGg93xSTRwJjIh8fe2zsTM/0Oyrt+7QQPC/+MEpVFyBuiKouwzKCcsW f7f1tuUib7SVwbH4ApTg3TyVdP3vMCrWs+SRYHFma0D0Pnb5N1Se61Nrb8L02ldX2ISj5 e9S0rbTanmqs2kguTFlMKnktKUkaLC0u70b+4+z5n2VUzO640TRkJxWGKDiWODmIqfm5g yhG8e3ygA2FjOacGUdEeeERdJEAsYSBeKU8qu05SstgNcS0aev4M/5xN4yjfsfUcIZQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kTs5zRig; arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.222.174
X-Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5698D606A336 for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 04:16:26 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5698D606A336
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-93f2f2edb19so38289485a.0 for <netdev@vger.kernel.org>; Thu, 03 Dec 2026 20:16:26 -0800 (PST)
X-ARC-Seal: i=1; a=rsa-sha256; t=1796357785; cv=none; d=google.com; s=arc-20260327; b=K1dUSv3s7+0JtNPS8dVjgL7xylR9e7EiTVsNMxykcetcU8YGxjgQF4n0zQqKbxXni4 Q3KTFfDaOFNp5SOzER70KJlS2p08eMYAksHdUG+CdndGyCy4ZhcEpcNSEU4Vt7rRN95l x9gwfWo+e2a0i0N1i81scmcb1fZo9XJ9hgN4eDw5mmCOEOTbSARiLqGH8gQPVLCnEOkK VAkYWRUsbtDLP0QEzmgK3gnas1o9xADwg6vLz8LKAEBGbSf6CGm96eJrC0Zqlqko8dMc AhZVVs+JHjds6zrWsVJLBipixSLuGFy6dHEY0w8TsJsypCjCTLgv6MNNL02Y+KX1JRZ/ lbRg==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=j2j64tcmDtrVgIwzq9YHlxUQ003rymOEZCw7FnuvwpM=; fh=U3bs++11aIaE+2mEP55vNrhfgqEEmhPoYtpZVhCLT1c=; b=lWhv9tjL0w5LZthGZuiLkjcOYNsJ1MYKWIyior5NKt3r/ecMu08O25r6xo0HpKeCWK gbTJGtTAyeoyof8OkWW7lDUA9wGYqTRC5o1hQCZSNp0Fu9TiezDd0U/YkfrWVPCRa+CO Vg66MixU7/JtwNkuUbJ+7fhPx5H6/IsPWjRzKUk4S/MsFBWHfIL+SvGrc57y+077JwSS +jeiMFv8t1bn7yve8+W88daMsuvWY7DujNvcuE9bgWcAsrMEHwXMDZGROW6+FkRIwsE+ E/DAvt4UbF1ywuqd4Yb33C38mWzYO3cTOO98EQ0eDASlKCcFVbXdJGk3q29PX8CnRM6e n78w==; darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796357785; x=1796962585; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:from:to:cc:subject:date:message-id:reply-to :content-type; bh=j2j64tcmDtrVgIwzq9YHlxUQ003rymOEZCw7FnuvwpM=; b=kTs5zRigOp9N7NdC/AYerOVUeOKw3uYGqQfEWfMM/7GCY9uzSjje60uXlWf2MAcBZ3 0dppS8QEZ6lFj5exozW6MyR4QfmcxVp5jZy71+jhFZCdEhkAWgoRF4NosUvxBuP+7jB+ zD2hN69n8RLhMYEFW/FGwjGRorZjdGWyqbuVHnwCXwCdw+wYDEGhEs6HjqcDF3ua0Lcz dj5Dsk9xhd+ejl65s23qPqHtdfRHeRTYewC3qlGTOFiJtHB0jG55ZObRfTf36YDeLBTY 1iMT9YeXiD+IyoxJdkoyFxoqtYB1nJ2X2DIKIdDO4QvGOWjA+cNNfVsAY7zFKal8LUz7 KE/g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796357785; x=1796962585; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=j2j64tcmDtrVgIwzq9YHlxUQ003rymOEZCw7FnuvwpM=; b=TB6iu7A/MxYv/PCU1Ktuhhdr3gujVYxidTsNhs8OT3028bmeJ8fKjBktsJeMuUelMA szVmfKG1OgmilFu7atZkdcrn8BbzvJttZqygeb47L3RVczfrMGNL325dwqKIz5jWhVjE gPjhR8dj/hfGh9hM4OSEkr67HvqBo05zJ3vU1Exvg/E5aZHBe4IBt3g1O1VF2qbU5sCd p5p4uy7UEbaMJZAfvu+as9xzUheeT17ocjYTnUGLVoLJ/PgXGCp9Arc78rA8yqSxA1Pd nkePCDwIMAXRrTURs7vQu1Dh95JNEgvXv04FFwo9dPotZk9gA3tc1VoV7Rz0XmxSB3oS Na6g==
X-Forwarded-Encrypted: i=1; AL+hErGl/NEf8+o8mCso4hZf/5V26wuyvpOWfIJ1qsie1KgITmgjHUKCpQXUiHrHlICZlZW693cp32o=@vger.kernel.org
X-Gm-Message-State: APuU4Z+bTsax1IAboqlw0Uwn9sigVZy0ZS/2ZQx+mRSwboHufJc12gVy 2eV/1IWK4zhbrea3xLFzhgmpEHqiH6cVt1VZC4OGn/W8XM4iDP71RMi5kEti+rQN/F0DrF0hdWE vjNlPMvi/LmPeMUMEU6JPXrTz1YmuTT8=
X-Gm-Gg: AZFdTZe8y/FWZH6t0S0NboYX8ZO7TYGqmDRfTWl2yiz2a3KA2yohKdQb12vP22FcP70 ljgX4maX4xTnS8/R3f7AUpf5jFTFZLgvg2YD29kVz9T7wKx3ZJJ3fzM4iCV/HtkNG9T6ofTyAJY Vw82LiMocQA10GGPIqeXqMfblAqBY+xUB/el9UpX3seoccC9LCcQWmM8gjzuTKoT3iu9eCjXN49 dNqsHrZwNdlSIkaCxwnnyO7N2pTBbiia9mEZNiJaWH6lalEb3n7a1N8qcNT4FUJdioKluRyQf3w AmX2ypqhBF2EaDGBkg2K3StlieL114k6yEZpyWq2p1vArFZNHAymsK7dPuThDn8/qn/ozqoo/C+ nHqk+HvmSBQ9IAhnjXUzbLiXTyvBvmmvSZXOZ7d/pVm0yqQsXGJtPWV/ga82Ecu8hgjwJqg==
X-Received: by 2002:a05:620a:31a3:b0:949:b7e9:5d18 with SMTP id af79cd13be357-94a827e2b83mr120070585a.16.1796357784760; Thu, 03 Dec 2026 20:16:24 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <axGXfT2fya5jtZCt@devvm29614.prn0.facebook.com>
X-Gm-Features: Aa3M54p3TxB42yViiU51xoZ7QN96Lszvp4HszRwA2HRDXfDdF6LzEr8HfIXX5Cw
X-Cc: Stefano Garzarella <sgarzare@redhat.com>, "Michael S . Tsirkin" <mst@redhat.com>, Jason Wang <jasowangio@gmail.com>, Eugenio PΓ©rez <eperezma@redhat.com>, Xuan Zhuo <xuanzhuo@linux.alibaba.com>, Stefan Hajnoczi <stefanha@redhat.com>, Steven Rostedt <rostedt@goodmis.org>, Masami Hiramatsu <mhiramat@kernel.org>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, "David S . Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, virtualization@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org