]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Mem/swapinfo.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Mem / swapinfo.d
1 #!/usr/sbin/dtrace -s
2 /*
3  * swapinfo.d - print virtual memory info (swap).
4  *              Written using DTrace (Solaris 10 3/05)
5  *
6  * Prints swap usage details for RAM and disk based swap.
7  * This script is UNDER CONSTRUCTION, check for newer versions.
8  *
9  * $Id: swapinfo.d 3 2007-08-01 10:50:08Z brendan $
10  *
11  * USAGE:       swapinfo.d      (check for newer versions)
12  *
13  * FIELDS:
14  *              RAM Total       Total RAM installed
15  *              RAM Unusable    RAM consumed by the OBP and TSBs
16  *              RAM Kernel      Kernel resident in RAM (and usually locked)
17  *              RAM Locked      Locked memory pages from swap (Anon)
18  *              RAM Used        anon + exec + file pages used
19  *              RAM Free        free memory + page cache free
20  *              Disk Total      Total disk swap configured
21  *              Disk Resv       Disk swap allocated + reserved
22  *              Disk Avail      Disk swap available for reservation
23  *              Swap Total      Total Virtual Memory usable
24  *              Swap Resv       VM allocated + reserved
25  *              Swap Avail      VM available for reservation
26  *              Swap MinFree    VM kept free from reservations
27  *
28  * SEE ALSO: swapinfo - K9Toolkit, http://www.brendangregg.com/k9toolkit.html
29  *           vmstat 1 2; swap -s; echo ::memstat | mdb -k
30  *           RMCmem - The MemTool Package
31  *           RICHPse - The SE Toolkit
32  *           "Clearing up swap space confusion" Unix Insider, Adrian Cockcroft
33  *           "Solaris Internals", Jim Mauro, Richard McDougall
34  *           /usr/include/vm/anon.h, /usr/include/sys/systm.h
35  *
36  * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
37  *
38  * CDDL HEADER START
39  *
40  *  The contents of this file are subject to the terms of the
41  *  Common Development and Distribution License, Version 1.0 only
42  *  (the "License").  You may not use this file except in compliance
43  *  with the License.
44  *
45  *  You can obtain a copy of the license at Docs/cddl1.txt
46  *  or http://www.opensolaris.org/os/licensing.
47  *  See the License for the specific language governing permissions
48  *  and limitations under the License.
49  *
50  * CDDL HEADER END
51  *
52  * Author: Brendan Gregg  [Sydney, Australia]
53  *
54  * 11-Jun-2005  Brendan Gregg   Created this.
55  * 24-Apr-2006     "      "     Improved disk measurements; changed terms.
56  * 24-Apr-2006     "      "     Last update.
57  */
58
59 #pragma D option quiet
60 #pragma D option bufsize=16k
61
62 inline int DEBUG = 0;
63
64 dtrace:::BEGIN
65 {
66         /* Debug stats */
67         this->ani_max = `k_anoninfo.ani_max;
68         this->ani_phys_resv = `k_anoninfo.ani_phys_resv;
69         this->ani_mem_resv = `k_anoninfo.ani_mem_resv;
70         this->ani_locked = `k_anoninfo.ani_locked_swap;
71         this->availrmem = `availrmem;
72
73         /* RAM stats */
74         this->ram_total = `physinstalled;
75         this->unusable  = `physinstalled - `physmem;
76         this->locked    = `pages_locked;
77         this->ram_used  = `availrmem - `freemem;
78         this->freemem   = `freemem;
79         this->kernel    = `physmem - `pages_locked - `availrmem;
80
81         /* Disk stats */
82         this->disk_total = `k_anoninfo.ani_max;
83         this->disk_resv = `k_anoninfo.ani_phys_resv;
84         this->disk_avail = this->disk_total - this->disk_resv;
85
86         /* Total Swap stats */
87         this->minfree = `swapfs_minfree;
88         this->reserve = `swapfs_reserve;
89         /* this is TOTAL_AVAILABLE_SWAP from /usr/include/vm/anon.h, */
90         this->swap_total = `k_anoninfo.ani_max +
91             (`availrmem - `swapfs_minfree > 0 ?
92             `availrmem - `swapfs_minfree : 0);
93         /* this is CURRENT_TOTAL_AVAILABLE_SWAP from /usr/include/vm/anon.h, */
94         this->swap_avail = `k_anoninfo.ani_max - `k_anoninfo.ani_phys_resv +
95             (`availrmem - `swapfs_minfree > 0 ?
96             `availrmem - `swapfs_minfree : 0);
97         this->swap_resv = this->swap_total - this->swap_avail;
98
99         /* Convert to Mbytes */
100         this->ani_phys_resv *= `_pagesize;  this->ani_phys_resv /= 1048576;
101         this->ani_mem_resv *= `_pagesize;  this->ani_mem_resv /= 1048576;
102         this->ani_locked *= `_pagesize;  this->ani_locked /= 1048576;
103         this->ani_max   *= `_pagesize;  this->ani_max   /= 1048576;
104         this->availrmem *= `_pagesize;  this->availrmem /= 1048576;
105         this->ram_total *= `_pagesize;  this->ram_total /= 1048576;
106         this->unusable  *= `_pagesize;  this->unusable  /= 1048576;
107         this->kernel    *= `_pagesize;  this->kernel    /= 1048576;
108         this->locked    *= `_pagesize;  this->locked    /= 1048576;
109         this->ram_used  *= `_pagesize;  this->ram_used  /= 1048576;
110         this->freemem   *= `_pagesize;  this->freemem   /= 1048576;
111         this->disk_total *= `_pagesize; this->disk_total /= 1048576;
112         this->disk_resv *= `_pagesize;  this->disk_resv /= 1048576;
113         this->disk_avail *= `_pagesize;  this->disk_avail /= 1048576;
114         this->swap_total *= `_pagesize; this->swap_total /= 1048576;
115         this->swap_avail *= `_pagesize;  this->swap_avail /= 1048576;
116         this->swap_resv *= `_pagesize;  this->swap_resv /= 1048576;
117         this->minfree   *= `_pagesize;  this->minfree   /= 1048576;
118         this->reserve   *= `_pagesize;  this->reserve   /= 1048576;
119
120         /* Print debug */
121         DEBUG ? printf("DEBUG   availrmem %5d MB\n", this->availrmem) : 1;
122         DEBUG ? printf("DEBUG     freemem %5d MB\n", this->freemem) : 1;
123         DEBUG ? printf("DEBUG     ani_max %5d MB\n", this->ani_max) : 1;
124         DEBUG ? printf("DEBUG ani_phys_re %5d MB\n", this->ani_phys_resv) : 1;
125         DEBUG ? printf("DEBUG  ani_mem_re %5d MB\n", this->ani_mem_resv) : 1;
126         DEBUG ? printf("DEBUG  ani_locked %5d MB\n", this->ani_locked) : 1;
127         DEBUG ? printf("DEBUG     reserve %5d MB\n", this->reserve) : 1;
128         DEBUG ? printf("\n") : 1;
129
130         /* Print report */
131         printf("RAM  _______Total %5d MB\n", this->ram_total);
132         printf("RAM      Unusable %5d MB\n", this->unusable);
133         printf("RAM        Kernel %5d MB\n", this->kernel);
134         printf("RAM        Locked %5d MB\n", this->locked);
135         printf("RAM          Used %5d MB\n", this->ram_used);
136         printf("RAM          Free %5d MB\n", this->freemem);
137         printf("\n");
138         printf("Disk _______Total %5d MB\n", this->disk_total);
139         printf("Disk         Resv %5d MB\n", this->disk_resv);
140         printf("Disk        Avail %5d MB\n", this->disk_avail);
141         printf("\n");
142         printf("Swap _______Total %5d MB\n", this->swap_total);
143         printf("Swap         Resv %5d MB\n", this->swap_resv);
144         printf("Swap        Avail %5d MB\n", this->swap_avail);
145         printf("Swap    (Minfree) %5d MB\n", this->minfree);
146
147         DEBUG ? printf("\nNow run other commands for confirmation.\n") : 1;
148         ! DEBUG ? exit(0) : 1;
149 }