暗无天日

=============>DarkSun的个人博客

如何在Linux上查看RAM信息

一般常用的查看RAM的方法是运行 free -h 或者直接查看 /proc/meminfo 文件

free -h

结果为:

              总计         已用        空闲      共享    缓冲/缓存    可用
内存:        3.6G        1.9G        693M         76M        1.1G        2.0G
交换:        8.0G          0B        8.0G
cat /proc/meminfo

结果为:

MemTotal:        3814108 kB
MemFree:          704976 kB
MemAvailable:    2111076 kB
Buffers:          129312 kB
Cached:           822152 kB
SwapCached:            0 kB
Active:          1578760 kB
Inactive:        1215704 kB
Active(anon):    1205632 kB
Inactive(anon):    77724 kB
Active(file):     373128 kB
Inactive(file):  1137980 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       8388604 kB
SwapFree:        8388604 kB
Dirty:               184 kB
Writeback:             0 kB
AnonPages:       1843088 kB
Mapped:           392840 kB
Shmem:             78340 kB
Slab:             216944 kB
SReclaimable:     181768 kB
SUnreclaim:        35176 kB
KernelStack:        7296 kB
PageTables:        20540 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    10295656 kB
Committed_AS:    4622348 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      118400 kB
DirectMap2M:     3846144 kB

但是通过这种方式,你只能看到内存的总量和使用量。而无法知道内存的类型(DDR1、DDR2、DDR3、DDR4、SDRAM、DRAM)、频率等信息。

要获取这些信息,你需要借助 dmidecode 命令,像下面这样:

sudo dmidecode --type memory

结果为:

# dmidecode 3.1
Getting SMBIOS data from sysfs.
SMBIOS 2.6 present.

Handle 0x0005, DMI type 16, 15 bytes
Physical Memory Array
        Location: System Board Or Motherboard
        Use: System Memory
        Error Correction Type: None
        Maximum Capacity: 16 GB
        Error Information Handle: Not Provided
        Number Of Devices: 2

Handle 0x0006, DMI type 17, 28 bytes
Memory Device
        Array Handle: 0x0005
        Error Information Handle: Not Provided
        Total Width: 64 bits
        Data Width: 64 bits
        Size: 2048 MB
        Form Factor: SODIMM
        Set: None
        Locator: ChannelA-DIMM0
        Bank Locator: BANK 0
        Type: DDR3
        Type Detail: Synchronous
        Speed: 1333 MT/s
        Manufacturer: Hynix/Hyundai
        Serial Number: 3152AA49
        Asset Tag: 9876543210
        Part Number: HMT325S6BFR8C-H9  
        Rank: Unknown

Handle 0x0007, DMI type 17, 28 bytes
Memory Device
        Array Handle: 0x0005
        Error Information Handle: Not Provided
        Total Width: 64 bits
        Data Width: 64 bits
        Size: 2048 MB
        Form Factor: SODIMM
        Set: None
        Locator: ChannelB-DIMM0
        Bank Locator: BANK 2
        Type: DDR3
        Type Detail: Synchronous
        Speed: 1333 MT/s
        Manufacturer: Hynix/Hyundai
        Serial Number: 0C41233F
        Asset Tag: 9876543210
        Part Number: HMT325S6BFR8C-H9  
        Rank: Unknown

可以看到,结果一共分成4段,其中

还有一种方法是,利用 lshw 来获取内存信息

sudo lshw -class memory

结果为:

*-cache:0
     description: L1 cache
     physical id: 2
     slot: L1-Cache
     size: 64KiB
     capacity: 64KiB
     capabilities: synchronous internal write-through data
     configuration: level=1
*-cache:1
     description: L2 cache
     physical id: 3
     slot: L2-Cache
     size: 256KiB
     capacity: 256KiB
     capabilities: synchronous internal write-through data
     configuration: level=2
*-cache:2
     description: L3 cache
     physical id: 4
     slot: L3-Cache
     size: 3MiB
     capacity: 3MiB
     capabilities: synchronous internal write-back unified
     configuration: level=3
*-memory
     description: System Memory
     physical id: 5
     slot: System board or motherboard
     size: 4GiB
   *-bank:0
        description: SODIMM DDR3 Synchronous 1333 MHz (0.8 ns)
        product: HMT325S6BFR8C-H9
        vendor: Hynix/Hyundai
        physical id: 0
        serial: 3152AA49
        slot: ChannelA-DIMM0
        size: 2GiB
        width: 64 bits
        clock: 1333MHz (0.8ns)
   *-bank:1
        description: SODIMM DDR3 Synchronous 1333 MHz (0.8 ns)
        product: HMT325S6BFR8C-H9
        vendor: Hynix/Hyundai
        physical id: 1
        serial: 0C41233F
        slot: ChannelB-DIMM0
        size: 2GiB
        width: 64 bits
        clock: 1333MHz (0.8ns)
*-firmware
     description: BIOS
     vendor: LENOVO
     physical id: f
     version: 8AET52WW (1.32 )
     date: 09/15/2011
     size: 128KiB
     capacity: 8128KiB
     capabilities: pci pnp upgrade shadowing cdboot bootselect edd int13floppy720 int5printscreen int9keyboard int14serial int17printer int10video acpi usb biosbootspecification

从它的 description, size, 和 clock 中也可以看出内存为DDR3,每条内存2G,频率为1333MHz。