Linux에서 L1, L2, L3 캐시 및 RAM의 크기를 알 수있는 방법이 있습니까?


답변:


23

당신이 만약 lshw설치 :

$ sudo lshw -C memory

예

$ sudo lshw -C memory
...
  *-cache:0
       description: L1 cache
       physical id: a
       slot: Internal L1 Cache
       size: 32KiB
       capacity: 32KiB
       capabilities: asynchronous internal write-through data
  *-cache:1
       description: L2 cache
       physical id: b
       slot: Internal L2 Cache
       size: 256KiB
       capacity: 256KiB
       capabilities: burst internal write-through unified
  *-cache:2
       description: L3 cache
       physical id: c
       slot: Internal L3 Cache
       size: 3MiB
       capacity: 8MiB
       capabilities: burst internal write-back
  *-memory
       description: System Memory
       physical id: 2a
       slot: System board or motherboard
       size: 8GiB
     *-bank:0
          description: SODIMM DDR3 Synchronous 1334 MHz (0.7 ns)
          product: M471B5273CH0-CH9
          vendor: Samsung
          physical id: 0
          serial: 67010644
          slot: DIMM 1
          size: 4GiB
          width: 64 bits
          clock: 1334MHz (0.7ns)
     *-bank:1
          description: SODIMM DDR3 Synchronous 1334 MHz (0.7 ns)
          product: 16JTF51264HZ-1G4H1
          vendor: Micron Technology
          physical id: 1
          serial: 3749C127
          slot: DIMM 2
          size: 4GiB
          width: 64 bits
          clock: 1334MHz (0.7ns)

1
답변에 실질을 포함하십시오. 명령 이름 만 언급하지 말고 출력을 표시하십시오.
— slm

lshw(물론 루트 권한으로 실행) 캐시 정보를 제공하지 않았습니다. 하지만 lscpu및 dmidecode도구 나에게 결과를 주었다.
— Shnd

19

lscpu

당신이 크기에 대한 유일한 관심 경우 시도 lscpu에서 util-linux.

예

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    2
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 37
Model name:            Intel(R) Core(TM) i5 CPU       M 560  @ 2.67GHz
Stepping:              5
CPU MHz:               1199.000
BogoMIPS:              5319.88
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0-3

x86info

x86info라는 패키지 / 명령도 있어야합니다. i386 / x86_64가 있다고 가정하면 x86info -c캐시에 대한 자세한 정보를 제공해야합니다.

예

$ x86info -c
x86info v1.30.  Dave Jones 2001-2011
Feedback to <davej@redhat.com>.

Found 4 identical CPUs
Extended Family: 0 Extended Model: 2 Family: 6 Model: 37 Stepping: 5
Type: 0 (Original OEM)
CPU Model (x86info's best guess): Core i7 (Nehalem) [Clarkdale/Arrandale]
Processor name string (BIOS programmed): Intel(R) Core(TM) i5 CPU       M 560  @ 2.67GHz

Cache info
 L1 Instruction cache: 32KB, 4-way associative. 64 byte line size.
 L1 Data cache: 32KB, 8-way associative. 64 byte line size.
 L2 (MLC): 256KB, 8-way associative. 64 byte line size.
TLB info
 Instruction TLB: 2MB or 4MB pages, fully associative, 7 entries
 Instruction TLB: 4K pages, 4-way associative, 64 entries.
 Data TLB: 4KB or 4MB pages, fully associative, 32 entries.
 Data TLB: 4KB pages, 4-way associative, 64 entries
 Data TLB: 4K pages, 4-way associative, 512 entries.
 Data TLB: 4KB or 4MB pages, fully associative, 32 entries.
 Data TLB: 4KB pages, 4-way associative, 64 entries
 64 byte prefetching.
 Data TLB: 4K pages, 4-way associative, 512 entries.
Found unknown cache descriptors: dd 
Total processor threads: 4
This system has 1 dual-core processor with hyper-threading (2 threads per core) running at an estimated 2.65GHz

3

이 명령을 시도해 볼 수 있습니다.

$sudo dmidecode -t cache

예

$ sudo dmidecode -t cache | grep -iE "leve|installed"
    Configuration: Enabled, Socketed, Level 1
    Installed Size: 32 kB
    Installed SRAM Type: Asynchronous
    Configuration: Enabled, Socketed, Level 2
    Installed Size: 256 kB
    Installed SRAM Type: Burst
    Configuration: Enabled, Socketed, Level 3
    Installed Size: 3072 kB
    Installed SRAM Type: Burst

RAM을 보려면 추가 스위치를 추가하십시오 -t memory.

$ sudo dmidecode -t cache -t memory

참고 문헌


3

getconf

getconf -a | grep CACHE

제공합니다 :

LEVEL1_ICACHE_SIZE                 32768
LEVEL1_ICACHE_ASSOC                8
LEVEL1_ICACHE_LINESIZE             64
LEVEL1_DCACHE_SIZE                 32768
LEVEL1_DCACHE_ASSOC                8
LEVEL1_DCACHE_LINESIZE             64
LEVEL2_CACHE_SIZE                  262144
LEVEL2_CACHE_ASSOC                 8
LEVEL2_CACHE_LINESIZE              64
LEVEL3_CACHE_SIZE                  20971520
LEVEL3_CACHE_ASSOC                 20
LEVEL3_CACHE_LINESIZE              64
LEVEL4_CACHE_SIZE                  0
LEVEL4_CACHE_ASSOC                 0
LEVEL4_CACHE_LINESIZE              0

또는 단일 레벨의 경우 :

getconf LEVEL2_CACHE_SIZE

이 인터페이스의 멋진 점은 POSIX sysconfC 함수를 둘러싼 래퍼 일 뿐이며 (캐시 인수는 POSIX 확장이 아닙니다) C 코드에서도 사용할 수 있습니다.

우분투 16.04에서 테스트되었습니다.

x86 CPUID 명령어

CPUID x86 명령어는 캐시 정보도 제공하며 사용자 사이트 ( https://en.wikipedia.org/wiki/CPUID)에서 직접 액세스 할 수 있습니다.

glibc는 x86에이 방법을 사용하는 것 같습니다. 나는 단계 디버깅 / 명령 추적으로 확인하지 않았지만 2.28의 소스 sysdeps/x86/cacheinfo.c는 다음을 수행합니다.

__cpuid (2, eax, ebx, ecx, edx);

최소한의 C 예제를 생성 할 일, 게으른 지금에 질문 : /programming/14283171/how-to-receive-l1-l2-l3-cache-size-using-cpuid-instruction-in-x86

ARM에는 캐시 크기 ID 레지스터 (CCSIDR)와 같은 레지스터를 통해 캐시 크기를 찾는 아키텍처 정의 메커니즘도 있습니다 . 개요 는 ARMv8 프로그래머 설명서 11.6 "캐시 발견"을 참조하십시오 .


2

sysfs2008 년 이후 로 / sys Linux 파일 시스템으로 내 보낸 특수 파일이 있습니다 .

https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu

What:       /sys/devices/system/cpu/cpu*/cache/index*/<set_of_attributes_mentioned_below>
Date:       July 2014(documented, existed before August 2008)
Description:    Parameters for the CPU cache attributes

    allocation_policy:
        - WriteAllocate: allocate a memory location to a cache line
                 on a cache miss because of a write
        - ReadAllocate: allocate a memory location to a cache line
                on a cache miss because of a read
        - ReadWriteAllocate: both writeallocate and readallocate

    coherency_line_size: the minimum amount of data in bytes that gets
                 transferred from memory to cache

    level: the cache hierarchy in the multi-level cache configuration

    number_of_sets: total number of sets in the cache, a set is a
            collection of cache lines with the same cache index

    physical_line_partition: number of physical cache line per cache tag

    shared_cpu_list: the list of logical cpus sharing the cache

    shared_cpu_map: logical cpu mask containing the list of cpus sharing
            the cache

    size: the total cache size in kB

    type:
        - Instruction: cache that only holds instructions
        - Data: cache that only caches data
        - Unified: cache that holds both data and instructions

    ways_of_associativity: degree of freedom in placing a particular block
                of memory in the cache

    write_policy:
        - WriteThrough: data is written to both the cache line
                and to the block in the lower-level memory
        - WriteBack: data is written only to the cache line and
                 the modified cache line is written to main
                 memory only when it is replaced

ID 파일 :

What:       /sys/devices/system/cpu/cpu*/cache/index*/id
Date:       September 2016
Contact:    Linux kernel mailing list <linux-kernel@vger.kernel.org>
Description:    Cache id

    The id provides a unique number for a specific instance of
    a cache of a particular type. E.g. there may be a level
    3 unified cache on each socket in a server and we may
    assign them ids 0, 1, 2, ...

    Note that id value can be non-contiguous. E.g. level 1
    caches typically exist per core, but there may not be a
    power of two cores on a socket, so these caches may be
    numbered 0, 1, 2, 3, 4, 5, 8, 9, 10, ...

내 컴퓨터에 이유를 궁금해 index0하고 index1모두가 할 level 1커널 v4.15에, 그것은 혼란. 0 인덱스 예방 코딩? :-)
— Ciro Santilli 新疆 改造 中心 法轮功 六四 事件

1
@CiroSantilli 华 涌 低端 人口 六四 事件 法轮功 (이름을 발음하지 않음)의 경우 index0은 L1 with typeData (L1 데이터 캐시)이고 index1은 L1 with typeInstruction (L1 명령어 캐시)에 관한 것입니다. 그런 다음 index2는 type Unified 및 level2입니다 (L2 캐시, 데이터와 명령을 모두 저장할 수 있음)
— osgx

아. 넵! 나는 :-) 문서를 읽을 수있는 더 인내심을해야한다
— 치로 틸리新疆改造中心法轮功六四事件

1

cpuid

다른 옵션은 cpuid 프로그램입니다. CPUID지침을 사용 하며 루트가 필요하지 않습니다. 또한 cpuidLinux 커널 모듈을 통해 작동 할 수 있습니다 .

cache and TLB information (2):
   0x59: data TLB: 4K pages, 16 entries
   0xba: data TLB: 4K pages, 4-way, 64 entries
   0x4f: instruction TLB: 4K pages, 32 entries
   0xc0: data TLB: 4K & 4M pages, 4-way, 8 entries
   0x80: L2 cache: 512K, 8-way, 64 byte lines
   0x30: L1 cache: 32K, 8-way, 64 byte lines
   0x0e: L1 data cache: 24K, 6-way, 64 byte lines

일반 소비자 CPU에서 L1 및 L2 캐시는 코어 당이고 L3 캐시는 모든 코어에서 공유됩니다.


0

L3 만 원한다면 grep "cache size" < /proc/cpuinfo충분해야합니다.

그러나 L3 캐시가 CPU 아치간에 공유되는 방식이 다르므로 해당 값을 정규화해야합니다.


아마도 쓸모없는 고양이 사용을 제거하고 싶을 것입니다.
— maxschlepzig
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.