linux - 了解缓存中的程序

标签 linux caching ubuntu ram

我现在遇到 RAM 和 SWAP 的情况:

$ free -h
             total       used       free     shared    buffers     cached
Mem:          7,7G       7,5G       159M       100M        75M       5,9G
-/+ buffers/cache:       1,5G       6,1G
Swap:         7,9G       408M       7,5G

我想知道...

有没有办法知道哪些程序/数据被 RAM 缓存和/或它们来自哪个进程?

我的想法是,既然它们是可重复使用的,就应该有一种方法来“识别”它们。
但是我的知识实在是太少了,不知道怎么做。

非常感谢您。

最佳答案

is there a way to know what programs/data are RAM-cached and/or from which process do they come from?

有一个程序http://hoytech.com/vmtouch/ vmtouch。它提供了文件缓存中文件的百分比信息。您可能需要编译它。这是我电脑上的例子:

在读取不在缓存中的文件之前:

$ vmtouch -v  /usr/share/dict/linux.words
/usr/share/dict/linux.words
[                                                          ] 0/1210

           Files: 1
     Directories: 0
  Resident Pages: 0/1210  0/4M  0%
         Elapsed: 0.000169 seconds

从文件中读取一些数据后:

$ tail -n 10000 /usr/share/dict/linux.words >/dev/null
$ vmtouch -v  /usr/share/dict/linux.words
/usr/share/dict/linux.words
[                                                        oO] 24/1210

           Files: 1
     Directories: 0
  Resident Pages: 24/1210  96K/4M  1.98%
         Elapsed: 0.000152 seconds

vmtouch 首先为文件调用nmap,然后使用mincore 系统调用来确定文件或其某些页面是否驻留在内存:

man mincore:

DESCRIPTION

mincore() returns a vector that indicates whether pages of the calling process’s virtual memory are resident in core (RAM), and so will not cause a disk access (page fault) if referenced. The kernel returns residency information about the pages starting at the address addr, and continuing for length bytes.

关于linux - 了解缓存中的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23662322/

相关文章:

c - ifconfig->which 的结果是我要提供给 TCP/IP 套接字的 IP 地址

Java - 即使文件不可读,file.length() 也会返回

linux - 内核是否不够聪明,无法为已读取的同一文件的 block 删除一些缓存?

.net - 如何创建行特定的 sql 缓存依赖项?

python - 选择目录后,QtGui.QFileDialog.getExistingDirectory() 窗口不会关闭(PyQt)

python - 检测 VGA 显示器何时插入

c++ - 在 Ubuntu 上安装 pHash 时出错

linux - 使用机器人框架和 VNCserver 的 Selenium@library 的代理设置

hibernate - 如何在grails中缓存(整个表或Domain.list()方法的结果)?

linux - gnu 联机帮助页,关于 "env"命令的两个版本的文档