From d542d45a28e3d759b20e33c36f0f577ed01cee74 Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Mon, 25 Jul 2022 13:19:30 -0700 Subject: [PATCH] Adjust batch size in fifo qdisc to match the fdbased batch size. These two are frequently used together, so this change slightly optimizes the number of write syscalls. PiperOrigin-RevId: 463161851 --- pkg/tcpip/link/fdbased/endpoint.go | 11 ++++++----- pkg/tcpip/link/qdisc/fifo/fifo.go | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index bc691cad3..493db9faf 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -66,6 +66,11 @@ type linkDispatcher interface { type PacketDispatchMode int const ( + // BatchSize is the number of packets to write in each syscall. It is 47 + // because when GvisorGSO is in use then a single 65KB TCP segment can get + // split into 46 segments of 1420 bytes and a single 216 byte segment. + BatchSize = 47 + // Readv is the default dispatch mode and is the least performant of the // dispatch options but the one that is supported by all underlying FD // types. @@ -670,11 +675,7 @@ func (e *endpoint) sendBatch(batchFDInfo fdInfo, pkts []*stack.PacketBuffer) (in // - pkt.NetworkProtocolNumber func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) { // Preallocate to avoid repeated reallocation as we append to batch. - // batchSz is 47 because when GvisorGSO is in use then a single 65KB TCP - // segment can get split into 46 segments of 1420 bytes and a single 216 - // byte segment. - const batchSz = 47 - batch := make([]*stack.PacketBuffer, 0, batchSz) + batch := make([]*stack.PacketBuffer, 0, BatchSize) batchFDInfo := fdInfo{fd: -1, isSocket: false} sentPackets := 0 for _, pkt := range pkts.AsSlice() { diff --git a/pkg/tcpip/link/qdisc/fifo/fifo.go b/pkg/tcpip/link/qdisc/fifo/fifo.go index d4ed3f0d5..227f5510a 100644 --- a/pkg/tcpip/link/qdisc/fifo/fifo.go +++ b/pkg/tcpip/link/qdisc/fifo/fifo.go @@ -28,9 +28,11 @@ import ( var _ stack.QueueingDiscipline = (*discipline)(nil) const ( - // BatchSize represents the number of packets written to the - // lower link endpoint during calls to WritePackets. - BatchSize = 32 + // BatchSize is the number of packets to write in each syscall. It is 47 + // because when GvisorGSO is in use then a single 65KB TCP segment can get + // split into 46 segments of 1420 bytes and a single 216 byte segment. + BatchSize = 47 + qDiscClosed = 1 )