[20191125]編譯vmtouch.txt

lfree發表於2019-11-25

[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.下載:

--//下載過程略.如果你能直接聯網很簡單:
$ git clone
$ 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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章