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 )