#overall check usage memory
free -mh
#overall check usage
sar -r 2 2
#check swap Report swap space utilization statistics
sar -S 2 2
# Report swapping statistics
sar -W 2 2
#check memory info
cat /proc/meminfo
# clean swap
sync
echo 3 > /proc/sys/vm/drop_caches
#check swap use thread value
sysctl -q vm.swappiness
# swap off/on
swapoff
swapon
root@shubuntu ~ free -mh ✔ ⚡ 25 05:08:08
total used free shared buff/cache available
Mem: 912M 110M 92M 4.3M 708M 781M
Swap: 0B 0B 0B
* free:读取自文件:/proc/meminfo
* buffer存放要写回到磁盘的数据
* cache存放从磁盘上读出的数据
* -buffers/cache,表示一个应用程序认为系统被用掉多少内存;被程序实实在在占用的内存
* +buffers/cache,表示一个应用程序认为系统还有多少内存;可用的内存数。
root@shubuntu ~ sar -r 2 ✔ ⚡ 26 05:34:34
Linux 4.15.0-1031-raspi2 (shubuntu) 07/18/19 _aarch64_ (4 CPU)
05:35:04 kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
05:35:06 95052 800684 838888 89.82 111368 485472 397660 42.58 458196 181020 48
05:35:08 94924 800556 839016 89.84 111376 485472 397660 42.58 458204 181020 40
05:35:10 94892 800524 839048 89.84 111376 485472 397660 42.58 458204 181020 40
kbmemfree:这个值和free命令中的free值基本一致,所以它不包括buffer和cache的空间.
kbmemused:这个值和free命令中的used值基本一致,所以它包括buffer和cache的空间.
%memused:物理内存使用率,这个值是kbmemused和内存总量(不包括swap)的一个百分比.
kbbuffers和kbcached:这两个值就是free命令中的buffer和cache.
kbcommit:保证当前系统所需要的内存,即为了确保不溢出而需要的内存(RAM+swap).
%commit:这个值是kbcommit与内存总量(包括swap)的一个百分比.
root@shubuntu ~ sar -S 2 SIGINT(2) ↵ ⚡ 30 05:48:05
Linux 4.15.0-1031-raspi2 (shubuntu) 07/18/19 _aarch64_ (4 CPU)
05:49:55 kbswpfree kbswpused %swpused kbswpcad %swpcad
05:49:57 0 0 0.00 0 0.00
05:49:59 0 0 0.00 0 0.00
05:50:01 0 0 0.00 0 0.00
root@shubuntu ~ sar -W 2 2 127 ↵ ⚡ 52 09:13:57
Linux 4.15.0-1031-raspi2 (shubuntu) 07/19/19 _aarch64_ (4 CPU)
09:25:18 pswpin/s pswpout/s
09:25:20 0.00 0.00
09:25:22 0.00 0.00
Average: 0.00 0.00
pswpout/s Total number of swap pages the system brought out per second.
pswpin/s Total number of swap pages the system brought in per second.
root@shubuntu ~ vmstat 2 ✔ ⚡ 28 05:45:14
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 94892 111444 613880 0 0 0 2 10 13 0 0 100 0 0
0 0 0 94860 111444 613880 0 0 0 0 8321 62 0 0 100 0 0
0 0 0 94860 111444 613880 0 0 0 0 8314 50 0 0 100 0 0
0 0 0 94860 111452 613872 0 0 0 18 8397 119 0 0 100 0 0
0 0 0 94892 111452 613876 0 0 0 0 8315 54 0 0 100 0 0
* r:等待运行的进程数,r<5表示状态好
* b:处于非中断睡眠状态的进程数,b≈0表示状态好
* id:CPU闲置时间
* 如果r经常大于3或4,且id经常小于50,表示CPU负荷很重
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free reclaimable slab objects (includes dentries and inodes):
echo 2 > /proc/sys/vm/drop_caches
To free slab objects and pagecache:
echo 3 > /proc/sys/vm/drop_caches