aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/top/machine.c
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2017-10-25 11:44:46 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2017-10-25 11:44:46 +0000
commit24e470ef9c4a7e6a92d3f872afbcca54b49b0258 (patch)
tree8a1e97b5c1c6687d6b40905f458c65d069dfe46c /usr.bin/top/machine.c
parent8d9b040dd4b289964bdcd94f5f7250526b770d7b (diff)
downloadsrc-24e470ef9c4a7e6a92d3f872afbcca54b49b0258.tar.gz
src-24e470ef9c4a7e6a92d3f872afbcca54b49b0258.zip
Limit top display of total swap size by the max swap size system can
handle. Keep both pagesize and the new swap_maxpages in the static variables to save sysctl calls. Submitted by: ota@j.email.ne.jp PR: 223149 MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=324972
Diffstat (limited to 'usr.bin/top/machine.c')
-rw-r--r--usr.bin/top/machine.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 6acfb38323ae..2d97d7f867f3 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1671,8 +1671,9 @@ static int
swapmode(int *retavail, int *retfree)
{
int n;
- int pagesize = getpagesize();
struct kvm_swap swapary[1];
+ static int pagesize = 0;
+ static u_long swap_maxpages = 0;
*retavail = 0;
*retfree = 0;
@@ -1683,6 +1684,16 @@ swapmode(int *retavail, int *retfree)
if (n < 0 || swapary[0].ksw_total == 0)
return (0);
+ if (pagesize == 0)
+ pagesize = getpagesize();
+ if (swap_maxpages == 0)
+ GETSYSCTL("vm.swap_maxpages", swap_maxpages);
+
+ /* ksw_total contains the total size of swap all devices which may
+ exceed the maximum swap size allocatable in the system */
+ if ( swapary[0].ksw_total > swap_maxpages )
+ swapary[0].ksw_total = swap_maxpages;
+
*retavail = CONVERT(swapary[0].ksw_total);
*retfree = CONVERT(swapary[0].ksw_total - swapary[0].ksw_used);