Page cache hit ratio

From Siwiki

Jump to: navigation, search

We now have a method of collecting one of the most significant performance statistics for a file system in Solaris -- the cache hit rate in the file system page cache. By using DTrace with probes at the entry and exit to the file system, we can collect the logical io's into the file system and physical io's from the file system into the device I/O subsystem. These two statistics give us insight into how effective the file system cache is being, and if there might be grounds for adding physical memory in order to increase the amount of file system level caching.

#!/usr/sbin/dtrace -s

#pragma D option quiet

::fop_read:entry
/self->trace == 0 && (((vnode_t *)arg0)->v_vfsp)->vfs_vnodecovered/
{
        vp = (vnode_t*)arg0;
        vfs = (vfs_t *)vp->v_vfsp;
        mountvp = vfs->vfs_vnodecovered;
        uio = (uio_t*)arg1;
        self->path=stringof(mountvp->v_path);
        @rio[stringof(mountvp->v_path), "logical"] = count();
        @rbytes[stringof(mountvp->v_path), "logical"] = sum(uio->uio_resid);
        self->trace = 1;
}

::fop_read:entry
/self->trace == 0 && (((vnode_t *)arg0)->v_vfsp == `rootvfs)/
{
        vp = (vnode_t*)arg0;
        vfs = (vfs_t *)vp->v_vfsp;
        mountvp = vfs->vfs_vnodecovered;
        uio = (uio_t*)arg1;
        self->path="/";
        @rio[stringof("/"), "logical"] = count();
        @rbytes[stringof("/"), "logical"] = sum(uio->uio_resid);
        self->trace = 1;
}

::fop_read:return
/self->trace == 1/
{
        self->trace = 0;
}

io::bdev_strategy:start
/self->trace/
{
        @rio[self->path, "physical"] = count();
        @rbytes[self->path, "physical"] = sum(args[0]->b_bcount);
}


tick-5s
{
        trunc (@rio, 20);
        trunc (@rbytes, 20);
        printf("\033[H\033[2J");
        printf ("\nRead IOPS\n");
        printa ("%-60s %10s %10@d\n", @rio);
        printf ("\nRead Bandwidth\n");
        printa ("%-60s %10s %10@d\n", @rbytes);
        trunc (@rbytes);
        trunc (@rio);
}

Using this script, we probe the amount of logical bytes into the file system though the new Solaris 10 file system fop layer. We count the physical bytes using the io provider. Running the script, we can see the logical and physical for a file system which can be used to calculate the hit rate:

Read IOPS
/data1                                                          physical        287
/data1                                                           logical       2401

Read Bandwidth
/data1                                                          physical    2351104
/data1                                                           logical    5101240

The /data1 file system on this machine is doing 2401 logical iops, and 287 physical - i.e. a hit rate of 2401 / (2401 + 287) = 89%. It is also doing 5.1MB/s logical and 2.3MB/s physical. We can also do this at the file level:

#!/usr/sbin/dtrace -s

#pragma D option quiet

::fop_read:entry
/self->trace == 0 && (((vnode_t *)arg0)->v_path)/
{
        vp = (vnode_t*)arg0;
        uio = (uio_t*)arg1;
        self->path=stringof(vp->v_path);
        self->trace = 1;
        @rio[stringof(vp->v_path), "logical"] = count();
        @rbytes[stringof(vp->v_path), "logical"] = sum(uio->uio_resid);
}

::fop_read:return
/self->trace == 1/
{
        self->trace = 0;
}

io::bdev_strategy:start
/self->trace/
{
        @rio[self->path, "physical"] = count();
        @rbytes[self->path, "physical"] = sum(args[0]->b_bcount);
}

tick-5s
{
        trunc (@rio, 20);
        trunc (@rbytes, 20);
        printf("\033[H\033[2J");
        printf ("\nRead IOPS\n");
        printa ("%-60s %10s %10@d\n", @rio);
        printf ("\nRead Bandwidth\n");
        printa ("%-60s %10s %10@d\n", @rbytes);
        trunc (@rbytes);
        trunc (@rio);
}
Solaris Internals
Personal tools
The Books
The Ads