CPU cache query tool in Linux
In Linux, you can use the following tool to query the CPU cache:
Method 1:
$ Lscpu
L1d cache: 32 K <span style = "white-space: pre"> </span> (level-1 data cache) L1i cache: 32 K <span style = "white-space: pre "> </span> <span style =" font-family: Arial, Helvetica, sans-serif; "> (level-1 Instruction cache) </span> L2 cache: 256 K <span style = "white-space: pre"> </span> (second-level cache) L3 cache: 8192 K <span style = "white-space: pre "> </span> (level 3 cache)
Method 2:
$ cat /sys/devices/system/cpu/cpu0/cache/index0/size32K
$ cat /sys/devices/system/cpu/cpu0/cache/index0/level 1
$ cat /sys/devices/system/cpu/cpu0/cache/index1/size32K
$ cat /sys/devices/system/cpu/cpu0/cache/index1/level 1
$ cat /sys/devices/system/cpu/cpu0/cache/index2/size256K
$ cat /sys/devices/system/cpu/cpu0/cache/index2/level 2
$ Cat/sys/devices/system/cpu/cpu0/cache/index3/size8192K
$ cat /sys/devices/system/cpu/cpu0/cache/index3/level3
Method 3:
$ sudo dmidecode -t cache
However, there is a way out from the above results. The displayed L1 cache is 1024 kB, And the L2 cache is kB. The 8-core cache is not consistent with the implementation.
The program may be faulty. We do not recommend using dmidecode.
# dmidecode 2.12SMBIOS 2.7 present.Handle 0x003B, DMI type 7, 19 bytesCache InformationSocket Designation: CPU Internal L1Configuration: Enabled, Not Socketed, Level 1Operational Mode: Write BackLocation: InternalInstalled Size: 256 kBMaximum Size: 256 kBHandle 0x003C, DMI type 7, 19 bytesCache InformationSocket Designation: CPU Internal L2Configuration: Enabled, Not Socketed, Level 2Operational Mode: Write BackLocation: InternalInstalled Size: 1024 kBMaximum Size: 1024 kBHandle 0x003D, DMI type 7, 19 bytesCache InformationSocket Designation: CPU Internal L3Configuration: Enabled, Not Socketed, Level 3Operational Mode: Write BackLocation: InternalInstalled Size: 8192 kBMaximum Size: 8192 kB
Method 4:
$ Cat/proc/cpuinfo
cache size: 8192 KB
This only shows the size of the L3 cache, which is not accurate.