Linux写日志一段时间以后变得非常卡顿
在Linux上通需要长时间写大量的日志,一开始系统是非常顺畅的,一段时间以后系统会变得非常卡顿,通过ssh连上机器以后去执行的命令速度非常非常慢。
直接在机器上接上显示器,通过free命令查看系统内容情况。
发现可用内存(freed)非常少非常少,cached占用了系统总内存的绝大部分,通过一段时间的观察,这个cached一直在上升没有下降的意思(一直在写日志)。
最后,系统实在是太慢太卡了,只能是重启系统。重启以后一开始也是十分顺畅,当可用内存所剩无几、cached变得很大的时候又非常卡顿。
请问:
cached一直增大时导致系统卡顿的原因吗?如果不是,那么造成系统卡顿的原因可能是什么呢?
说明:
已经单独严重写日志的程序是没有内存泄露的。 可能是io的问题,你把日志先都写到/dev/null,如果同样时间没问题,估计就是io太慢:luya: 关闭swap试一下。 nswcfd 发表于 2016-05-16 18:21 static/image/common/back.gif
关闭swap试一下。
free命令看到,swap分区都没有被使用到 试试"echo 3 >/proc/sys/vm/drop_caches "会不会好点? zhayun604863141 发表于 2016-05-30 13:44 static/image/common/back.gif
试试"echo 3 >/proc/sys/vm/drop_caches "会不会好点?
有用的,但是直接drop cache会不会太暴力了,有些数据可能在cache里面没有write back到硬盘文件的吧
另外一个,如果是在sysctl.conf里面设置vm.drop_caches = 3再sysctl -p的话,好像只生效一次。
每执行一次echo 3 >/proc/sys/vm/drop_caches,cache会下降,可用内存会回升,过一段时间cache有增大了许多
得不断执行echo 3 >/proc/sys/vm/drop_caches
可以尝试修改调大/proc/sys/vm/vfs_cache_pressure 的值试试
Documentation/sysctl/vm.txt:
vfs_cache_pressure
------------------
Controls the tendency of the kernel to reclaim the memory which is used for
caching of directory and inode objects.
At the default value of vfs_cache_pressure=100 the kernel will attempt to
reclaim dentries and inodes at a "fair" rate with respect to pagecache and
swapcache reclaim.Decreasing vfs_cache_pressure causes the kernel to prefer
to retain dentry and inode caches. When vfs_cache_pressure=0, the kernel will
never reclaim dentries and inodes due to memory pressure and this can easily
lead to out-of-memory conditions. Increasing vfs_cache_pressure beyond 100
causes the kernel to prefer to reclaim dentries and inodes.
页:
[1]