Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Apr 2018 20:16:58 +0300
From:      Andriy Gapon <avg@FreeBSD.org>
To:        Mark Millard <marklmi26-fbsd@yahoo.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Strange ARC/Swap/CPU on yesterday's -CURRENT
Message-ID:  <1b31e36e-e84b-cc63-1422-d1e0ce2f03c8@FreeBSD.org>
In-Reply-To: <E41D1122-9E08-41C7-B970-AC085CC5829D@yahoo.com>
References:  <FD75495D-AC03-4037-9C62-5A3AC588317C@yahoo.com> <alpine.BSF.2.21.1803111759150.1232@desktop> <20180317103915.081ca2dd@thor.intern.walstatt.dynvpn.de> <F48580A7-2C4C-4297-B083-B7EEBA1C8665@yahoo.com> <f48d7287-c707-369d-f2cb-6bf0ed1054c6@FreeBSD.org> <D9288EC1-624E-4977-BD97-557DA11A5D8E@yahoo.com> <a1d97a3c-247f-8eb0-6497-d0273773741c@FreeBSD.org> <E41D1122-9E08-41C7-B970-AC085CC5829D@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 01/04/2018 05:31, Mark Millard wrote:
> I have a hypothesis for part of what top is
> counting in the process/thread SWAP column
> that might not be what one would expect.
> 
> It appears to me that vnode-backed pages are
> being re-classfied sometimes for inactive
> processes, and this classification leads to
> top classifying the pages as not-resident
> but swapped (in that a "VN PAGER in" would
> be required, in systat -vmstat terms).

Not sure.
To me it seems that top just uses wrong statistics to calculate the value.

 /* swap usage */
 #define ki_swap(kip) \
   ((kip)->ki_swrss > (kip)->ki_rssize ? (kip)->ki_swrss - (kip)->ki_rssize : 0)

ki_rssize is the resident size of a process.
ki_swrss is resident set size before last swap.

Their difference is... exactly what?
I cannot even meaningfully describe this value.
But it is certainly _not_ the current swap utilization by the process.

Here is my attempt at obtaining a more reasonable approximation of the. process
swap use.  But it is still wildly inaccurate.

diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 2d97d7f867f36..361a1542e6e16 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -233,12 +233,13 @@ static int carc_enabled;
 static int pageshift;		/* log base 2 of the pagesize */

 /* define pagetok in terms of pageshift */
-
-#define pagetok(size) ((size) << pageshift)
+#define pagetok(size) ((size) << (pageshift - LOG1024))
+#define btopage(size) ((size) >> pageshift)

 /* swap usage */
 #define ki_swap(kip) \
-    ((kip)->ki_swrss > (kip)->ki_rssize ? (kip)->ki_swrss - (kip)->ki_rssize : 0)
+    (btopage((kip)->ki_size) > (kip)->ki_rssize ? \
+    btopage((kip)->ki_size) - (kip)->ki_rssize : 0)

 /* useful externals */
 long percentages(int cnt, int *out, long *new, long *old, long *diffs);
@@ -384,9 +385,6 @@ machine_init(struct statics *statics, char do_unames)
 		pagesize >>= 1;
 	}

-	/* we only need the amount of log(2)1024 for our conversion */
-	pageshift -= LOG1024;
-
 	/* fill in the statics information */
 	statics->procstate_names = procstatenames;
 	statics->cpustate_names = cpustatenames;
@@ -1374,7 +1372,7 @@ static int sorted_state[] = {
 } while (0)

 #define ORDERKEY_SWAP(a, b) do { \
-	int diff = (int)ki_swap(b) - (int)ki_swap(a); \
+	int diff = (long)ki_swap(b) - (long)ki_swap(a); \
 	if (diff != 0) \
 		return (diff > 0 ? 1 : -1); \
 } while (0)

-- 
Andriy Gapon



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1b31e36e-e84b-cc63-1422-d1e0ce2f03c8>