Leadaxe 说明 sing-box-lx 已实现 Go 运行时内存限制模式,尚待设备验证

在 sing-box-lx #62 的讨论中,Leadaxe 表示相关实现已提交到 lx 分支,尚未进入 tag。新增 Status.MemoryRuntime 表示 Go 运行时占用,原 Memory 仍表示进程 RSS;内部选项 OomMemoryLimitHeap 默认关闭,显式启用且限制大于零时按运行时占用判断阈值,并继续监测系统可用内存,没有新增配置键。作者还纠正了把该设备发热归因于 GC 软限制的推断,称相关包已有 9 项单元测试,但尚未设备验证,需在 tag 后通过 LxBox 检查。

作者原文

Implemented in 0f94afdcc (SPEC 148, SPECS/TASKS/148-OOM_KILLER_RUNTIME_MEMORY/SPEC.md), on lx, not yet in a tag.

What landed, per the contract above:

  • Measured quantity: runtime/metrics /memory/classes/total:bytes − /memory/classes/heap/released:bytes — the figure debug.SetMemoryLimit governs, read without stop-the-world. Not memory.Inuse().
  • Status.MemoryRuntime (proto memoryRuntime = 10, StatusMessage.MemoryRuntime): one additive javap getter. Memory stays the process RSS. Sent on every status tick regardless of the oom-killer settings.
  • SetupOptions.OomMemoryLimitHeap (default false = upstream behaviour). With the flag and a limit > 0 the oom-killer runs the new policy mode runtime_limit: the limit is compared with the runtime figure; thresholds limit − 5 / − 10 MiB and the GC soft limit limit*4/5 are unchanged, so "200 MB" means GC target 160 MiB and a reset at 195 MiB of runtime memory. The watch on the system available memory stays on (either condition triggers); a zero Available reading counts as unknown. No config key: the option field is internal like MemoryLimitOverride.
  • Flag, not platform automatics: the same limit path serves boxdd and lxd, where the process is the core and RSS is the right measure.

Two notes from the allocs profile attached to the thread: the live Go heap was 42 MB, so the 160 MiB soft limit was not binding on that device — the "soft limit below the live heap" paragraph above does not hold; the GC churn (WG pools 108 MB allocated for 16 MB live, x/net socket.recvMsg 43 MB) is the SPEC 020 topic, not this one. And the rate trigger never arms on Android (its baseline is set only by the darwin pressure callback).

Nine unit tests (service/oomkiller, common/lxmemory), both packages added to lx-ci. Not device-verified: that is the LxBox check after the tag (no memory threshold reached at start with a WARP WG group and limit 200, MemoryRuntime ≠ Memory in Status, a test heap leak still resets).