ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [20191125]编译vmtouch.txt

[20191125]编译vmtouch.txt

原创 Linux操作系统 作者:lfree 时间:2019-11-25 10:48:02 0 删除 编辑

[20191125]编译vmtouch.txt

vmtouch is a tool for learning about and controlling the file system cache of unix and unix-like systems.

vmtouch – the Virtual Memory Toucher

Portable file system cache diagnostics and control vmtouch is a tool for learning about and controlling the file system
cache of unix and unix-like systems. It is BSD licensed so you can basically do whatever you want with it.

从介绍可以看出vmtouch是一个管理和控制Unix和类Unix文件系统缓存的工具。

vmtouch的主要功能如下:

查看一个文件(或者目录)哪些部分在内存中;
把文件调入内存;
把文件清除出内存;
把文件锁住在内存中而不被换出到磁盘上;

--//个人感觉linux发布版本应该提供一个类似的工具.至少是查看的工具.
--//关于pagecache内容,可以参考:http://blog.chinaunix.net/uid-20662820-id-3480240.html,我更愿意叫文件系统缓存.
--//我以前使用nocache查看,参考链接:http://blog.itpub.net/267265/viewspace-2147398/=>[20171117]nocache的编译.txt

1.下载:
https://hoytech.com/vmtouch/
--//下载过程略.如果你能直接联网很简单:
$ git clone https://github.com/hoytech/vmtouch.git
$ cd vmtouch
$ make
$ sudo make install

2.解压:
# unzip vmtouch-master.zip  -d /tmp/
Archive:  vmtouch-master.zip
35085ac628bf574d16463ee8ef4806f26a6e8baa
   creating: /tmp/vmtouch-master/
  inflating: /tmp/vmtouch-master/.gitignore
  inflating: /tmp/vmtouch-master/.logp.conf
  inflating: /tmp/vmtouch-master/.travis.yml
  inflating: /tmp/vmtouch-master/CHANGES
  inflating: /tmp/vmtouch-master/LICENSE
  inflating: /tmp/vmtouch-master/Makefile
  inflating: /tmp/vmtouch-master/README.md
  inflating: /tmp/vmtouch-master/TODO
  inflating: /tmp/vmtouch-master/TUNING.md
   creating: /tmp/vmtouch-master/debian/
  inflating: /tmp/vmtouch-master/debian/changelog
 extracting: /tmp/vmtouch-master/debian/compat
  inflating: /tmp/vmtouch-master/debian/control
  inflating: /tmp/vmtouch-master/debian/copyright
 extracting: /tmp/vmtouch-master/debian/gbp.conf
  inflating: /tmp/vmtouch-master/debian/rules
   creating: /tmp/vmtouch-master/debian/source/
 extracting: /tmp/vmtouch-master/debian/source/format
  inflating: /tmp/vmtouch-master/debian/vmtouch.default
  inflating: /tmp/vmtouch-master/debian/vmtouch.docs
  inflating: /tmp/vmtouch-master/debian/vmtouch.init
 extracting: /tmp/vmtouch-master/debian/vmtouch.manpages
   creating: /tmp/vmtouch-master/scripts/
  inflating: /tmp/vmtouch-master/scripts/render-man-page.sh
  inflating: /tmp/vmtouch-master/scripts/watch-vmtouch.pl
   creating: /tmp/vmtouch-master/snap/
  inflating: /tmp/vmtouch-master/snap/snapcraft.yaml
  inflating: /tmp/vmtouch-master/vmtouch.c
  inflating: /tmp/vmtouch-master/vmtouch.pod

# cd /tmp/vmtouch-master
# make
cc -Wall -O2 -g -std=c99  -o vmtouch vmtouch.c
vmtouch.c: In function 'register_signals_for_pidfile':
vmtouch.c:898: warning: missing braces around initializer
vmtouch.c:898: warning: (near initialization for 'sa.__sigaction_handler')
pod2man --section 8 --center "System Manager's Manual" --release " " vmtouch.pod > vmtouch.8

--//先看看安装到哪里?
# make -n install
mkdir -p /usr/local/bin /usr/local/share/man/man8
install -m 0755 vmtouch /usr/local/bin/vmtouch
install -m 0644 vmtouch.8 /usr/local/share/man/man8/vmtouch.8

--//安装就2个文件,vmtouch和 vmtouch.8

# make install
mkdir -p /usr/local/bin /usr/local/share/man/man8
install -m 0755 vmtouch /usr/local/bin/vmtouch
install -m 0644 vmtouch.8 /usr/local/share/man/man8/vmtouch.8

3.简单测试:
$ vmtouch /mnt/ramdisk/book/
           Files: 20
     Directories: 1
  Resident Pages: 1427801/1567493  5G/5G  91.1%
         Elapsed: 0.34285 seconds
--//加入-v可以显示各个文件的情况.
--//BTW:实际上我这个目录的文件建立ramdisk盘上的,缓存应该是100.为什么91.1是因为:
# find . -name "*.dbf" -print0 | xargs -0 -IQ cachestats Q
./T01.dbf                                pages in cache: 10242/10242 (100.0%)  [filesize=40968.0K, pagesize=4K]
./tea01.dbf                              pages in cache: 1538/1538 (100.0%)  [filesize=6152.0K, pagesize=4K]
./temp01.dbf                             pages in cache: 4440/38402 (11.6%)  [filesize=153608.0K, pagesize=4K]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./undotbs03.dbf                          pages in cache: 4098/4098 (100.0%)  [filesize=16392.0K, pagesize=4K]
./undotbs02.dbf                          pages in cache: 4098/4098 (100.0%)  [filesize=16392.0K, pagesize=4K]
./users01.dbf                            pages in cache: 32770/32770 (100.0%)  [filesize=131080.0K, pagesize=4K]
./undotbs01.dbf                          pages in cache: 221442/221442 (100.0%)  [filesize=885768.0K, pagesize=4K]
./system01.dbf                           pages in cache: 197122/197122 (100.0%)  [filesize=788488.0K, pagesize=4K]
./sysaux01.dbf                           pages in cache: 755202/755202 (100.0%)  [filesize=3020808.0K, pagesize=4K]
./example01.dbf                          pages in cache: 88642/88642 (100.0%)  [filesize=354568.0K, pagesize=4K]
--//是因为临时文件是稀疏文件,没有展开的原因.

# vmtouch -e  users01.dbf
           Files: 1
     Directories: 0
   Evicted Pages: 32770 (128M)
         Elapsed: 0.015256 seconds

# vmtouch   users01.dbf
           Files: 1
     Directories: 0
  Resident Pages: 32770/32770  128M/128M  100%
         Elapsed: 0.008341 seconds
--//可以发现-e无用.

--//使用vmtouch的好处是可以看整个目录,cachestats不行,给1个1个文件看.要结合find+xargs才行.
--//换一台机器测试:

# cachestats /u01/app/oracle/oradata/peis/system01.dbf
/u01/app/oracle/oradata/peis/system01.dbf pages in cache: 72/1013762 (0.0%)  [filesize=4055048.0K, pagesize=4K]

# vmtouch  /u01/app/oracle/oradata/peis/system01.dbf
           Files: 1
     Directories: 0
  Resident Pages: 72/1013762  288K/3G  0.0071%
         Elapsed: 0.014663 seconds

--//72*4 = 288,1013762*4 = 4055048
--//vmtouch看到文件大小取值不合理,单位G删除小数点的后面位数.实际上是4055048/1024/1024 = 3.86G.
--//功能许多,慢慢看文档.

# vmtouch   /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
  Resident Pages: 0/1282  0/5M  0%
         Elapsed: 9.5e-05 seconds

--//-t  Touch virtual memory pages. Reads a byte from each page of the file. If the page is not resident in memory,
--//a page fault will be generated and the page will be read from disk into the file system's memory cache.
--//-t 参数可以加入文件系统缓存,-e 参数可以反转.

--//加载
# vmtouch -t  /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
   Touched Pages: 1282 (5M)
         Elapsed: 0.081837 seconds

--//查看,全部在缓存.
# vmtouch   /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
  Resident Pages: 1282/1282  5M/5M  100%
         Elapsed: 0.000196 seconds

--//剔除出缓存.
# vmtouch  -ve /u01/app/oracle/oradata/peis/users01.dbf
Evicting /u01/app/oracle/oradata/peis/users01.dbf

           Files: 1
     Directories: 0
   Evicted Pages: 1282 (5M)
         Elapsed: 4.9e-05 seconds

# vmtouch   /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
  Resident Pages: 0/1282  0/5M  0%
         Elapsed: 9.1e-05 seconds

--//你甚至可以lock文件或者目录在内存里面,测试:
# vmtouch  -l  /u01/app/oracle/oradata/peis/users01.dbf
LOCKED 1282 pages (5M)
^Z
[1]+  Stopped                 vmtouch -l /u01/app/oracle/oradata/peis/users01.dbf

# bg
[1]+ vmtouch -l /u01/app/oracle/oradata/peis/users01.dbf &

# vmtouch -e   /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
   Evicted Pages: 1282 (5M)
         Elapsed: 0.000212 seconds

# vmtouch    /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
  Resident Pages: 1282/1282  5M/5M  100%
         Elapsed: 0.000197 seconds
--//马上加载到缓存.

# ps -ef | grep vmtouc[h]
root      1346   985  0 10:20 pts/0    00:00:00 vmtouch -l /u01/app/oracle/oradata/peis/users01.dbf

--//必须kill掉才行.
# kill -9 1346

# vmtouch   -e /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
   Evicted Pages: 1282 (5M)
         Elapsed: 0.000746 seconds

# vmtouch    /u01/app/oracle/oradata/peis/users01.dbf
           Files: 1
     Directories: 0
  Resident Pages: 0/1282  0/5M  0%
         Elapsed: 9.4e-05 seconds

--//我个人感觉发行版本应该一个工具查看各个文件缓存的情况.也许许多linux发布版觉得这个工具不重要吧

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2665523/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    2548
  • 访问量
    6335977