Repository navigation
Description
What is the issue?
This is sort of similar to #866 or #7621
I'm setting up a new linux laptop and noticed that when idle on battery, tailscaled is using more CPU than any other process. A system wide perf profile pointed to tailscale spending a lot of time in proc_reg_read.
a go cpu profile points to the portlist polling:
❯ tailscale debug -cpu-profile=prof.cpu --profile-seconds=60
❯ go tool pprof prof.cpu
File: .tailscaled-wrapped
Type: cpu
Time: Nov 30, 2023 at 8:45am (EST)
Duration: 60s, Total samples = 900ms ( 1.50%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top30 -cum
Showing nodes accounting for 850ms, 94.44% of 900ms total
Showing top 30 nodes out of 100
flat flat% sum% cum cum%
850ms 94.44% 94.44% 850ms 94.44% runtime/internal/syscall.Syscall6
0 0% 94.44% 820ms 91.11% syscall.RawSyscall6
0 0% 94.44% 790ms 87.78% tailscale.com/ipn/ipnlocal.(*LocalBackend).readPoller
0 0% 94.44% 790ms 87.78% tailscale.com/portlist.(*Poller).Poll
0 0% 94.44% 790ms 87.78% tailscale.com/portlist.(*Poller).getList (inline)
0 0% 94.44% 790ms 87.78% tailscale.com/portlist.(*linuxImpl).AppendListeningPorts
0 0% 94.44% 770ms 85.56% syscall.Syscall
0 0% 94.44% 740ms 82.22% bufio.(*Reader).ReadSlice
0 0% 94.44% 740ms 82.22% bufio.(*Reader).fill
0 0% 94.44% 740ms 82.22% internal/poll.(*FD).Read
0 0% 94.44% 740ms 82.22% internal/poll.ignoringEINTRIO (inline)
0 0% 94.44% 740ms 82.22% os.(*File).Read
0 0% 94.44% 740ms 82.22% os.(*File).read (inline)
0 0% 94.44% 740ms 82.22% syscall.Read (inline)
0 0% 94.44% 740ms 82.22% syscall.read
0 0% 94.44% 740ms 82.22% tailscale.com/portlist.(*linuxImpl).parseProcNetFile
0 0% 94.44% 60ms 6.67% syscall.Syscall6
0 0% 94.44% 50ms 5.56% tailscale.com/portlist.(*linuxImpl).findProcessNames
0 0% 94.44% 50ms 5.56% tailscale.com/portlist.(*linuxImpl).findProcessNames.func2
0 0% 94.44% 50ms 5.56% tailscale.com/portlist.foreachPID
0 0% 94.44% 50ms 5.56% tailscale.com/portlist.foreachPID.func1
0 0% 94.44% 50ms 5.56% tailscale.com/util/dirwalk.WalkShallow
0 0% 94.44% 50ms 5.56% tailscale.com/util/dirwalk.linuxWalkShallow
0 0% 94.44% 40ms 4.44% tailscale.com/net/dns/resolver.(*forwarder).send.func3
0 0% 94.44% 40ms 4.44% tailscale.com/net/dns/resolver.(*forwarder).sendUDP
0 0% 94.44% 40ms 4.44% tailscale.com/util/race.(*Race[go.shape.[]uint8]).Start.func1
0 0% 94.44% 30ms 3.33% runtime.findRunnable
0 0% 94.44% 30ms 3.33% runtime.mcall
0 0% 94.44% 30ms 3.33% runtime.netpoll
0 0% 94.44% 30ms 3.33% runtime.schedule
It's not a TON of CPU, but it works out to about 30seconds of CPU time over a 30 minute period.. about 1 seconds worth every minute.
Unlike #7621 There isn't much going on on this system in the first place:
❯ wc -l /proc/net/{tcp,udp}{,6}
18 /proc/net/tcp
4 /proc/net/tcp6
12 /proc/net/udp
5 /proc/net/udp6
39 total
❯ ls -l /proc | wc -l
401
If I set TS_DEBUG_DISABLE_PORTLIST=true the CPU usage drops to almost nothing. With the default, you can see the CPU time constantly tick up:
❯ top -d 10 -b -p 82579|grep tail
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
82579 root 20 0 1319652 47444 18816 S 0.0 0.1 0:31.14 .tailscaled-wra
82579 root 20 0 1319652 47444 18816 S 1.3 0.1 0:31.27 .tailscaled-wra
82579 root 20 0 1319652 47444 18816 S 1.5 0.1 0:31.42 .tailscaled-wra
82579 root 20 0 1319652 47444 18816 S 1.3 0.1 0:31.55 .tailscaled-wra
82579 root 20 0 1319652 47444 18816 S 1.6 0.1 0:31.71 .tailscaled-wra
82579 root 20 0 1319652 47444 18816 S 1.3 0.1 0:31.84 .tailscaled-wra
82579 root 20 0 1319652 47444 18816 S 1.6 0.1 0:32.00 .tailscaled-wra
After, almost no usage:
❯ top -d 10 -b -p 90739|grep tail
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
90739 root 20 0 1317860 46592 18816 S 0.0 0.1 0:00.13 .tailscaled-wra
90739 root 20 0 1317860 46976 18816 S 0.2 0.1 0:00.15 .tailscaled-wra
90739 root 20 0 1317860 47104 18816 S 0.0 0.1 0:00.15 .tailscaled-wra
90739 root 20 0 1317860 47104 18816 S 0.2 0.1 0:00.17 .tailscaled-wra
90739 root 20 0 1317860 47360 18816 S 0.1 0.1 0:00.18 .tailscaled-wra
90739 root 20 0 1317860 47360 18816 S 0.1 0.1 0:00.19 .tailscaled-wra
90739 root 20 0 1317860 47616 18816 S 0.2 0.1 0:00.21 .tailscaled-wra
90739 root 20 0 1317860 47744 18816 S 0.1 0.1 0:00.22 .tailscaled-wra
90739 root 20 0 1317860 48384 18816 S 0.1 0.1 0:00.23 .tailscaled-wra
90739 root 20 0 1317860 48384 18816 S 0.2 0.1 0:00.25 .tailscaled-wra
I see that on linux (and I guess android?) the poll interval is 1s, but it's 5s on other platforms. I wasn't too familiar with this feature and wonder what the use case is that requires the interval to be so low (effectively realtime?). Until looking into this I had never really noticed the "Services" feature before.
Steps to reproduce
- Start tailscale
- Look at a system wide perf profile
Are there any recent changes that introduced the issue?
No response
OS
Linux
OS version
nixos-unstable (linux 6.6.2)
Tailscale version
1.54.0
Other software
No response
Bug report
BUG-0f7323196cd6d35321a40bcab01b0b310841e058d84b98ce0035eb4083dd4915-20231130135143Z-51f2bc23fee62715
Activity
JustinAzoff commentedon Dec 5, 2023
Ah, just noticed on android this is disabled via:
tailscale/portlist/portlist_linux.go
Lines 97 to 102 in 9c4b73d
so it's likely just linux laptops that are affected.
bluet commentedon Dec 16, 2023
Do you have systemd-resolved on your system? When tailscale's consuming lots of CPU on my laptop, systemd-resolved is getting busy, too. #10630
JustinAzoff commentedon Dec 16, 2023
No resolved here, that looks like a very different issue. My issue was a continuous small burst of activity once per second, never more than 1% of a CPU.
My issue is entirely resolved by sticking
in my nix config. I've been looking into this a little more and may just submit a PR that changes the default port list polling times to 60s, unless there's a reason it needs to update so fast.
shawnvega commentedon May 4, 2024
I'm seeing the issue also on my raspberry pi. I'm wondering where the config file is that you place that into? or is it something that you pass into a command?
JustinAzoff commentedon May 4, 2024
@shawnvega that was for nixos. For a pi running raspbian, edit
/etc/default/tailscaledand addto the bottom and restart tailscale, that should do it.
I need to take a closer look at this issue again. I think making linux and other platforms refresh the server list every 30 or 60s would be fine, but I'm not sure if there is a requirement I don't know of somewhere for the service list to quickly reflect updates. As far as I know nothing depends on this information.
shawnvega commentedon May 6, 2024
@JustinAzoff Thanks! Editing that file then restarting tailscale reduced the CPU usage by a lot. I hope that it is fixed in a future release so that people don't have to do that manually.
L3tum commentedon Aug 2, 2025
I noticed the CPU usage also dramatically goes down (10 Services at 13% constantly vs 10 Services at 1,7%) when you disable the Feature Preview "Services Collection" under Settings. That way you don't have to play with the config files on each device.
Disable Tailscale port listing to reduce CPU usage by ~50%
fix: set TS_DEBUG_DISABLE_PORTLIST at systemd service level
portlist: use inet_diag for Linux listener discovery
portlist: exercise Linux discovery backends with real sockets
portlist: use inet_diag for Linux listener discovery
portlist: exercise Linux discovery backends with real sockets
portlist: use inet_diag for Linux listener discovery
portlist: exercise Linux discovery backends with real sockets
portlist: use inet_diag for Linux listener discovery
portlist: exercise Linux discovery backends with real sockets
portlist: use inet_diag for Linux listener discovery
portlist: exercise Linux discovery backends with real sockets
dweekly commentedon Sep 23, 2026
Adding some measurements for @L3tum's workaround above, since it's the fastest fix and easy to miss in this thread.
Disabling the "Services Collection" feature preview in the admin console (Settings → General) stops the portlist poller immediately — tailnet-wide, no config file edits, and no
tailscaledrestart.Measured on an idle Ubuntu 24.04 server, tailscale 1.102.4, ~560 processes / ~6100 open fds / 13 Docker containers:
/proc/net/{tcp,tcp6,udp,udp6}re-readsrcharread rateThe clearest signal that this is disproportionate work: over 5.4 days of uptime
tailscaledhad a lifetimercharof 10.4 GB, whiletailscale0carried only ~97 MB of actual tunnel traffic — ~100x more/procreading than networking. CPU was also 89% system time (5893s sys vs 704s user), consistent with @JustinAzoff'sparseProcNetFileprofile.Two notes for anyone landing here:
/proc/net/*fds stay open but are never read again. That looks like the missingdefer poller.Close()infeature/portlist/portlist.go, which is fixed in 343e2b2.mainbut is not in any release yet — it isn't in v1.102.4 and it postdates the v1.103.0-pre tag by 241 commits. So the env knob / admin toggle is still needed for now.TS_DEBUG_DISABLE_PORTLIST=truein/etc/default/tailscaledremains the per-device equivalent, but it requires a restart.