Cache usage Check script under Linux system

Source: Internet
Author: User

The performance impact of the Linux cache Pagecache is critical, but how well we use it in the actual system, especially with regard to the utilization of each device.

From the following figure we can see very clearly:

We know that IO request is initiated by the VFS, after Pagecache cache, can not block the implementation of the IO device, then statistics this utilization is very simple. All we need to know is the proportion of Io that can't be blocked.

I wrote a systemtap script to solve this problem:

The code is as follows Copy Code


$ uname-r
2.6.18-164.el5

$ sudo rpm-i kernel-debuginfo-common-2.6.18-164.el5.x86_64.rpm
$ sudo rpm-i kernel-debuginfo-2.6.18-164.el5.x86_64.rpm

$ cat >PCMR.STP
Global Io_stat, Blk_stat

Global rd_cnt=2, wr_cnt=3

Probe Vfs.read.return {
if ($return >0 && devname!= "N/a") {
Io_stat[devname, 0] + + $return
Io_stat[devname, rd_cnt] + +;
}
}

Probe Ioblock.request {
Blk_stat[devname, rw] = = Size
Blk_stat[devname, rw+rd_cnt] + +;
}

Probe Vfs.write.return {
if ($return >0 && devname!= "N/a") {
Io_stat[devname, 1] + + $return
Io_stat[devname, wr_cnt] + +;
}
}


Global _IO,_BLK

Probe timer.ms (5000) {

foreach ([Devname, Action] in Io_stat)
{
_io[action] + = io_stat[devname, action];
_blk[action] + = blk_stat[devname, action]
}

if (_io[0] + _io[1]) {

printf ("n%-25s,%s%db/%d,%s%db/%d,%s%db/%d,%s%db/%d,%s%d%%nn",
CTime (gettimeofday_s ()),
"IO Read:", _io[0], _io[rd_cnt],
"IO Write:", _io[1],_io[wr_cnt],
"Blk Read:", _blk[0], _blk[rd_cnt],
"Blk Write:", _blk[1],_blk[wr_cnt],
"PCMR:", (_blk[0]+_blk[1]) */(_io[0] + _io[1))

        Delete _io
        Delete _blk
   
   /* Print header */
    printf ("%8s%2s%19s%19s%5sn",
           "DEVICE", "T", "IO", "BLK", "PCMR")
 }

/* Print Top ten I/O
foreach ([Devname, Action] in Io_stat-limit 10)
if (Action < rd_cnt)
printf ("%8s%2s%11db/%6d%11db/%6d%4d%%n",
Devname, action? " W ":" R ",
Io_stat[devname, Action],io_stat[devname, action+rd_cnt],
Blk_stat[devname, Action],blk_stat[devname, action+rd_cnt],
(Blk_stat[devname, Action] *)/io_stat[devname, action]
)

/* Clear Data */
Delete Io_stat
Delete Blk_stat
}

Probe begin
{
println ("::");
}

Ctrl+d

Arguments let's explain the following:
IO read:vfs level See IO Read/count
Io write:vfs level see iOS Write/number
Blk read: block level see IO Read/Count
Blk write: Io written at block level see Number of times
Pcmr:pagecache Miss Rate =100 * Blk/io, because file reads and writes are in page, it may >100%
The first line is a summary statistic, printed every 5 seconds.
Summary: PCMR is as small as possible, indicating high cache utilization.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.