linux手动释放资源

查看内存占用情况:free

free
              total        used        free      shared  buff/cache   available
Mem:        1863252      775764      249672       14140      837816      863760
Swap:       2097148           0     2097148

默认kb为单位,使用-m,-g参数可以改为mb,gb参数

free -m
              total        used        free      shared  buff/cache   available
Mem:           1819         758         242          13         818         842
Swap:          2047           0        2047

占用内存的一般是文件系统的缓存,这些缓存刷入磁盘不会影响读写数据。所以可以手动释放

sync 命令将所有未写的系统缓冲区写到磁盘中,具体可以使用sync --help或者man sync查看说明

释放内存

echo 3 > /proc/sys/vm/drop_caches

/proc/sys/vm/drop_caches默认是0

# echo 1 > /proc/sys/vm/drop_caches; free pagecache, use
# echo 2 > /proc/sys/vm/drop_caches; free dentries and inodes
# echo 3 > /proc/sys/vm/drop_caches; free pagecache, dentries and inodes

参考proc目录下文件说明

http://man7.org/linux/man-pages/man5/proc.5.html

总体来说,手动释放内存占用需要同时执行如下两个命令:

sync
echo 3 > /proc/sys/vm/drop_caches

执行完之后可以再次free -m查看内存占用情况

sync 将未写的缓存刷入磁盘

echo N > /proc/sys/vm/drop_caches释放缓存

Writing to this file causes the kernel to drop clean caches, dentries, and inodes from memory, causing that memory to become free

 

查看文件句柄占用数量

lsof -c php

查看php占用的文件句柄信息,包括php、php-fpm,-c参数是获取所有php开头的进程占用文件信息

lsof -c php | wc可以统计行数,也就是占用的文件的个数,

如果文件占用数量太大,也没有更好的办法,只能重启php-fpm,找到文件占用过高的问题出处,有open的地方一定要close,

 

查看其他资源占用情况,

top

按q退出,top动态显示当前进程占用的资源列表,网络、内存、cpu占用情况,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值