You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux系统下如何获取CPU缓存路数(ways)与组数(sets)?

Linux下查询CPU缓存路数(ways)和组数(sets)的方法

在Linux系统里,除了lscpu,还有几种可靠的方法能获取缓存的路数和组数:

1. 使用cpuid工具

cpuid直接读取CPU的CPUID指令输出,能拿到最底层的缓存参数。

  • 先安装工具:
    Debian/Ubuntu系:sudo apt install cpuid
    RHEL/CentOS系:sudo yum install cpuid
  • 运行命令查看缓存详情:
    cpuid -1 | grep -A 10 "Cache"
    输出里的ways associativity对应路数,number of sets对应组数。如果要精准过滤,也可以用:
    cpuid -r | grep -E "(cache_ways|cache_sets)"

2. 读取sysfs文件系统

Linux的sysfs提供了硬件的详细属性文件,缓存信息存在/sys/devices/system/cpu/cpu0/cache/路径下:

  • 每个缓存层级对应一个index*目录(比如index0是L1数据缓存,index1是L1指令缓存,index2是L2,index3是L3,可通过cat /sys/devices/system/cpu/cpu0/cache/index*/type确认类型)
  • 查看路数:cat /sys/devices/system/cpu/cpu0/cache/index3/ways_of_associativity
  • 查看组数:cat /sys/devices/system/cpu/cpu0/cache/index3/number_of_sets
    把index3换成对应的层级目录,就能获取对应缓存的参数。

3. 使用hwloc工具

hwloc是硬件拓扑查询工具,能直观展示缓存的关联属性:

  • 安装工具:
    Debian/Ubuntu系:sudo apt install hwloc
    RHEL/CentOS系:sudo yum install hwloc
  • 命令行模式查看:
    lstopo-no-graphics | grep -E "Associativity|Sets"
    输出里会明确标注每个缓存层级的路数(Associativity)和组数(Sets)。

内容的提问来源于stack exchange,提问作者xdxdxd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 10:30:42