mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: more small alloc optimizations
PiperOrigin-RevId: 620360076
This commit is contained in:
committed by
gVisor bot
parent
32afe881c5
commit
5728f719d5
@@ -237,6 +237,9 @@ type recvMMsgDispatcher struct {
|
||||
// array is passed as the parameter to recvmmsg call to retrieve
|
||||
// potentially more than 1 packet per unix.
|
||||
msgHdrs []rawfile.MMsgHdr
|
||||
|
||||
// pkts is reused to avoid allocations.
|
||||
pkts stack.PacketBufferList
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -290,20 +293,18 @@ func (d *recvMMsgDispatcher) dispatch() (bool, tcpip.Error) {
|
||||
return false, err
|
||||
}
|
||||
// Process each of received packets.
|
||||
// Keep a list of packets so we can DecRef outside of the loop.
|
||||
var pkts stack.PacketBufferList
|
||||
|
||||
d.e.mu.RLock()
|
||||
dsp := d.e.dispatcher
|
||||
d.e.mu.RUnlock()
|
||||
|
||||
defer func() { pkts.DecRef() }()
|
||||
defer d.pkts.Reset()
|
||||
for k := 0; k < nMsgs; k++ {
|
||||
n := int(d.msgHdrs[k].Len)
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Payload: d.bufs[k].pullBuffer(n),
|
||||
})
|
||||
pkts.PushBack(pkt)
|
||||
d.pkts.PushBack(pkt)
|
||||
|
||||
// Mark that this iovec has been processed.
|
||||
d.msgHdrs[k].Msg.Iovlen = 0
|
||||
|
||||
+8
-4
@@ -2668,15 +2668,19 @@ func (a AddressWithPrefix) Subnet() Subnet {
|
||||
addrLen := a.Address.length
|
||||
if a.PrefixLen <= 0 {
|
||||
return Subnet{
|
||||
address: AddrFromSlice(bytes.Repeat([]byte{0}, addrLen)),
|
||||
mask: MaskFromBytes(bytes.Repeat([]byte{0}, addrLen)),
|
||||
address: Address{length: addrLen},
|
||||
mask: AddressMask{length: addrLen},
|
||||
}
|
||||
}
|
||||
if a.PrefixLen >= addrLen*8 {
|
||||
return Subnet{
|
||||
sub := Subnet{
|
||||
address: a.Address,
|
||||
mask: MaskFromBytes(bytes.Repeat([]byte{0xff}, addrLen)),
|
||||
mask: AddressMask{length: addrLen},
|
||||
}
|
||||
for i := 0; i < addrLen; i++ {
|
||||
sub.mask.mask[i] = 0xff
|
||||
}
|
||||
return sub
|
||||
}
|
||||
|
||||
sa := Address{length: addrLen}
|
||||
|
||||
Reference in New Issue
Block a user