mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: don't allocate to get send buffer size
In a redis-benchmark PING_INLINE test, this reduces allocations by 7.7%. PiperOrigin-RevId: 616263988
This commit is contained in:
committed by
gVisor bot
parent
586c38d700
commit
28c01a50f0
@@ -495,6 +495,16 @@ func (s *Stack) TransportProtocolOption(transport tcpip.TransportProtocolNumber,
|
||||
return transProtoState.proto.Option(option)
|
||||
}
|
||||
|
||||
// SendBufSizeProto is a protocol that can return its send buffer size.
|
||||
type SendBufSizeProto interface {
|
||||
SendBufferSize() tcpip.TCPSendBufferSizeRangeOption
|
||||
}
|
||||
|
||||
// TCPSendBufferLimits returns the TCP send buffer size limit.
|
||||
func (s *Stack) TCPSendBufferLimits() tcpip.TCPSendBufferSizeRangeOption {
|
||||
return s.transportProtocols[header.TCPProtocolNumber].proto.(SendBufSizeProto).SendBufferSize()
|
||||
}
|
||||
|
||||
// SetTransportProtocolHandler sets the per-stack default handler for the given
|
||||
// protocol.
|
||||
//
|
||||
|
||||
@@ -3228,12 +3228,10 @@ func (e *endpoint) SocketOptions() *tcpip.SocketOptions {
|
||||
}
|
||||
|
||||
// GetTCPSendBufferLimits is used to get send buffer size limits for TCP.
|
||||
func GetTCPSendBufferLimits(s tcpip.StackHandler) tcpip.SendBufferSizeOption {
|
||||
var ss tcpip.TCPSendBufferSizeRangeOption
|
||||
if err := s.TransportProtocolOption(header.TCPProtocolNumber, &ss); err != nil {
|
||||
panic(fmt.Sprintf("s.TransportProtocolOption(%d, %#v) = %s", header.TCPProtocolNumber, ss, err))
|
||||
}
|
||||
|
||||
func GetTCPSendBufferLimits(sh tcpip.StackHandler) tcpip.SendBufferSizeOption {
|
||||
// This type assertion is safe because only the TCP stack calls this
|
||||
// function.
|
||||
ss := sh.(*stack.Stack).TCPSendBufferLimits()
|
||||
return tcpip.SendBufferSizeOption{
|
||||
Min: ss.Min,
|
||||
Default: ss.Default,
|
||||
|
||||
@@ -480,6 +480,13 @@ func (p *protocol) Option(option tcpip.GettableTransportProtocolOption) tcpip.Er
|
||||
}
|
||||
}
|
||||
|
||||
// SendBufferSize implements stack.SendBufSizeProto.
|
||||
func (p *protocol) SendBufferSize() tcpip.TCPSendBufferSizeRangeOption {
|
||||
p.mu.RLock()
|
||||
defer p.mu.RUnlock()
|
||||
return p.sendBufferSize
|
||||
}
|
||||
|
||||
// Close implements stack.TransportProtocol.Close.
|
||||
func (p *protocol) Close() {
|
||||
p.dispatcher.close()
|
||||
|
||||
Reference in New Issue
Block a user