经常需要查看一个文件有多少页面驻留在物理内存中,Linux中没有找到现成的命令,自己动手写了个小工具,基于mincore(2)系统调用。代码放在Github上面,可以git clone git://github.com/dutor/mincore.git获取。
目前可用选项有限:查看特定文件驻留物理内存的页面数/字节数;将文件全部加载到物理内存;递归地查看某个目录下所有文件的映射情况。其他需要的功能,可能在以后添加。
$ ./mincore -h mincore [options] <-p file or directory> -h --help print this message. -p --path path to file or directory you want to inspect. -t --touch whether to touch pages of the file, in order to load them into memory. $ ./mincore -p /lib64/libc.so.6 /lib64/libc.so.6: page count: 420, cached: 408 file size: 1717800(1677K), cached: 1668648(1629K) $ ./mincore -p /lib64/libc.so.6 -t $ ./mincore -p /lib64/libc.so.6 /lib64/libc.so.6: page count: 420, cached: 420 file size: 1717800(1677K), cached: 1717800(1677K) $ ./mincore -p . <.> ./README.md: page count: 1, cached: 1 file size: 326(0K), cached: 4096(4K) ./mincore: page count: 5, cached: 5 file size: 16597(16K), cached: 16597(16K) ./Makefile: page count: 1, cached: 1 file size: 134(0K), cached: 4096(4K)
另外有一个叫vmtouch的工具,可以提供更丰富的功能。
你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
博主的github的几个Rep也是C写得多,但是貌似现在很少有平民C工程能有人fork一下。
感觉C的代码在github不太流行
一些小代码,放在Github方便管理而已。
技术博,支持一下。
额,linux的菜鸟想问问,在vm中安装的ubuntu没有声音,即使装了vmware tools也不行,是啥情况?
用vmtouch比较多
收割机还有虚拟内存的?
dutor 童鞋好久木有更新了
客官您见笑了(^_^)
歪楼个:
我发现好多人喜欢用这种风格的代码:
int
main(int argc, char **args) {
….
}
这是从哪里起源的呢?
又见linux高人