2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1980, 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 2017, 2020 Yoshihiro Ota
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 static const char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95";
42 * swapinfo - based on a program of the same name by Kevin Lahey
45 #include <sys/param.h>
46 #include <sys/ioctl.h>
67 return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0));
82 * The meat of all the swap stuff is stolen from pstat(8)'s
83 * swapmode(), which is based on a program called swapinfo written by
84 * Kevin Lahey <kml@rokkaku.atl.ga.us>.
89 static struct kvm_swap kvmsw[NSWAP];
90 static int kvnsw, okvnsw;
100 if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
101 error("systat: kvm_getswapinfo failed");
104 pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */;
117 if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
118 error("systat: kvm_getswapinfo failed");
122 struct devinfo *tmp_dinfo;
124 tmp_dinfo = last_dev.dinfo;
125 last_dev.dinfo = cur_dev.dinfo;
126 cur_dev.dinfo = tmp_dinfo;
128 last_dev.snap_time = cur_dev.snap_time;
139 dslabel(12, 0, LINES - DISKHIGHT - 1);
142 mvwprintw(wnd, 0, 0, "(swap not configured)");
146 mvwprintw(wnd, 0, 0, "%*s%5s %5s %s",
147 -pathlen, "Device/Path", "Size", "Used",
148 "|0% /10 /20 /30 /40 / 60\\ 70\\ 80\\ 90\\ 100|");
160 dsshow(12, 0, LINES - DISKHIGHT - 1, &cur_dev, &last_dev);
165 for (i = (kvnsw == 1 ? 0 : kvnsw); i >= 0; i--) {
166 name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname;
167 mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name);
169 sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0);
170 sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used,
173 if (kvmsw[i].ksw_used > 0) {
174 count = 50 * kvmsw[i].ksw_used / kvmsw[i].ksw_total;
175 sysputXs(wnd, i + 1, pathlen + 5 + 1 + 5 + 1, count);
179 count = kvnsw == 1 ? 2 : 3;
180 proclabel(kvnsw + count);
181 procshow(kvnsw + count, LINES - 5 - kvnsw + 3 - DISKHIGHT + 1,
182 kvmsw[kvnsw].ksw_total);