Skip to content

portlist: high CPU usage on otherwise idle system #10430

Open

Description

@JustinAzoff

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

  1. JustinAzoff commented on Dec 5, 2023

    @JustinAzoff
    Author

    Ah, just noticed on android this is disabled via:

    if runtime.GOOS == "android" {
    // Android 10+ doesn't allow access to this anymore.
    // https://developer.android.com/about/versions/10/privacy/changes#proc-net-filesystem
    // Ignore it rather than have the system log about our violation.
    return nil, nil
    }

    so it's likely just linux laptops that are affected.

  2. bluet commented on Dec 16, 2023

    @bluet

    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

  3. JustinAzoff commented on Dec 16, 2023

    @JustinAzoff
    Author

    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

    systemd.services.tailscaled.serviceConfig.Environment = ["TS_DEBUG_DISABLE_PORTLIST=true"] ;
    

    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.

  4. shawnvega commented on May 4, 2024

    @shawnvega

    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

    systemd.services.tailscaled.serviceConfig.Environment = ["TS_DEBUG_DISABLE_PORTLIST=true"] ;
    

    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.

    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?

  5. JustinAzoff commented on May 4, 2024

    @JustinAzoff
    Author

    @shawnvega that was for nixos. For a pi running raspbian, edit /etc/default/tailscaled and add

    TS_DEBUG_DISABLE_PORTLIST="true"
    

    to 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.

  6. shawnvega commented on May 6, 2024

    @shawnvega

    @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.

  7. L3tum commented on Aug 2, 2025

    @L3tum

    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.

  8. dweekly commented on Sep 23, 2026

    @dweekly

    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 tailscaled restart.

    Measured on an idle Ubuntu 24.04 server, tailscale 1.102.4, ~560 processes / ~6100 open fds / 13 Docker containers:

    before after
    /proc/net/{tcp,tcp6,udp,udp6} re-reads ~1/sec 0
    rchar read rate ~35 KB/s ~5 KB/s
    CPU (90s sustained) ~2.0% ~1.0%

    The clearest signal that this is disproportionate work: over 5.4 days of uptime tailscaled had a lifetime rchar of 10.4 GB, while tailscale0 carried only ~97 MB of actual tunnel traffic — ~100x more /proc reading than networking. CPU was also 89% system time (5893s sys vs 704s user), consistent with @JustinAzoff's parseProcNetFile profile.

    Two notes for anyone landing here:

    1. After disabling, the four /proc/net/* fds stay open but are never read again. That looks like the missing defer poller.Close() in
      feature/portlist/portlist.go, which is fixed in 343e2b2.
    2. The real fix (343e2b2, "portlist: use inet_diag for Linux listener discovery") is merged to main but 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=true in /etc/default/tailscaled remains the per-device equivalent, but it requires a restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions