Re: Strange ARC/Swap/CPU on yesterday's -CURRENT

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Wed, 4 Apr 2018 20:16:58 +0300
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
_at__at_ -233,12 +233,13 _at__at_ 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);
_at__at_ -384,9 +385,6 _at__at_ 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;
_at__at_ -1374,7 +1372,7 _at__at_ 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
Received on Wed Apr 04 2018 - 15:23:33 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:15 UTC