When sendmsg() or vhost_net_build_xdp() fails with an error that a retry
cannot fix, vhost_net puts the descriptor back and the worker retries the
same packet at once. The TX queue stops and the worker uses a full CPU.
Patch 1 drops the packet on -ENOMEM/-ENOBUFS from sendmsg() (e.g. an 8MB
frame on tun). Patch 2 drops packets with a bad virtio-net header in the
XDP batch path.
Trade-off of patch 1: a transient allocation failure now drops the packet
instead of retrying. With 10% of order >= 3 allocations failing in the
vhost worker, a guest TCP stream went from 104 to 42 Gbit/s; at 1% there
was no throughput loss, only some retransmits. I can add a bounded retry
instead if preferred.
Tested on x86_64 with a program that drives /dev/vhost-net and queues a
bad packet followed by a good one: before, the queue is stuck; after,
both packets complete.
The issues were found with the help of an AI coding assistant.
Haishuang Yan (2):
vhost_net: drop TX packets that tun cannot allocate
vhost_net: drop TX packets with a bad header in the XDP batch path
drivers/vhost/net.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
base-commit: ef3e21c61baa74e39a49b75318bd4541562ec43f
--
2.43.0