排查ThinkPad X240 Linux Mint工作站卡顿问题的系统性方法及事后日志方案咨询
Hey Pierre, let’s work through this systematically to figure out why your X240 is acting sluggish. You’ve already ruled out the obvious culprits like RAM exhaustion or constant swapping, and average CPU load looks fine—so let’s dig into the remaining suspects and set up logging to catch those intermittent slowdowns after they happen.
一、即时排查:逐一验证你的假设
Let’s tackle each of your hypotheses with concrete checks:
1. 验证SSD IO瓶颈
If your SSD is struggling with IO queues, that can cause system-wide lag even if RAM/CPU look okay. Here’s how to check:
- Run
iostat -x 1in the terminal to get real-time disk stats. Keep an eye on:- %util: If this stays near 100%, your SSD is operating at full capacity.
- await: This is the average time (in milliseconds) IO requests wait to be processed. A high number (over 50ms) means requests are piling up.
- Use
iotop(install it withsudo apt install iotop) to see exactly which processes are hogging disk bandwidth—sometimes background tasks like system indexers or update daemons are the culprit. - Check your SSD’s health with
sudo smartctl -a /dev/sda(replace/dev/sdawith your actual SSD device). Look for metrics like Percentage Used or Wear Leveling Count—if your drive is heavily worn, its IO performance will drop off.
2. 检查图形硬件加速是否正常
Since most of the slowness happens in Firefox (especially Google Maps), faulty hardware acceleration could be the issue:
- In Firefox, go to
about:supportand scroll to the Graphics section. Verify that:- Compositing is set to WebRender
- Hardware acceleration is enabled
- WebGL and WebGL 2 show as Available
- System-wide, run
glxinfo | grep "direct rendering"—if it outputsYes, OpenGL hardware acceleration is working. - Test by disabling Firefox’s hardware acceleration (Settings → General → Performance → Uncheck "Use hardware acceleration when available"). If the slowness eases, that points to a graphics driver issue that needs tweaking.
3. 排查系统配置异常或后台进程问题
Average load doesn’t always catch short, sharp CPU spikes that cause lag. Let’s dig deeper:
- Use
htop(install withsudo apt install htop) to monitor real-time CPU usage. Watch for processes that jump to 100% CPU for even a few seconds—these can cause the choppiness you’re seeing, even if average load stays below 1.00. - Check enabled startup services with
systemctl list-unit-files --type=service | grep enabled. Look for unnecessary services (like extra cloud sync tools, unused indexing services) that might be running in the background and consuming resources. - Create a new user account and test your workflow (Firefox + LibreOffice) there. If the slowness disappears, the problem is likely corrupted configuration files in your main user profile (e.g., a broken Firefox setting).
4. 重新确认CPU实际负载(跳出平均负载的局限)
Average load is a 1/5/15 minute average, so it can miss short-lived CPU bottlenecks:
- Run
mpstat -P ALL 1to see real-time usage for each CPU core. Sometimes a single core gets pinned by a single-threaded process, causing lag even if overall average load is low. - Use
perf top(install withsudo apt install linux-tools-common) to see exactly which kernel or user-space functions are consuming CPU. This can uncover hidden issues like inefficient kernel modules or buggy process code.
二、事后日志方案:捕捉间歇性卡顿的证据
Since you can’t always be there when the slowness hits, set up persistent logging to record system metrics for later analysis:
1. 用sar跟踪系统资源
sysstat包中的sar工具会自动定期记录系统状态:
- 安装工具:
sudo apt install sysstat - 编辑配置文件
/etc/default/sysstat,将ENABLED="false"改为ENABLED="true" - 重启服务:
sudo systemctl restart sysstat - 日志存储在
/var/log/sysstat/目录下,卡顿发生后可以用以下命令分析:sar -u查看历史CPU使用率sar -r查看内存状态sar -d查看磁盘IO活动
- 把卡顿发生的时间点和日志对应,就能找到异常指标。
2. 用pidstat记录进程级活动
写一个简单脚本持续记录实时进程状态:
#!/bin/bash # 保存为log_processes.sh mkdir -p ~/system_logs while true; do pidstat -u -r -d -p ALL 1 >> ~/system_logs/pidstat_logs.txt sleep 1 done
- 赋予脚本执行权限:
chmod +x log_processes.sh - 后台启动脚本:
nohup ./log_processes.sh & - 脚本会每秒记录所有进程的CPU、内存、磁盘IO使用率,卡顿发生后搜索对应时间点的日志就能找到异常进程。
3. 捕获显卡驱动日志
- 查看
/var/log/Xorg.0.log获取显卡驱动相关错误。如果需要更详细的日志,编辑/etc/X11/xorg.conf(不存在就新建)并添加:Section "Log" Option "Verbosity" "3" EndSection - 重启系统后,Xorg日志会包含更多渲染相关的细节,有助于定位硬件加速问题。
4. 记录Firefox活动
如果卡顿是浏览器专属问题,捕获Firefox的详细日志:
- 在Firefox地址栏输入
about:config,设置browser.dom.window.dump.enabled为true - 关闭Firefox,从终端启动并记录日志:
firefox > ~/firefox_log.txt 2>&1 - 日志会记录浏览器的所有活动,包括渲染错误和扩展相关问题,卡顿发生后检查对应时间点的日志即可找到线索。
三、额外快速测试
- 尝试用Chrome/Chromium替代Firefox,如果卡顿消失,说明问题出在Firefox的配置或扩展上。
- 禁用除了你安装的标签卸载扩展之外的所有Firefox插件,有时候插件冲突会导致意外的性能损耗。
备注:内容来源于stack exchange,提问作者Pierre

