SagerNet/sing-box

在大量路由表下 netlink 路由轮询导致 CPU 占用过高

Open

#3180 opened on Jul 14, 2025

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Go (33,800 stars) (3,997 forks)batch import
bughelp wanted

Description

操作系统

Linux

系统版本

debian 12 6.1.0-10-amd64

安装类型

sing-box 原始命令行程序

如果您使用图形客户端程序,请提供该程序版本。

No response

版本

sing-box version 1.12.0-beta.33

Environment: go1.24.4 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale
Revision: 8ec5593805c9eaef1faa772ca9e08a59110c6c7c
CGO: disabled

描述

在拥有大量系统路由表的机器上(运行了 bird)运行 singbox,导致 cpu 内存高占用 pprof 发现 checkUpdate 通过 netlink.RouteListFiltered 轮询整个路由表,每次调用都要处理大量路由条目导致高 CPU 占用和内存占用

Showing nodes accounting for 19.85s, 91.60% of 21.67s total
Dropped 156 nodes (cum <= 0.11s)
Showing top 20 nodes out of 76
      flat  flat%   sum%        cum   cum%
    12.80s 59.07% 59.07%     12.80s 59.07%  internal/runtime/syscall.Syscall6
     2.74s 12.64% 71.71%      2.74s 12.64%  runtime.memclrNoHeapPointers
     1.24s  5.72% 77.43%      1.24s  5.72%  runtime.memmove
     0.75s  3.46% 80.90%      1.81s  8.35%  runtime.scanobject
     0.42s  1.94% 82.83%      0.62s  2.86%  runtime.findObject
     0.25s  1.15% 83.99%      0.30s  1.38%  runtime.typePointers.next
     0.21s  0.97% 84.96%      0.21s  0.97%  runtime.nextFreeFast (inline)
     0.19s  0.88% 85.83%      1.72s  7.94%  github.com/sagernet/netlink.deserializeRoute
     0.17s  0.78% 86.62%      0.17s  0.78%  runtime.madvise
     0.15s  0.69% 87.31%      0.15s  0.69%  runtime.(*mspan).base (inline)
     0.14s  0.65% 87.96%      1.11s  5.12%  github.com/sagernet/netlink/nl.ParseRouteAttr
     0.13s   0.6% 88.56%      0.79s  3.65%  runtime.mallocgcSmallScanNoHeader
     0.11s  0.51% 89.06%      0.11s  0.51%  runtime.duffcopy
     0.10s  0.46% 89.52%     19.57s 90.31%  github.com/sagernet/netlink.(*Handle).RouteListFiltered
     0.10s  0.46% 89.99%      0.33s  1.52%  runtime.bulkBarrierPreWriteSrcOnly
     0.10s  0.46% 90.45%      4.90s 22.61%  runtime.growslice
     0.10s  0.46% 90.91%      4.30s 19.84%  runtime.mallocgc
     0.07s  0.32% 91.23%      0.23s  1.06%  runtime.greyobject
     0.05s  0.23% 91.46%      0.22s  1.02%  runtime.wbBufFlush1
     0.03s  0.14% 91.60%     14.27s 65.85%  github.com/sagernet/netlink/nl.(*NetlinkRequest).Execute

重现方式

config.json:

{
    "log": {
        "disabled": true,
        "level": "info",
        "timestamp": true
    },
    "inbounds": [
        {
            "type": "shadowsocks",
            "listen": "::",
            "listen_port": 43533,
            "method": "2022-blake3-chacha20-poly1305",
            "password": "kk2ZV6dAX+NzDeqc/bFkS5Sn3tOkGxa8M3x6Z/JOoEU=",
            "tcp_fast_open": true,
            "tcp_multi_path": true,
            "udp_fragment": true
        }
    ],
    "outbounds": [
        {
            "type": "direct"
        }
    ]
}

日志

支持我们

完整性要求

  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我保证提供了可以在本地重现该问题的服务器、客户端配置文件与流程,而不是一个脱敏的复杂客户端配置文件。
  • 我保证提供了可用于重现我报告的错误的最简配置,而不是依赖远程服务器、TUN、图形界面客户端或者其他闭源软件。
  • 我保证提供了完整的配置文件与日志,而不是出于对自身智力的自信而仅提供了部分认为有用的部分。

Contributor guide