現象: 容器裡的 AI 推論、編譯或資料處理突然變慢,主機 RAM 看起來還有剩,最後卻在尖峰時被 OOM Killer 終止。只盯著 free 或 top,常常看不到是哪一個 cgroup 先碰到壓力。 Phenomenon: An AI inference, build, or data-processing container suddenly slows down. The host still appears to have free RAM, yet the workload is eventually killed by the OOM killer. Looking only at free or top hides which cgroup reached pressure first. cgroup v2 memory control memory.current observe usage memory.high reclaim / throttle memory.max hard boundary memory.events latency + logs 圖一|先觀察用量,再以 memory.high 控制回收與降速,最後才把 memory.max 當硬邊界。 Figure 1 | Observe usage, throttle with memory.high, and reserve memory.max for the hard boundary. 機制:三個檔案代表三種控制語意 / Mechanism: three files, three meanings cgroup v2 的 memory.current 是目前用量;memory.high 是「超過後要付出成本」的軟邊界,核心會讓工作進入回收與節流路徑,但不以它直接殺掉整個 cgroup;memory.max 才是硬邊界,回收仍不足時可能觸發 cgroup 內的 OOM。這三者不是三個可互換的 RAM 數字,而是由觀察、降速到最後保護的階梯。 In cgroup v2, memory.current reports current usage. memory.high is a throttle boundary: crossing it pushes tasks throu...
daily-tech:2026-11-16 現象:一個指標,為什麼不能直接讀? / Symptom: Why can’t one pointer simply be read? 寫 eBPF 時,最容易踩到的坑不是語法,而是「我明明先算出位址,為什麼載入核心就被拒絕?」原因是 eBPF 程式會在核心內執行;Linux 不能等錯誤發生後才補救,因此載入前先由 verifier 檢查指標型別、數值範圍、對齊與控制流程。 When writing eBPF, the frustrating failure is often not syntax: “I calculated the address, so why did the kernel reject the program?” eBPF runs inside the kernel. Linux therefore checks pointer types, value ranges, alignment, and control flow before loading instead of repairing a fault afterward. 機制:verifier 追蹤的是狀態,不是猜測 / Mechanism: the verifier tracks states, not guesses 官方文件把暫存器分成 scalar 與多種 pointer。scalar 會保存最小、最大值與未知位元;指標則帶著來源與可存取範圍。以封包為例,先取出 data 與 data_end,再確認 data 加上標頭長度沒有越過 data_end,之後那個分支內的讀取才被視為安全。若中間把指標做成無法證明範圍的運算,狀態會退化成 scalar,後面的記憶體讀取就會失效。 The kernel documentation describes registers as scalars or several pointer types. A scalar carries bounds and unknown bits; a pointer carries its origin and an accessible range. For packet data, the program loads data and data_end,...