svn commit: r324972 - head/usr.bin/top
Konstantin Belousov
kib at FreeBSD.org
Wed Oct 25 11:44:48 UTC 2017
Author: kib
Date: Wed Oct 25 11:44:46 2017
New Revision: 324972
URL: https://svnweb.freebsd.org/changeset/base/324972
Log:
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 at j.email.ne.jp
PR: 223149
MFC after: 2 weeks
Modified:
head/usr.bin/top/machine.c
Modified: head/usr.bin/top/machine.c
==============================================================================
--- head/usr.bin/top/machine.c Wed Oct 25 09:12:22 2017 (r324971)
+++ head/usr.bin/top/machine.c Wed Oct 25 11:44:46 2017 (r324972)
@@ -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;
@@ -1682,6 +1683,16 @@ swapmode(int *retavail, int *retfree)
n = kvm_getswapinfo(kd, swapary, 1, 0);
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);
More information about the svn-src-head
mailing list