Howto在Linux上查看内存

服务器上除了CPU还有内存,硬盘等硬件。

前面我们讲了查看CPU信息的几种方式。
这篇文章将讲述查看内存信息。

首先来看一下当前内存的使用量怎么查看

查看内存信息用到的命令是free
命令: free
常用参数
-g 输出结果以G为单位
-m 输出结果以M为单位
-h 输出结果符合人的阅读习惯

示例1: free -g

[root@localhost ~]# free -g
               total        used        free      shared  buff/cache   available
Mem:               3           0           2           0           0           2
Swap:              3           0           3

示例2: free -m

[root@localhost ~]# free -m
               total        used        free      shared  buff/cache   available
Mem:            3616         585        2979           9         285        3030
Swap:           4003           0        4003

示例3: free -h

[root@localhost ~]# free -h
               total        used        free      shared  buff/cache   available
Mem:           3.5Gi       585Mi       2.9Gi       9.0Mi       285Mi       3.0Gi
Swap:          3.9Gi          0B       3.9Gi

这三种显示内存的方式哪种更适合你的的阅读呢?

如果看过前面安装虚拟机的同学可能会有疑问了。

安装虚拟机时我们选择的是4G内存,为什么这里只显示有3.5G呢?

虽然我们安装的是4G内存,但是系统也会使用一部分内存,

而这这部分被系统使用的内存,free命令是不会统计的,所以用free命令查看到的内存比实际上要小。

如果你想查看更详细的内存信息可以用命令cat /proc/meminfo

使用free命令只能查看内存的使用量。

那怎么才能知道内存的生产厂商,这台机器插了几根内存条,内存的频率呢?
有的小伙伴说这个还不简单,直接打开机箱不久行了,一目了然。

你还真是个大聪明,允许使用这种方法,但是不提倡[手动狗头]。

还记得前面查看CPU信息使用的lshw 命令么?没看过的赶紧去看一下!

这个命令也同样可以查看内存的硬件信息。
接下来看看具体使用方法

命令:lshw -c memory

root@test:~# lshw -c memory
  *-firmware                
       description: BIOS
       vendor: American Megatrends Inc.
       physical id: 0
       version: 1.5
       date: 11/17/2020
       size: 64KiB
       capacity: 32MiB
       capabilities: pci upgrade shadowing cdboot bootselect socketedrom edd int13floppy1200 int13floppy720 int13floppy2880 int5printscreen int14serial int17pacpi usb biosbootspecification uefi
  *-memory
       description: System Memory
       physical id: 22
       slot: System board or motherboard
       size: 32GiB
       capabilities: ecc
       configuration: errordetection=ecc
     *-bank:0
          description: DIMM DDR4 Synchronous 3200 MHz (0.3 ns)
          product: M391A1K43DB2-CWE
          vendor: Samsung
          physical id: 0
          serial: 017D9C66
          slot: DIMMA1
          size: 8GiB
          width: 64 bits
          clock: 3200MHz (0.3ns)
     *-bank:1
          description: DIMM DDR4 Synchronous 3200 MHz (0.3 ns)
          product: M391A1K43DB2-CWE
          vendor: Samsung
          physical id: 1
          serial: 017D9C64
          slot: DIMMA2
          size: 8GiB
          width: 64 bits
          clock: 3200MHz (0.3ns)
     *-bank:2
          description: DIMM DDR4 Synchronous 3200 MHz (0.3 ns)
          product: M391A1K43DB2-CWE
          vendor: Samsung
          physical id: 2
          serial: 017D9BC0
          slot: DIMMB1
          size: 8GiB
          width: 64 bits
          clock: 3200MHz (0.3ns)
     *-bank:3
          description: DIMM DDR4 Synchronous 3200 MHz (0.3 ns)
          product: M391A1K43DB2-CWE
          vendor: Samsung
          physical id: 3
          serial: 017D9B8A
          slot: DIMMB2
          size: 8GiB
          width: 64 bits
          clock: 3200MHz (0.3ns)
  *-cache:0
       description: L1 cache
       physical id: 2d
       slot: L1 Cache
       size: 256KiB
       capacity: 256KiB
       capabilities: synchronous internal write-back unified
       configuration: level=1
  *-cache:1
       description: L2 cache
       physical id: 2e
       slot: L2 Cache
       size: 1MiB
       capacity: 1MiB
       capabilities: synchronous internal write-back unified
       configuration: level=2
  *-cache:2
       description: L3 cache
       physical id: 2f
       slot: L3 Cache
       size: 6MiB
       capacity: 6MiB
       capabilities: synchronous internal write-back unified
       configuration: level=3
  *-memory UNCLAIMED
       description: RAM memory
       product: Cannon Lake PCH Shared SRAM
       vendor: Intel Corporation
       physical id: 14.2
       bus info: pci@0000:00:14.2
       version: 10
       width: 64 bits
       clock: 33MHz (30.3ns)
       capabilities: pm cap_list
       configuration: latency=0
       resources: memory:94112000-94113fff memory:9411d000-9411dfff

列出的信息有点多,知道你不会仔细看。所以这里我就总结了一下。
总结的内容可要仔细看了。

主要看几个字段,

字段说明
description基本描述
product产品型号
vendor厂商名称
size内存大小

从上面的description字段可以看到,该内存是DDR4的,频率是3200MHz
它的型号是:M391A1K43DB2-CWE
生产厂商是:Samsung
单根大小是:8GiB

这里问一个问题,从上面列出的信息。
你知道这台服务器上插了几根内存条么?

不知道没关系。
马上揭晓答案这台服务器有4个内存插槽,并且4个插槽都插上了内存。
这个信息是从哪里得来的呢?

看到 *-bank 字段了么,这个字段就是显示服务器上的内存插槽的。
上面下最后一个是 *-bank:3。
这个序号是从0开始的,因此服务器上有4个内存插槽。

为什么还知道4个插槽都插了内存呢?
因为只要这个插槽插上内存, description字段和下面的一些字段就会有信息,
如果这个插槽是空的话,显示内容如下:

*-bank:22
          description: DIMM Synchronous [empty]
          product: NO DIMM
          vendor: NO DIMM
          physical id: 16
          serial: NO DIMM
          slot: CPU2_DIMM_F1

有个[empty],说明该插槽没有插内存条。

上面2个命令,一个查看内存使用量,一个查看内存硬件信息。
完美。

看完是不是觉得自己又进步了一点点呢?
关注我成为更好的Linuxer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维0到1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值