Set the socket buffers through the force options alone instead of falling back to the capped ones
This commit is contained in:
@@ -15,13 +15,9 @@ type mmsghdr struct {
|
|||||||
|
|
||||||
func htons(v uint16) uint16 { return v<<8 | v>>8 }
|
func htons(v uint16) uint16 { return v<<8 | v>>8 }
|
||||||
|
|
||||||
func setBufForce(fd, forceOpt, opt, size int) error {
|
// Set through the FORCE options alone: the plain ones are clamped to wmem_max
|
||||||
if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, forceOpt, size); err == nil {
|
// and rmem_max, so falling back to them would quietly leave a fraction of this
|
||||||
return nil
|
// and go on measuring as though it had not.
|
||||||
}
|
|
||||||
return unix.SetsockoptInt(fd, unix.SOL_SOCKET, opt, size)
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sndbufBytes = 8 << 20
|
sndbufBytes = 8 << 20
|
||||||
rcvbufBytes = 64 << 20
|
rcvbufBytes = 64 << 20
|
||||||
@@ -40,7 +36,7 @@ func openTxSocket(ifindex int) (int, error) {
|
|||||||
unix.Close(fd)
|
unix.Close(fd)
|
||||||
return -1, fmt.Errorf("qdisc bypass: %w", err)
|
return -1, fmt.Errorf("qdisc bypass: %w", err)
|
||||||
}
|
}
|
||||||
if err := setBufForce(fd, unix.SO_SNDBUFFORCE, unix.SO_SNDBUF, sndbufBytes); err != nil {
|
if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_SNDBUFFORCE, sndbufBytes); err != nil {
|
||||||
unix.Close(fd)
|
unix.Close(fd)
|
||||||
return -1, fmt.Errorf("sndbuf: %w", err)
|
return -1, fmt.Errorf("sndbuf: %w", err)
|
||||||
}
|
}
|
||||||
@@ -53,7 +49,7 @@ func openRxSocket(ifindex int, etherType uint16) (int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, fmt.Errorf("socket: %w", err)
|
return -1, fmt.Errorf("socket: %w", err)
|
||||||
}
|
}
|
||||||
if err := setBufForce(fd, unix.SO_RCVBUFFORCE, unix.SO_RCVBUF, rcvbufBytes); err != nil {
|
if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_RCVBUFFORCE, rcvbufBytes); err != nil {
|
||||||
unix.Close(fd)
|
unix.Close(fd)
|
||||||
return -1, fmt.Errorf("rcvbuf: %w", err)
|
return -1, fmt.Errorf("rcvbuf: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user