Ubuntu 查看 CPU 缓存大小的常用方法
方法一 使用 lscpu 快速查看
- 在终端运行:lscpu
- 在输出中直接读取缓存行:L1d cache(一级数据缓存)、L1i cache(一级指令缓存)、L2 cache、L3 cache。例如:
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 6144K
- 说明:该方式最直观,适合快速确认各级缓存容量。
方法二 查看 /proc/cpuinfo
- 在终端运行:cat /proc/cpuinfo
- 关注字段:cache size(通常显示的是 L3 缓存大小)。示例:
cache size : 6144 KB
- 提示:该文件按逻辑处理器列出信息,若需汇总可结合 sort/uniq 去重查看。
方法三 通过 sysfs 逐级查看并核对 Cache Line
- 查看各级缓存大小(以 cpu0 为例):
- L1d:cat /sys/devices/system/cpu/cpu0/cache/index0/size
- L1i:cat /sys/devices/system/cpu/cpu0/cache/index1/size
- L2:cat /sys/devices/system/cpu/cpu0/cache/index2/size
- L3:cat /sys/devices/system/cpu/cpu0/cache/index3/size
- 查看缓存行大小(所有层级通常一致):
- cat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size(单位:字节)
- 说明:可据此核对 L1/L2/L3 的实际容量与行大小,适合脚本化采集或深入排查。
方法四 使用 dmidecode 查看处理器缓存信息(需 sudo)
- 在终端运行:sudo dmidecode -t processor
- 在输出中查找与缓存相关的条目(如 Internal L1/L2/L3 Cache),可补充核对硬件规格。