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,...
現象: AI 推論、編譯或大量 I/O 同時跑時,CPU 可能沒有 100%,但延遲突然變長。只看 top 很難知道工作卡在 CPU、記憶體還是 I/O。 Phenomenon: During inference, builds, or heavy I/O, latency can jump while CPU is below 100%. top alone cannot identify whether work waits on CPU, memory, or I/O. PSI pressure-stall flow runnable work is delayed kernel aggregates some / full stall /proc/pressure/* time windows correlate with p95 tune reversibly 圖 1|PSI 將想執行卻被延遲的時間彙整成可觀察訊號。 Figure 1 | PSI turns delayed progress into an observable signal. 機制:PSI 量的是有工作卻前進不了 / Mechanism: PSI measures stalled progress Pressure Stall Information(PSI)統計任務因資源競爭而停滯的時間。some 表示至少部分任務受阻;full 表示一段時間內所有非閒置工作都受阻。Linux 將 CPU、記憶體與 I/O 分別放在 /proc/pressure/。 Pressure Stall Information (PSI) measures time lost to contention. some means some tasks are stalled; full means all non-idle work is stalled for an interval. Linux exposes CPU, memory, and I/O separately under /proc/pressure/. 影響:先分辨壓力類型 / Impact: classify pressure first 邊緣 LLM 若 memory some 持續升高,可能是回收、匿名頁或記憶體頻寬造成延遲;若 io...