Linux CPUInfo 中 L1 缓存的解读

一、先搞清 L1 缓存的含义
二、在 Linux 中查看 L1 的正确方式
L1d cache: 32K、L1i cache: 32K 表示该 CPU 的每个核心拥有 32KB 数据缓存与 32KB 指令缓存。cache size : 256 KB 的总缓存或三级缓存值,很多发行版不会在 cpuinfo 中直接给出 L1d/L1i 的细分;因此更推荐用 lscpu 或 sysfs 查看 L1。/sys/devices/system/cpu/cpuX/cache/level 与 type 文件为准)。cat /sys/devices/system/cpu/cpu0/cache/index0/sizecat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_sizecat /sys/devices/system/cpu/cpu0/cache/index0/type(应为 Data/Instruction)。三、读懂 L1 相关字段与计算
lscpu 的 Core(s) per socket × Socket(s),或用 /proc/cpuinfo 统计不同 physical id 与 cpu cores。CPU(s) 或 processor 数量;若 Thread(s) per core = 2 则开启了超线程。四、常见误区与排查
cache size 当成 L1。很多平台该字段反映的是 L3 或“最末级缓存”,并非 L1;请以 lscpu 或 sysfs 为准。level 与 type 文件确认哪个是 L1d/L1i,不要仅凭 index0/1/2/3 猜测。