procps工具集 ----Linux中的可用内存指的是什么?【转】

转自:https://www.cnblogs.com/zengkefu/p/5654346.html

https://gitlab.com/procps-ng/procps

复制代码
free - Report the amount of free and used memory in the system
kill - Send a signal to a process based on PID
pgrep - List processes based on name or other attributes
pkill - Send a signal to a process based on name or other attributes
pmap - Report memory map of a process
ps - Report information of processes
pwdx - Report current directory of a process
skill - Obsolete version of pgrep/pkill
slabtop - Display kernel slab cache information in real time
snice - Renice a process
sysctl - Read or Write kernel parameters at run-time
tload - Graphical representation of system load average
top - Dynamic real-time view of running processes
uptime - Display how long the system has been running
vmstat - Report virtual memory statistics
w - Report logged in users and what they are doing
watch - Execute a program periodically, showing output fullscreen
复制代码

1、从meminfo文件中查看可用内存:

从Linux kernel-3.14和2.6.27+ 开始,在/proc/meminfo中提供了可用内存MemAvailable值。

kernel 中的available 介绍:

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773

检查/proc/meminfo文件,通过将“MemFree + Buffers+ Cached”相加,预估有多少可用内存,这在十年前是可以,但是在今天肯定是不对的。

因为缓存包含存不能释放的page cache,例如shared memory segments、tmpfs、ramfs,它不包括可收回的slab内存,比如在大多数空闲的系统中,存在很多文件时,它会占用大量的系统内存。

在系统没有发生交换时,预估需要多少available内存才可以启动新的应用程序。这个available字段不同于cache或free字段所提供的数据,它除了要考虑到page cache,还要考虑到当项目在使用时,并不是所有的slabs都能被回收这一情况。

从proc/meminfo文件中查看可用内存:

[root@server-mysql]# /usr/local/bin/free
              total        used        free      shared  buff/cache   available
Mem:        1364828      175720      956704        1168      232404     1064754
Swap:       3071992           0     3071992
[root@server-mysql procps-master]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.3G        171M        934M        1.1M        227M        1.0G
Swap:          2.9G          0B        2.9G

2、使用free命令查看可用内存:

我们一般都使用“free”命令来获得系统的内存使用情况,但是一些老版本的的“procps”包没有包含查看“Available”的参数,可以通过升级“procps”程序来查看“Available”内存值。

procps升级方式(需要大于等于autoconf-2.69支持)

# git clone https://gitlab.com/procps-ng/procps.git

# cd procps

# ./autogen.sh

# ./configure && make&& make install

查看不同free版本显示可用内存的区别:

/usr/bin/free是系统自带的命令。

/usr/local/bin/free是下载最新的procps包编译安装的命令。

原文地址:https://www.cnblogs.com/sky-heaven/p/12170997.html