在Linux系统中,可通过以下命令查看CPU缓存大小:
lscpu命令:直接显示各级缓存大小,格式清晰,推荐使用。
lscpu | grep -i cache # 输出示例:L1d cache: 32K, L1i cache: 32K, L2 cache: 256K, L3 cache: 8192K 查看/proc/cpuinfo:需过滤缓存相关行,信息可能较分散。
cat /proc/cpuinfo | grep -i "cache size\|L1\|L2\|L3" /sys/devices/system/cpu/目录:需手动遍历文件,适合脚本处理。
ls /sys/devices/system/cpu/cpu0/cache/ # 查看缓存索引 cat /sys/devices/system/cpu/cpu0/cache/index*/size # 查看各级缓存大小 dmidecode命令:需安装,部分系统可能不准确。
sudo dmidecode -t cache | grep -i "installed size" 注:优先使用lscpu,简单直观;若需详细参数(如缓存类型、关联性),可通过/sys目录或dmidecode获取。