1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * swapinfo.d - print virtual memory info (swap).
1N/A * Written using DTrace (Solaris 10 3/05)
1N/A *
1N/A * Prints swap usage details for RAM and disk based swap.
1N/A * This script is UNDER CONSTRUCTION, check for newer versions.
1N/A *
1N/A * $Id: swapinfo.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: swapinfo.d (check for newer versions)
1N/A *
1N/A * FIELDS:
1N/A * RAM Total Total RAM installed
1N/A * RAM Unusable RAM consumed by the OBP and TSBs
1N/A * RAM Kernel Kernel resident in RAM (and usually locked)
1N/A * RAM Locked Locked memory pages from swap (Anon)
1N/A * RAM Used anon + exec + file pages used
1N/A * RAM Free free memory + page cache free
1N/A * Disk Total Total disk swap configured
1N/A * Disk Resv Disk swap allocated + reserved
1N/A * Disk Avail Disk swap available for reservation
1N/A * Swap Total Total Virtual Memory usable
1N/A * Swap Resv VM allocated + reserved
1N/A * Swap Avail VM available for reservation
1N/A * Swap MinFree VM kept free from reservations
1N/A *
1N/A * SEE ALSO: swapinfo - K9Toolkit, http://www.brendangregg.com/k9toolkit.html
1N/A * vmstat 1 2; swap -s; echo ::memstat | mdb -k
1N/A * RMCmem - The MemTool Package
1N/A * RICHPse - The SE Toolkit
1N/A * "Clearing up swap space confusion" Unix Insider, Adrian Cockcroft
1N/A * "Solaris Internals", Jim Mauro, Richard McDougall
1N/A * /usr/include/vm/anon.h, /usr/include/sys/systm.h
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * Author: Brendan Gregg [Sydney, Australia]
1N/A *
1N/A * 11-Jun-2005 Brendan Gregg Created this.
1N/A * 24-Apr-2006 " " Improved disk measurements; changed terms.
1N/A * 24-Apr-2006 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option bufsize=16k
1N/A
1N/Ainline int DEBUG = 0;
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A /* Debug stats */
1N/A this->ani_max = `k_anoninfo.ani_max;
1N/A this->ani_phys_resv = `k_anoninfo.ani_phys_resv;
1N/A this->ani_mem_resv = `k_anoninfo.ani_mem_resv;
1N/A this->ani_locked = `k_anoninfo.ani_locked_swap;
1N/A this->availrmem = `availrmem;
1N/A
1N/A /* RAM stats */
1N/A this->ram_total = `physinstalled;
1N/A this->unusable = `physinstalled - `physmem;
1N/A this->locked = `pages_locked;
1N/A this->ram_used = `availrmem - `freemem;
1N/A this->freemem = `freemem;
1N/A this->kernel = `physmem - `pages_locked - `availrmem;
1N/A
1N/A /* Disk stats */
1N/A this->disk_total = `k_anoninfo.ani_max;
1N/A this->disk_resv = `k_anoninfo.ani_phys_resv;
1N/A this->disk_avail = this->disk_total - this->disk_resv;
1N/A
1N/A /* Total Swap stats */
1N/A this->minfree = `swapfs_minfree;
1N/A this->reserve = `swapfs_reserve;
1N/A /* this is TOTAL_AVAILABLE_SWAP from /usr/include/vm/anon.h, */
1N/A this->swap_total = `k_anoninfo.ani_max +
1N/A (`availrmem - `swapfs_minfree > 0 ?
1N/A `availrmem - `swapfs_minfree : 0);
1N/A /* this is CURRENT_TOTAL_AVAILABLE_SWAP from /usr/include/vm/anon.h, */
1N/A this->swap_avail = `k_anoninfo.ani_max - `k_anoninfo.ani_phys_resv +
1N/A (`availrmem - `swapfs_minfree > 0 ?
1N/A `availrmem - `swapfs_minfree : 0);
1N/A this->swap_resv = this->swap_total - this->swap_avail;
1N/A
1N/A /* Convert to Mbytes */
1N/A this->ani_phys_resv *= `_pagesize; this->ani_phys_resv /= 1048576;
1N/A this->ani_mem_resv *= `_pagesize; this->ani_mem_resv /= 1048576;
1N/A this->ani_locked *= `_pagesize; this->ani_locked /= 1048576;
1N/A this->ani_max *= `_pagesize; this->ani_max /= 1048576;
1N/A this->availrmem *= `_pagesize; this->availrmem /= 1048576;
1N/A this->ram_total *= `_pagesize; this->ram_total /= 1048576;
1N/A this->unusable *= `_pagesize; this->unusable /= 1048576;
1N/A this->kernel *= `_pagesize; this->kernel /= 1048576;
1N/A this->locked *= `_pagesize; this->locked /= 1048576;
1N/A this->ram_used *= `_pagesize; this->ram_used /= 1048576;
1N/A this->freemem *= `_pagesize; this->freemem /= 1048576;
1N/A this->disk_total *= `_pagesize; this->disk_total /= 1048576;
1N/A this->disk_resv *= `_pagesize; this->disk_resv /= 1048576;
1N/A this->disk_avail *= `_pagesize; this->disk_avail /= 1048576;
1N/A this->swap_total *= `_pagesize; this->swap_total /= 1048576;
1N/A this->swap_avail *= `_pagesize; this->swap_avail /= 1048576;
1N/A this->swap_resv *= `_pagesize; this->swap_resv /= 1048576;
1N/A this->minfree *= `_pagesize; this->minfree /= 1048576;
1N/A this->reserve *= `_pagesize; this->reserve /= 1048576;
1N/A
1N/A /* Print debug */
1N/A DEBUG ? printf("DEBUG availrmem %5d MB\n", this->availrmem) : 1;
1N/A DEBUG ? printf("DEBUG freemem %5d MB\n", this->freemem) : 1;
1N/A DEBUG ? printf("DEBUG ani_max %5d MB\n", this->ani_max) : 1;
1N/A DEBUG ? printf("DEBUG ani_phys_re %5d MB\n", this->ani_phys_resv) : 1;
1N/A DEBUG ? printf("DEBUG ani_mem_re %5d MB\n", this->ani_mem_resv) : 1;
1N/A DEBUG ? printf("DEBUG ani_locked %5d MB\n", this->ani_locked) : 1;
1N/A DEBUG ? printf("DEBUG reserve %5d MB\n", this->reserve) : 1;
1N/A DEBUG ? printf("\n") : 1;
1N/A
1N/A /* Print report */
1N/A printf("RAM _______Total %5d MB\n", this->ram_total);
1N/A printf("RAM Unusable %5d MB\n", this->unusable);
1N/A printf("RAM Kernel %5d MB\n", this->kernel);
1N/A printf("RAM Locked %5d MB\n", this->locked);
1N/A printf("RAM Used %5d MB\n", this->ram_used);
1N/A printf("RAM Free %5d MB\n", this->freemem);
1N/A printf("\n");
1N/A printf("Disk _______Total %5d MB\n", this->disk_total);
1N/A printf("Disk Resv %5d MB\n", this->disk_resv);
1N/A printf("Disk Avail %5d MB\n", this->disk_avail);
1N/A printf("\n");
1N/A printf("Swap _______Total %5d MB\n", this->swap_total);
1N/A printf("Swap Resv %5d MB\n", this->swap_resv);
1N/A printf("Swap Avail %5d MB\n", this->swap_avail);
1N/A printf("Swap (Minfree) %5d MB\n", this->minfree);
1N/A
1N/A DEBUG ? printf("\nNow run other commands for confirmation.\n") : 1;
1N/A ! DEBUG ? exit(0) : 1;
1N/A}