wgengine/magicsock: don't use endpoint debug ringbuffer on mobile.

Save some memory.

Updates tailscale/corp#18514

Change-Id: Ibcaf3c6d8e5cc275c81f04141d0f176e2249509b
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/11488/head
Brad Fitzpatrick 8 months ago committed by Brad Fitzpatrick
parent 512fc0b502
commit 5d1c72f76b

@ -24,7 +24,12 @@ type RingBuffer[T any] struct {
// Add appends a new item to the RingBuffer, possibly overwriting the oldest // Add appends a new item to the RingBuffer, possibly overwriting the oldest
// item in the buffer if it is already full. // item in the buffer if it is already full.
//
// It does nothing if rb is nil.
func (rb *RingBuffer[T]) Add(t T) { func (rb *RingBuffer[T]) Add(t T) {
if rb == nil {
return
}
rb.mu.Lock() rb.mu.Lock()
defer rb.mu.Unlock() defer rb.mu.Unlock()
if len(rb.buf) < rb.max { if len(rb.buf) < rb.max {
@ -37,6 +42,8 @@ func (rb *RingBuffer[T]) Add(t T) {
// GetAll returns a copy of all the entries in the ring buffer in the order they // GetAll returns a copy of all the entries in the ring buffer in the order they
// were added. // were added.
//
// It returns nil if rb is nil.
func (rb *RingBuffer[T]) GetAll() []T { func (rb *RingBuffer[T]) GetAll() []T {
if rb == nil { if rb == nil {
return nil return nil

@ -1815,9 +1815,11 @@ func debugRingBufferSize(numPeers int) int {
} }
var maxRingBufferSize int var maxRingBufferSize int
if runtime.GOOS == "ios" || runtime.GOOS == "android" { if runtime.GOOS == "ios" || runtime.GOOS == "android" {
maxRingBufferSize = 1 * 1024 * 1024 maxRingBufferSize = 1 << 20
// But as of 2024-03-20, we now just disable the ring buffer entirely
// on mobile as it hadn't proven useful enough to justify even 1 MB.
} else { } else {
maxRingBufferSize = 4 * 1024 * 1024 maxRingBufferSize = 4 << 20
} }
if v := debugRingBufferMaxSizeBytes(); v > 0 { if v := debugRingBufferMaxSizeBytes(); v > 0 {
maxRingBufferSize = v maxRingBufferSize = v
@ -1984,7 +1986,6 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
ep = &endpoint{ ep = &endpoint{
c: c, c: c,
debugUpdates: ringbuffer.New[EndpointChange](entriesPerBuffer),
nodeID: n.ID(), nodeID: n.ID(),
publicKey: n.Key(), publicKey: n.Key(),
publicKeyHex: n.Key().UntypedHexString(), publicKeyHex: n.Key().UntypedHexString(),
@ -1993,6 +1994,14 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
heartbeatDisabled: flags.heartbeatDisabled, heartbeatDisabled: flags.heartbeatDisabled,
isWireguardOnly: n.IsWireGuardOnly(), isWireguardOnly: n.IsWireGuardOnly(),
} }
switch runtime.GOOS {
case "ios", "android":
// Omit, to save memory. Prior to 2024-03-20 we used to limit it to
// ~1MB on mobile but we never used the data so the memory was just
// wasted.
default:
ep.debugUpdates = ringbuffer.New[EndpointChange](entriesPerBuffer)
}
if n.Addresses().Len() > 0 { if n.Addresses().Len() > 0 {
ep.nodeAddr = n.Addresses().At(0).Addr() ep.nodeAddr = n.Addresses().At(0).Addr()
} }

Loading…
Cancel
Save