Linux free 查看内存使用情况 常用命令

45 篇文章 3 订阅

Intro

  • 常用命令

free
free -h 以更易读(human-readable)的格式输出
free -s 3 每3秒输出一次

  • 示例
wuyujin1997@budy:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           985M        253M        124M        2.7M        607M        566M
Swap:            0B          0B          0B
wuyujin1997@budy:~$
  • 行列意义

先区分行:

  • Mem 真正的物理内存
  • Swap 交换空间(物理量内存过小时利用了硬盘空间进行“中转”的空间)

再区分列:

  • total 机器的整体内存大小(物理内存 + 处于硬盘区的交换空间)

  • used 已使用的内存大小,计算方式: total - free - buffers - cache

  • free 未使用/空闲的内存

  • shared 共享内存(tmpfs使用的内存)

  • buff/cache 内核使用的缓冲块buffer、页面缓存cache。

  • available 估算在不使用交换空间的前提下,有多少内存可用于新启动的程序运行。

  • 表格分析

              total        used        free      shared  buff/cache   available
Mem:           985M        253M        124M        2.7M        607M        566M
Swap:            0B          0B          0B

由表格可见,我的机器:
内存大小total为:985M
已使用内存used为: 253M
空闲内存free为:124M
buff/cache之和为607M
而:已使用内存 + 空闲内存 + buff/cache = 253 + 124 + 607 = 984M 约等于整体内存985M

两个核心指标:
total 机器整体内存有985M
available 新运行程序的可用内存大小为566M(而非free的124M)

available是大于free值的,因为如果新启动的程序内存不够用,可以去回收buff/cache的大小来运行新的程序。
可得available的值上限:free+buff/cache
即:0 < available < (free + buff/cache) 毕竟buff/cache使用的内存是不能被全部回收的。

程序文档

  • 查看free命令的使用手册

man free

NAME
       free - Display amount of free and used memory in the system

SYNOPSIS
       free [options]

DESCRIPTION
       free  displays  the total amount of free and used physical and swap memory in the system, as well as the buffers
       and caches used by the kernel. The information is gathered by parsing /proc/meminfo. The displayed columns are:

       total  Total installed memory (MemTotal and SwapTotal in /proc/meminfo)

       used   Used memory (calculated as total - free - buffers - cache)

       free   Unused memory (MemFree and SwapFree in /proc/meminfo)

       shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)

       buffers
              Memory used by kernel buffers (Buffers in /proc/meminfo)

       cache  Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)

       buff/cache
              Sum of buffers and cache

       available
              Estimation of how much memory is available for starting new applications, without  swapping.  Unlike  the
              data provided by the cache or free fields, this field takes into account page cache and also that not all
              reclaimable memory slabs will be reclaimed due to items being  in  use  (MemAvailable  in  /proc/meminfo,
              available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)
...

可见:free命令的输出信息是基于/proc/meminfo文件的

  • 查看系统文件

more /proc/meminfo

wuyujin1997@budy:~$ more /proc/meminfo
MemTotal:        1008720 kB
MemFree:          123096 kB
MemAvailable:     575792 kB
Buffers:          145400 kB
Cached:           398732 kB
SwapCached:            0 kB
Active:           622084 kB
Inactive:         141012 kB
Active(anon):     219436 kB
Inactive(anon):     2348 kB
Active(file):     402648 kB
Inactive(file):   138664 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:               372 kB
Writeback:             0 kB
AnonPages:        219020 kB
Mapped:            92012 kB
Shmem:              2820 kB
Slab:              93564 kB
SReclaimable:      77848 kB
SUnreclaim:        15716 kB
KernelStack:        2988 kB
PageTables:         7156 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      504360 kB
Committed_AS:     906428 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       85888 kB
DirectMap2M:      962560 kB
DirectMap1G:           0 kB
wuyujin1997@budy:~$ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值