linux服务器如何查看内存,释放内存和缓存

Posted xyhero

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux服务器如何查看内存,释放内存和缓存相关的知识,希望对你有一定的参考价值。

1、使用df -hl 命令,查看挂载空间是否充足;

 技术分享图片

2、使用top命令,查看内存运行情况;

 技术分享图片

使用free -m命令应该也可以:

[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 2013 1661 352 0 223 1206
-/+ buffers/cache: 231 1782
Swap: 2047 0 2047

3、使用sync命令,将缓存写入文件中;

[[email protected] test]# sync

手动执行sync命令(描述:sync 命令运行 sync 子例程。如果必须停止系统,则运行sync 命令以确保文件系统的完整性。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件)

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

默认是0,1表示清空页缓存,2表示清空inode和目录树缓存,3清空所有的缓存。

查看:

[[email protected] ~]# cat /proc/sys/vm/drop_caches

4、冗余数据及时删除,生产数据备份;

测试
[[email protected] ~]# uname -a
Linux testserver 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 2013 1661 352 0 223 1206
-/+ buffers/cache: 231 1782
Swap: 2047 0 2047

[[email protected] ~]# sync
[[email protected] ~]# sync
[[email protected] ~]# cat /proc/sys/vm/drop_caches
0
[[email protected] ~]# echo 3 > /proc/sys/vm/drop_caches
[[email protected]erver ~]# cat /proc/sys/vm/drop_caches
3
[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 2013 100 1913 0 0 14
-/+ buffers/cache: 85 1927
Swap: 2047 0 2047
[[email protected] ~]#

 技术分享图片




























以上是关于linux服务器如何查看内存,释放内存和缓存的主要内容,如果未能解决你的问题,请参考以下文章

如何为linux释放内存和缓存

linux 查看占用内存

Linux free 缓存内存释放

如何手动释放Linux内存的方法

如何手动释放Linux内存?

linux下清理系统缓存并释放内存