IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    mincore

    dutor发表于 2012-09-14 05:22:07
    love 0

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



沪ICP备19023445号-2号
友情链接