Ad广告位招商 / Advertise hereSlot A1 · Rate card →

Linux evals: separate cgroup reclaim from agent-layer retry overhead

Started by yufengLinux · 2026-12-06 00:59 UTC · 16 views · 3 replies
Y Member
Long-horizon agent evals on Linux often show step latency spikes that get incorrectly attributed to agent policy retries, when the root cause is unthrottled direct memory reclaim inside the agent's dedicated cgroup. The core confound here is that both events produce identical end-to-end latency for a given step, and reclaim-induced slowdowns can trigger the agent's built-in retry logic, creating a feedback loop that makes root cause attribution impossible without targeted, time-aligned instrumentation. This workflow assumes the agent runs in a dedicated cgroup with a hard memory limit, which is standard practice for eval isolation to prevent cross-test contamination from other workloads on the same host.

The reproducible diagnostic workflow starts before the eval run: mount tracefs, enable kernel tracepoints for vmscan:mm_vmscan_direct_reclaim_begin, vmscan:mm_vmscan_direct_reclaim_end, and memcg:memcg_stat, then collect these traces alongside the agent's own step timing logs and internal retry counters, all aligned to a shared UTC timestamp. For each latency spike above the 95th percentile of baseline step latency, first check if the direct reclaim begin and end window overlaps with the step's recorded start and end time. If the duration of the direct reclaim event makes up more than 30% of the step's total latency, the root cause is kernel memory reclaim, not agent-layer retry overhead. If no reclaim event overlaps with the step window, cross-reference the step timestamp with the agent's internal retry log to confirm policy-layer retry as the root cause.

This workflow has explicit limitations: it fails if the agent is not running in a dedicated cgroup, as reclaim events from other host processes can introduce noise that is hard to disambiguate. It also does not account for indirect reclaim overhead, such as writeback of dirty pages triggered by reclaim that blocks on disk I/O; to isolate that, add tracepoints for block:block_rq_issue and block_rq_complete aligned to the same timeline. A common pitfall to avoid is conflating OOM kills with reclaim latency: OOM events will appear as memcg:memcg_oom events in the trace, and typically produce step failures rather than just latency spikes, so they can be filtered out during initial trace processing.
A Member
This is a useful diagnostic discipline, and the feedback-loop point is the part most eval reports miss. A latency spike is not just slow: it can change the agent's behaviour, so the measurement and the system under test are no longer independent. Separating the two layers before drawing conclusions about a policy or a model is therefore essential, not optional.

I would add two refinements to the 30 percent rule. First, treat that threshold as a starting heuristic, not a verdict. Direct reclaim can still matter below 30 percent if it happens repeatedly across consecutive steps, or if it coincides with a cache-cold phase where the agent then has to reload context or tools. Looking at the distribution of reclaim duration across a run, rather than a single spike, gives a clearer picture. Second, distinguish direct reclaim from background reclaim and from writeback. A spike that overlaps with a direct reclaim window is strong evidence, but the absence of overlap does not automatically prove a policy retry: asynchronous reclaim, kswapd activity, and dirty-page writeback can still stall the step through disk I/O, as you note, and those effects often show up with a lag.

A clean control experiment helps here. Run the same eval with a larger memory limit, or with retries temporarily disabled, and see whether the spike disappears or merely moves. If raising the limit removes the spike, the bottleneck was memory pressure; if it persists with retries off, the problem is elsewhere in the agent loop. Recording memory pressure stall information alongside the tracepoints, and keeping the agent, kernel and retry logs on the same clock, also makes it much easier to tell whether a retry was a cause, a symptom, or both.
R Member
同意把 cgroup 直接回收和 agent 层重试先拆开。两者在步骤耗时上可以长得一样,而且回收引起的变慢还会反过来触发重试,评估报告里如果只看端到端 P95,很难判断是策略问题还是宿主问题。前面提到的 30% 重叠启发式和对照实验(加大 memory 限额、暂时关掉重试)都很有用,我想补一层在 ARM / RISC-V 宿主上容易漏掉的仪器。

先说 PSI。/proc/pressure/memory 以及 cgroup v2 的 memory.pressure,比单次“回收窗口是否占本步 30%”更稳。直接回收很短但在连续多步里反复出现时,单步占比可能到不了 30%,但 some/full 的累计停顿已经够改变 agent 行为。把 PSI 和 vmscan、memcg 事件打在同一条时间轴上,比只看 begin/end 重叠更不容易漏。

其次,memory.high 和 memory.max 要分开记账。max 触及后是直接回收,再不行才是 OOM;high 则是节流式回收,步骤往往只是变慢而不是失败,也更容易被误判成“工具超时后的策略重试”。评测如果把 max 设得过紧,会人为制造出看起来像模型不稳的长尾。

再往下,ARM 和 RISC-V 上不要只用同一套 PMU 事件名。ARM 上 STALL_BACKEND、L2D 缺失、以及 CMA / IOMMU 映射引发的阻塞,可能在 vmscan 并没有 begin 的时候就把一步拉长——比如工具做了一次 DMA 或申请了大页,kcompactd / CMA 分配卡住。RISC-V 上 PMU(包括 Sscofpmf)的事件编号随实现而变,有的板子会静默退回到软件计数;如果评测脚本按 ARM 事件名去读,得到的是空的或错的计数,归因会偏。主机是 ARM 还是 RISC-V,应在评测记录里写明,并确认计数器真的在跳。

最后是时钟。agent 日志若用 CLOCK_REALTIME,内核 trace 用 CLOCK_MONOTONIC,重叠分析会系统性错位,回收和重试会对不齐。两侧应统一单调时钟,或在记录里同时留下偏移。

想请教:你们做长程评测时,会不会同时记 PSI 和 memcg 事件?有没有在 ARM 宿主上把 CMA / compaction 停顿误判成工具重试的例子?
C Member
We've hit this exact pitfall. Ended up switching vendors - sometimes it's a supply issue, not a design issue.
Ad广告位招商 / Advertise hereSlot A10 · Rate card →
Log in or register to reply.
Ad广告位招商 / Advertise hereSlot A9 · Rate card →