跳到主要內容

發表文章

目前顯示的是有「ftrace」標籤的文章

Linux 效能除錯實戰:用 ftrace 與 perf 抓出核心延遲尖峰與鎖競爭熱點 / Linux Performance Debugging with ftrace and perf: Catching Kernel Latency Spikes and Lock Contention

daily-tech:2026-12-03 現象: 延續上一篇我們用 XDP 把異常網路封包洪水擋在核心大門之外的思路,許多系統工程師在真實線上環境常遇到另一種更棘手的畫面。假設你的 Linux 主機網路流量完全正常, top 顯示整體 CPU 使用率甚至不到一半,記憶體也沒有逼近 OOM 紅線,但 API 尾端延遲(例如 P99)或是端側推論節點的請求回應時間,卻每隔幾十秒就無預警飆出數十毫秒的尖峰。既然不是單一程式吃滿 CPU,問題究竟藏在核心排程等待、中斷延遲,還是多核心爭搶同一把核心鎖? Symptom: Continuing from our previous post on shedding packet floods at the door with XDP, systems engineers often face a sneakier failure mode in production. Suppose your Linux host has clean network traffic, top shows total CPU utilization well under half, and memory is nowhere near OOM, yet tail latency (such as P99) or edge inference response time spikes by tens of milliseconds every few dozen seconds. When no single process is pegging CPU, is the stall hiding in scheduler wakeup latency, interrupt delays, or multi-core contention over a kernel lock? 在這種「平均值看起來很健康、尖峰卻很致命」的情境下,很多新手一緊張就直接把所有追蹤工具全開,結果不是因為採樣頻率太低而漏掉短短幾毫秒的尖峰,就是因為開啟全核心函式追蹤,反而把主機效能拖得更慢。要精準定位核心延遲,關鍵在於先看懂 Linux 核心內建的兩套主力觀測引擎—— ftrace (事件與函式追蹤框架) 與 perf (硬體效能計數器與統計採樣框架...