经常需要查看一个文件有多少页面驻留在物理内存中,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的工具,可以提供更丰富的功能。

Tags: .
你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
Home

RFC: Request For Comments. Orz..

You must be logged in to post a comment.