Skip to contentSkip to conversation

vsock: amortize RX socket locking for stream packets

PATCH Superseded [email protected] 2 participants 2 messages Oct 2 – Oct 3

Subsystems (6)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/5 vsock: amortize RX socket locking for stream packets

From: Jia Jia <[email protected]>

The virtio-vsock RX worker currently acquires and releases the socket lock for every received packet. Keep the lock held while processing a bounded run of packets that belongs to the same socket.

Only ordinary RW packets for an established STREAM socket whose transport and protocol remain unchanged are eligible. Control packets, SEQPACKET traffic, state or transport changes, malformed packets, and sockets whose protocol has been replaced end the active batch and retain their existing handling.

Serialize the initial eligibility check with sk_callback_lock because sockmap removal restores the protocol without taking the socket lock.

Limit each batch to 64 packets or 64K of payload to bound the work performed under one socket lock. Keep the lookup reference until the batch finishes.

The virtqueue callback remains a queue_work() callback. Batching runs only in the process-context RX worker.

Introduce virtio_transport_rx_batch_finish() to tear down the batch and release the socket lock and lookup reference.

---
 include/linux/virtio_vsock.h            |   9 ++
 net/vmw_vsock/virtio_transport.c        |  48 ++++++++-
 net/vmw_vsock/virtio_transport_common.c | 126 +++++++++++++++++++++++-
 3 files changed, 181 insertions(+), 2 deletions(-)
include/linux/virtio_vsock.h +9 -0
index f91704731..95ab1a75f 100644
@@ -282,6 +282,15 @@ void virtio_transport_destruct(struct vsock_sock *vsk);
 
 void virtio_transport_recv_pkt(struct virtio_transport *t,
 			       struct sk_buff *skb, struct net *net);
+
+struct virtio_transport_rx_batch {
+	struct sock *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);
net/vmw_vsock/virtio_transport.c +47 -1

92 lines not on this page · raw message

net/vmw_vsock/virtio_transport_common.c +125 -1

153 lines not on this page · raw message

Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 19 lines

From: Jia Jia <[email protected]>

The virtio-vsock RX worker currently acquires and releases the socket lock for every received packet. Keep the lock held while processing a bounded run of packets that belongs to the same socket.

Only ordinary RW packets for an established STREAM socket whose transport and protocol remain unchanged are eligible. Control packets, SEQPACKET traffic, state or transport changes, malformed packets, and sockets whose protocol has been replaced end the active batch and retain their existing handling.

Serialize the initial eligibility check with sk_callback_lock because sockmap removal restores the protocol without taking the socket lock.

Limit each batch to 64 packets or 64K of payload to bound the work performed under one socket lock. Keep the lookup reference until the batch finishes.

Quoted 7 lines

The virtqueue callback remains a queue_work() callback. Batching runs only in the process-context RX worker.

Introduce virtio_transport_rx_batch_finish() to tear down the batch and release the socket lock and lookup reference.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2