关于内存及内存释放的命令

2020-12-23  本文已影响0人  慕知
1,查看内存使用(buffers和cache是连在一起的)
[root@m01~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         131         271          24         570         609
Swap:          1023           1        1022
2,查看内存使用(buffers和cache分开)
[root@m01~]# free -w
              total        used        free      shared     buffers       cache   available
Mem:         995896      134548      277624       25016           0      583724      623792
Swap:       1048572        1544     1047028

buffers 是即将要被写入磁盘
cache 是从磁盘中读出来的

3,sync
- 释放内存之前,多次执行sync,会尽可能把内存的数据存到硬盘,保证不丢失
4,释放内存命令
#可多次执行
[root@m01~]# echo 3 > /proc/sys/vm/drop_caches

#查看
[root@m01~]# free -w
              total        used        free      shared     buffers       cache   available
Mem:         995896      114568      797812       25016           0       83516      742624
Swap:       1048572        1544     1047028
  • buffers和cache是包含在可使用内存中的
  • 算出内存使用率:used / total
  • 算出内存可使用率: available / total
5,计算内存使用率
[root@m01~]# free -w
              total        used        free      shared     buffers       cache   available
Mem:         995896      115384      794456       25016           0       86056      740528
Swap:       1048572        1544     1047028


[root@m01~]# available=`free -w | awk 'NR==2{print $NF}'`
[root@m01~]# total=`free -w | awk 'NR==2{print $2}'`
[root@m01~]# echo "scale=2;$available / $total" | bc
.74

[root@m01~]# result=`echo "scale=2;$available / $total" | bc | cut -d. -f2`
[root@m01~]# echo $result
74
上一篇下一篇

猜你喜欢

热点阅读