2026-10-08 18:19:34 +08:00
<!DOCTYPE html>
< html lang = "zh-CN" data-theme = "light" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< title > 性能分析与内核调优 · 阶段 5 模块 3 · SRE 从零到成熟< / title >
< meta name = "description" content = "性能分析与内核调优 模块目录:共 13 章、43 个小节。" >
< link rel = "stylesheet" href = "../../assets/doc.css" >
< / head >
< body >
< header class = "topbar" >
< div class = "tb-in" >
< a class = "brand" href = "../../index.html" > < span class = "logo" > SRE< / span > < div > 从零到成熟< small > 模块详解< / small > < / div > < / a >
< div class = "crumbs" >
< a href = "../../index.html" > 学习路径< / a > < span class = "sep" > /< / span >
< a href = "../../index.html#s5" > 阶段 5 · 扛得住< / a > < span class = "sep" > /< / span >
< b > 性能分析与内核调优< / b >
< / div >
< div class = "spacer" > < / div >
< button class = "btn" id = "tocToggle" > ☰ 导航< / button >
< button class = "btn" id = "themeBtn" title = "切换到深色主题" > 深色< / button >
< / div >
< / header >
< div class = "layout" id = "layout" >
< aside class = "sidebar" >
< h2 > 章节目录< / h2 >
< nav id = "chapters" > < a class = "toc-a" href = "01-why.html" > < i class = "cn" > 1< / i > 方法论:先定位再优化,每次都要有前后对照< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "01-why.html#sec-1-1" > 三个「先优化」的典型翻车< / a > < a class = "toc-a lv3" href = "01-why.html#sec-1-2" > USE 方法:把「哪里慢」变成一张待查清单< / a > < a class = "toc-a lv3" href = "01-why.html#sec-1-3" > 没有前后对照的优化不算优化< / a > < / div > < a class = "toc-a" href = "02-toolbox.html" > < i class = "cn" > 2< / i > 基础工具箱:六个命令各自回答哪个问题< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "02-toolbox.html#sec-2-1" > 问题与命令的对应表< / a > < a class = "toc-a lv3" href = "02-toolbox.html#sec-2-2" > top 与 vmstat: 秒级现场和十秒趋势< / a > < a class = "toc-a lv3" href = "02-toolbox.html#sec-2-3" > sar: 故障已经过去, 只有它还记得< / a > < a class = "toc-a lv3" href = "02-toolbox.html#sec-2-4" > ss 与 pidstat: 连接, 以及按进程归因< / a > < / div > < a class = "toc-a" href = "03-cpu.html" > < i class = "cn" > 3< / i > CPU 分析: 负载、运行队列与「CPU 高但吞吐不高」< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "03-cpu.html#sec-3-1" > load average 到底在数什么< / a > < a class = "toc-a lv3" href = "03-cpu.html#sec-3-2" > 运行队列、上下文切换与非自愿切换< / a > < a class = "toc-a lv3" href = "03-cpu.html#sec-3-3" > CPU 高但吞吐不高:三种典型与 perf top 初探< / a > < / div > < a class = "toc-a" href = "04-memory.html" > < i class = "cn" > 4< / i > 内存分析: available、page cache 与 swap 抖动< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "04-memory.html#sec-4-1" > free 的每一列,以及一个判据< / a > < a class = "toc-a lv3" href = "04-memory.html#sec-4-2" > buff/cache、脏页与直接 IO< / a > < a class = "toc-a lv3" href = "04-memory.html#sec-4-3" > swap 抖动与 OOM 判定< / a > < / div > < a class = "toc-a" href = "05-io.html" > < i class = "cn" > 5< / i > IO 分析: iostat -x 的每一列与「到底是谁在等」< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "05-io.html#sec-5-1" > iostat -x 列精读< / a > < a class = "toc-a lv3" href = "05-io.html#sec-5-2" > %iowait 的语义,以及「到底是谁在等」< / a > < a class = "toc-a lv3" href = "05-io.html#sec-5-3" > 文件系统与 IO 调度器< / a > < / div > < a class = "toc-a" href = "06-perf.html" > < i class = "cn" > 6< / i > perf 与火焰图:把定位精度推到函数级< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "06-perf.html#sec-6-1" > 为什么采样比插桩更适合生产< / a > < a class = "toc-a lv3" href = "06-perf.html#sec-6-2" > perf record / report 实战< / a > < a class = "toc-a lv3" href = "06-perf.html#sec-6-3" > 生成并读懂火焰图< / a > < a class = "toc-a lv3" href = "06-perf.html#sec-6-4" > 符号缺失:[unknown] 的四种来源与修法< / a > < / div > < a class = "toc-a" href = "07-ebpf.html" > < i class = "cn" > 7< / i > eBPF 与 off-CPU: CPU 不高却慢的终极武器< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "07-ebpf.html#sec-7-1" > bcc 工具箱:把问题映射到工具< / a > < a class = "toc-a lv3" href = "07-ebpf.html#sec-7-2" > bpftrace: 不用编译的一行脚本< / a > < a class = "toc-a lv3" href = "07-ebpf.html#sec-7-3" > off-CPU 分析:把「等」变成火焰图< / a > < / div > < a class = "toc-a" href = "08-kernel.html" > < i class = "cn" > 8< / i > 内核与协议参数:能被一行配置改死的那些默认值< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "08-kernel.html#sec-8-1" > 文件句柄:三处限制,改错一处等于没改< / a > < a class = "toc-a lv3" href = "08-kernel.html#sec-8-2" > TCP 队列: backlog 的取小语义与溢出判定< / a > < a class = "toc-a lv3" href = "08-kernel.html#sec-8-3" > TIME_WAIT 与端口复用< / a > < a class = "toc-a lv3" href = "08-kernel.html#sec-8-4" > 内存回收行为与套接字缓冲< / a > < / div > < a class = "toc-a" href = "09-app.html" > < i class = "cn" > 9< / i > 应用侧: GC、连接池、线程模型与锁竞争< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "09-app.html#sec-9-1" > GC 调优:先减分配,再调参数< / a > < a class = "toc-a lv3" href = "09-app.html#sec-9-2" > 连接池:池子大小由下游决定,不是由你决定< / a > < a class = "toc-a lv3" href = "09-app.html#sec-9-3" > 线程与协程模型:并发数算错的两个
< div class = "side-foot" >
< a class = "btn" href = "index.html" > ← 模块目录< / a >
< a class = "btn" href = "../../index.html" > 学习路径< / a >
< / div >
< / aside >
< div class = "mask" id = "mask" > < / div >
< main class = "main-col" >
< article >
< div class = "modhero" >
< span class = "mh-no" > 阶段 5 · 模块 3 / 5< / span >
< h1 > 性能分析与内核调优< / h1 >
< p class = "mh-sub" > 阶段 5 · 扛得住 · 只用命令行,从现象一路定位到函数级瓶颈< / p >
< div class = "mh-meta" >
< span > 共 < b > 13< / b > 章< / span >
< span > < b > 43< / b > 个小节< / span >
< span > 约 < b > 72< / b > 千字< / span >
< / div >
< / div >
< p class = "lead" >
< b > 模块定位:< / b > 阶段 5 的第 3 个模块。< a href = "../s5-01-oncall/index.html" > On-call 与应急响应< / a > 教你在故障里保住用户,
这一页教你在故障里< b > 找到原因< / b > 。它和容量规划的区别是:容量问「能扛多少」,性能问「现在到底卡在哪一行」。
本模块刻意绕开监控系统——假设 Prometheus 挂了、看板没有这个指标、exporter 没采集到那个维度,
你手上只有一台能 ssh 上去的机器和一套命令行工具。命令行定位能力是 SRE 的地基:
监控告诉你「哪里异常」,命令行告诉你「为什么异常」。
< br > < br >
< b > 学完之后你应该能:< / b > 用 < code > top< / code > / < code > vmstat< / code > / < code > iostat< / code > / < code > sar< / code > / < code > ss< / code > / < code > pidstat< / code >
在 5 分钟内把问题收敛到 CPU、内存、IO、网络中的一类; 用 < code > perf< / code > 采样并生成火焰图,把定位精度推到函数级;
用 < code > bpftrace< / code > / < code > bcc< / code > 做 off-CPU 分析, 找出「CPU 不高但慢」的真凶;
会算文件句柄、< code > somaxconn< / code > 、TCP backlog、TIME_WAIT 这几个能被一行配置改死的参数;
并且每次优化都留下可核对的前后对照数据。
< br > < br >
< b > 前置:< / b > 阶段 0 的 < a href = "../s0-01-linux/index.html" > Linux 系统与命令行< / a > ( 进程、文件描述符、内核参数、systemd) 、
< a href = "../s0-02-network/index.html" > 计算机网络< / a > ( TCP 握手挥手、拥塞控制、DNS 解析链路)、
阶段 2 的 < a href = "../s2-01-metrics/index.html" > 指标与 Prometheus< / a > (本章所有结论都要能回到同一条指标曲线上复核)、
阶段 3 的 < a href = "../s3-03-capacity/index.html" > 容量规划与成本< / a > (拐点、水位、单请求 CPU 时间是本模块的参照系)。
< br > < br >
< b > 建议投入:< / b > 20– 24 小时。< b > 其中至少 10 小时必须在一台能随便折腾的 Linux 机器上动手< / b > ——
开两台虚拟机或一台 4 核 8G 的云主机即可。性能分析是肌肉记忆:< code > vmstat< / code > 的第三列是什么、
< code > iostat -x< / code > 的 < code > aqu-sz< / code > 正常范围是多少,背下来没用,看一百次真实输出才有用。
装好 < code > sysstat< / code > 、< code > perf< / code > 、< code > bcc< / code > 、< code > bpftrace< / code > 、< code > fio< / code > 、< code > stress-ng< / code > 再开始读。
< / p >
< h2 id = "chapters-list" > 章节目录< / h2 >
< ol class = "chaplist" >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 1< / span >
< a class = "ci-title" href = "01-why.html" > 方法论:先定位再优化,每次都要有前后对照< / a >
< a class = "ci-go" href = "01-why.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "01-why.html#sec-1-1" > 三个「先优化」的典型翻车< / a > < a href = "01-why.html#sec-1-2" > USE 方法:把「哪里慢」变成一张待查清单< / a > < a href = "01-why.html#sec-1-3" > 没有前后对照的优化不算优化< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 2< / span >
< a class = "ci-title" href = "02-toolbox.html" > 基础工具箱:六个命令各自回答哪个问题< / a >
< a class = "ci-go" href = "02-toolbox.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "02-toolbox.html#sec-2-1" > 问题与命令的对应表< / a > < a href = "02-toolbox.html#sec-2-2" > top 与 vmstat: 秒级现场和十秒趋势< / a > < a href = "02-toolbox.html#sec-2-3" > sar: 故障已经过去, 只有它还记得< / a > < a href = "02-toolbox.html#sec-2-4" > ss 与 pidstat: 连接, 以及按进程归因< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 3< / span >
< a class = "ci-title" href = "03-cpu.html" > CPU 分析: 负载、运行队列与「CPU 高但吞吐不高」< / a >
< a class = "ci-go" href = "03-cpu.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "03-cpu.html#sec-3-1" > load average 到底在数什么< / a > < a href = "03-cpu.html#sec-3-2" > 运行队列、上下文切换与非自愿切换< / a > < a href = "03-cpu.html#sec-3-3" > CPU 高但吞吐不高:三种典型与 perf top 初探< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 4< / span >
< a class = "ci-title" href = "04-memory.html" > 内存分析: available、page cache 与 swap 抖动< / a >
< a class = "ci-go" href = "04-memory.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "04-memory.html#sec-4-1" > free 的每一列,以及一个判据< / a > < a href = "04-memory.html#sec-4-2" > buff/cache、脏页与直接 IO< / a > < a href = "04-memory.html#sec-4-3" > swap 抖动与 OOM 判定< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 5< / span >
< a class = "ci-title" href = "05-io.html" > IO 分析: iostat -x 的每一列与「到底是谁在等」< / a >
< a class = "ci-go" href = "05-io.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "05-io.html#sec-5-1" > iostat -x 列精读< / a > < a href = "05-io.html#sec-5-2" > %iowait 的语义,以及「到底是谁在等」< / a > < a href = "05-io.html#sec-5-3" > 文件系统与 IO 调度器< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 6< / span >
< a class = "ci-title" href = "06-perf.html" > perf 与火焰图:把定位精度推到函数级< / a >
< a class = "ci-go" href = "06-perf.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "06-perf.html#sec-6-1" > 为什么采样比插桩更适合生产< / a > < a href = "06-perf.html#sec-6-2" > perf record / report 实战< / a > < a href = "06-perf.html#sec-6-3" > 生成并读懂火焰图< / a > < a href = "06-perf.html#sec-6-4" > 符号缺失:[unknown] 的四种来源与修法< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 7< / span >
< a class = "ci-title" href = "07-ebpf.html" > eBPF 与 off-CPU: CPU 不高却慢的终极武器< / a >
< a class = "ci-go" href = "07-ebpf.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "07-ebpf.html#sec-7-1" > bcc 工具箱:把问题映射到工具< / a > < a href = "07-ebpf.html#sec-7-2" > bpftrace: 不用编译的一行脚本< / a > < a href = "07-ebpf.html#sec-7-3" > off-CPU 分析:把「等」变成火焰图< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 8< / span >
< a class = "ci-title" href = "08-kernel.html" > 内核与协议参数:能被一行配置改死的那些默认值< / a >
< a class = "ci-go" href = "08-kernel.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "08-kernel.html#sec-8-1" > 文件句柄:三处限制,改错一处等于没改< / a > < a href = "08-kernel.html#sec-8-2" > TCP 队列: backlog 的取小语义与溢出判定< / a > < a href = "08-kernel.html#sec-8-3" > TIME_WAIT 与端口复用< / a > < a href = "08-kernel.html#sec-8-4" > 内存回收行为与套接字缓冲< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 9< / span >
< a class = "ci-title" href = "09-app.html" > 应用侧: GC、连接池、线程模型与锁竞争< / a >
< a class = "ci-go" href = "09-app.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "09-app.html#sec-9-1" > GC 调优:先减分配,再调参数< / a > < a href = "09-app.html#sec-9-2" > 连接池:池子大小由下游决定,不是由你决定< / a > < a href = "09-app.html#sec-9-3" > 线程与协程模型:并发数算错的两个方向< / a > < a href = "09-app.html#sec-9-4" > 锁竞争与伪共享< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 10< / span >
< a class = "ci-title" href = "10-network.html" > 网络与依赖侧: 重传、DNS 与「本机假象」< / a >
< a class = "ci-go" href = "10-network.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "10-network.html#sec-10-1" > 重传与拥塞窗口:把网络质量问题变成数字< / a > < a href = "10-network.html#sec-10-2" > DNS: 最容易被忽略的固定延迟源< / a > < a href = "10-network.html#sec-10-3" > 「我慢」还是「我等」:本机假象的判据< / a > < a href = "10-network.html#sec-10-4" > 网卡、软中断与丢包< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 11< / span >
< a class = "ci-title" href = "11-report.html" > 定位报告:从现象到函数级的完整推理链< / a >
< a class = "ci-go" href = "11-report.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "11-report.html#sec-11-1" > 五层推理链与每层的判据< / a > < a href = "11-report.html#sec-11-2" > 一份能通过复核的报告长什么样< / a > < a href = "11-report.html#sec-11-3" > 结论怎么写才不会被推翻< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 12< / span >
< a class = "ci-title" href = "12-cheat.html" > 速查表与高频坑< / a >
< a class = "ci-go" href = "12-cheat.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "12-cheat.html#sec-12-1" > 症状驱动的命令速查表< / a > < a href = "12-cheat.html#sec-12-2" > 内核参数速查表< / a > < a href = "12-cheat.html#sec-12-3" > 十二个高频坑< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 13< / span >
< a class = "ci-title" href = "13-checklist.html" > 完成标准与自测< / a >
< a class = "ci-go" href = "13-checklist.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "13-checklist.html#sec-13-1" > 自测题< / a > < a href = "13-checklist.html#sec-13-2" > 下一步< / a > < / div >
< / li >
< / ol >
< div class = "box tip" >
< span class = "bt" > 怎么用这一模块< / span >
< p > 左侧是< b > 章节目录树< / b > :先看章标题快速定位,进入某一章后该章的小节会展开并跟随滚动高亮;点其它章标题可直接跳到对应页面。< / p >
< p > 每章结尾都有「上一章 / 下一章」可以连续阅读,代码块右上角可以一键复制。< / p >
< / div >
< / article >
< nav class = "pager" >
< a class = "prev" href = "../s5-02-postmortem/index.html" > < span class = "k" > ← 上一模块< / span > < span class = "v" > 复盘与根因分析< / span > < / a >
< a class = "next" href = "../s5-04-security/index.html" > < span class = "k" > 下一模块 →< / span > < span class = "v" > 安全与合规运维< / span > < / a >
< / nav >
< p class = "foot" >
性能分析与内核调优 · 模块目录< br >
< a href = "../../index.html" > 返回学习路径< / a >
< / p >
< / main >
< / div >
< button id = "toTop" title = "回到顶部" > ↑< / button >
< script src = "../../assets/doc.js" > < / script >
2026-10-14 22:42:38 +08:00
< script src = "../../../../assets/back.js" data-portal-back = "knowledge/sre-learning-path" data-portal-label = "知识库 › SRE 从零到成熟学习路径" > < / script >
2026-10-08 18:19:34 +08:00
< / body >
< / html >