💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
https://www.cnblogs.com/newjiang/p/9541223.html # 查看内存信息 ``` cat /proc/meminfo ``` ``` MemTotal: 2042752 kB MemFree: 437836 kB MemAvailable: 1093472 kB Buffers: 78624 kB Cached: 656148 kB SwapCached: 16812 kB Active: 495972 kB Inactive: 829024 kB Active(anon): 289000 kB Inactive(anon): 310396 kB Active(file): 206972 kB Inactive(file): 518628 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 2095100 kB SwapFree: 1905916 kB Dirty: 112 kB Writeback: 0 kB AnonPages: 558672 kB Mapped: 115024 kB Shmem: 9144 kB Slab: 190000 kB SReclaimable: 117864 kB SUnreclaim: 72136 kB KernelStack: 7920 kB PageTables: 16248 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 3106236 kB Committed_AS: 4336936 kB VmallocTotal: 34359738367 kB VmallocUsed: 0 kB VmallocChunk: 0 kB Percpu: 1536 kB HardwareCorrupted: 0 kB AnonHugePages: 223232 kB ShmemHugePages: 0 kB ShmemPmdMapped: 0 kB HugePages_Total: 10 HugePages_Free: 10 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB Hugetlb: 20480 kB DirectMap4k: 167872 kB DirectMap2M: 1929216 kB ``` ***** # free命令 ``` total used free shared buff/cache available Mem: 2042752 746884 500164 9168 795704 1098836 Swap: 2095100 192512 1902588 ``` 其中第一行用全局角度描述系统使用的内存状况: total——总物理内存 used——已使用内存,一般情况这个值会比较大,因为这个值包括了cache+应用程序使用的内存 free——完全未被使用的内存 shared——应用程序共享内存 buffers——缓存,主要用于目录方面,inode值等(ls大目录可看到这个值增加) cached——缓存,用于已打开的文件 总结: total=used+free used=buffers+cached (maybe add shared also) 第二行描述应用程序的内存使用: 前个值表示-buffers/cache——应用程序使用的内存大小,used减去缓存值 后个值表示+buffers/cache——所有可供应用程序使用的内存大小,free加上缓存值 总结: -buffers/cache=used-buffers-cached +buffers/cache=free+buffers+cached 第三行表示swap的使用: used——已使用 free——未使用 ***** https://stackoverflow.com/questions/30207256/how-to-get-the-size-of-cpu-cache-in-linux lscpu lscpu | grep cache If you want to get size of CPU cache in Linux, easiest way to do that is lscpu: $ lscpu | grep cache L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 15360K If you want to get detailed information on each cache, check sysfs: $ SYSNODE=/sys/devices/system/node $ grep '.*' $SYSNODE/node*/cpu*/cache/index*/* 2>/dev/null | awk '-F[:/]' '{ printf "%6s %6s %24s %s\n" $6, $7, $9, $10, $11 ; }' node0 cpu0 index0 level 1 node0 cpu0 index0 number_of_sets 64 node0 cpu0 index0 physical_line_partition 1 node0 cpu0 index0 shared_cpu_list 0,12 node0 cpu0 index0 shared_cpu_map 0000,00001001 node0 cpu0 index0 size 32K node0 cpu0 index0 type Data node0 cpu0 index0 ways_of_associativity 8 node0 cpu0 index1 coherency_line_size 64 Some cache instances will be seen multiple times (per each hardware thread), but you can check that in shared_cpu_list field getconf getconf -a | grep CACHE gives: 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 Or for a single level: getconf LEVEL2_CACHE_SIZE The cool thing about this interface is that it is just a wrapper around the POSIX sysconf C function (cache arguments are non-POSIX extensions), and so it can be used from C code as well. Tested in Ubuntu 16.04. x86 CPUID instruction The CPUID x86 instruction also offers cache information, and can be directly accessed by userland: https://en.wikipedia.org/wiki/CPUID glibc seems to use that method for x86. I haven't confirmed by step debugging / instruction tracing, but the source for 2.28 sysdeps/x86/cacheinfo.c does that: __cpuid (2, eax, ebx, ecx, edx); TODO create a minimal C example, lazy now, asked at: How to receive L1, L2 & L3 cache size using CPUID instruction in x86 ARM also has an architecture-defined mechanism to find cache sizes through registers such as the Cache Size ID Register (CCSIDR), see the ARMv8 Programmers' Manual 11.6 "Cache discovery" for an overview.