[Linux] Linux下谁在消耗我们的cache
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[Linux] Linux下谁在消耗我们的cache,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2364字,纯文字阅读大概需要4分钟。
内容图文
![[Linux] Linux下谁在消耗我们的cache](/upload/InfoBanner/zyjiaocheng/1305/c1e2abc88e174751bda946dd0fbea9c8.jpg)
一、缘由:
曾经看到MySQL服务器上Cache占用特别大,其实大家都知道这是合理的,这些都是可用内存;
那么问题来了,是谁在占用这些Cache呢?如果去掉不合理的Cache占用,系统内存会更充分的得到利用。
total used free shared buffers cached Mem: 64309 55889 8420 0 240 43363 -/+ buffers/cache: 1228552024 Swap: 20479020479
由上图可见,Cache占用了42G内存,猛地一看很可怕。实际上他还属于memfree之列。具体说明,可以看这里:
http://www.linuxatemyram.com/。
二、解决办法:
这里有两个工具可以查看某个文件是否占用了Page Cache,占用了多少:fincore和vmtouch
1、fincore
这是linux-ftools工具的一部分,你给出文件(夹)名作为输入,他会告诉你他有多少文件(数据)被系统缓存起来。
因为不太会安装,这里不做推荐,具体看这里https://code.google.com/p/linux-ftools/。
2、vmtouch
vmtouch可以查到缓存的文件和目录、把文件推入缓存和驱逐缓存中的文件等等。(推荐)
安装方法:
$ git clone https://github.com/hoytech/vmtouch$ cd vmtouch $ make $ sudomakeinstall
使用方法:
$ vmtouch vmtouch: no files or directories specified vmtouch v1. 0.2 - the Virtual Memory Toucher by Doug Hoyte Portable file system cache diagnostics and control Usage: vmtouch [OPTIONS] ... FILES OR DIRECTORIES ... Options: -t touch pages into memory -e evict pages from memory -l lock pages in physical memory with mlock(2) -L lock pages in physical memory with mlockall(2) -d daemon mode -m max file size to touch -p use the specified portion instead of the entire file -f follow symbolic links -h also count hardlinked copies -wwaituntil all pages are locked (only useful together with -d) -v verbose -q quiet
例子:
1)查看/tmp目录在内存中的缓存:
$ vmtouch /tmp/ vmtouch: WARNING: skipping non-regular file: /tmp/ssh-GgJnCEkWMQC2/agent.1068 Files: 17 Directories: 7 Resident Pages: 4780/4780 18M/18M 100% Elapsed: 0.001006 seconds
详细信息查看可使用-v参数 例如:vmtouch -v /tmp/
2)查看一个文件被缓存了多少:
$ vmtouch -v ~/Downloads/phoronix-test-suite_6.0.1_all.deb /home/neo/Downloads/phoronix-test-suite_6.0.1_all.deb [ ] 0/132 Files: 1 Directories: 0 Resident Pages: 0/1320/528K 0% Elapsed: 0.000117 seconds
3)把文件缓存起来:
$ vmtouch -vt ~/Downloads/phoronix-test-suite_6.0.1_all.deb /home/neo/Downloads/phoronix-test-suite_6.0.1_all.deb [OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO] 132/132 Files: 1 Directories: 0 Touched Pages: 132 (528K) Elapsed: 0.007935 seconds
4)把缓存中的数据驱逐出去:
$ vmtouch -ve ~/Downloads/phoronix-test-suite_6.0.1_all.deb Evicting /home/neo/Downloads/phoronix-test-suite_6.0.1_all.deb Files: 1 Directories: 0 Evicted Pages: 132 (528K) Elapsed: 0.000109 seconds
附:
具体信息参考官网:https://hoytech.com/vmtouch/
另一个参考页面:vmtouch: portable file cache analyzer
原文:http://www.cnblogs.com/langdashu/p/5953222.html
内容总结
以上是互联网集市为您收集整理的[Linux] Linux下谁在消耗我们的cache全部内容,希望文章能够帮你解决[Linux] Linux下谁在消耗我们的cache所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。