[collectd] swap.c problem on Solaris

Christophe Kalt collectd at klb.taranis.org
Fri Jun 9 19:01:10 CEST 2006


Hi,

On May 24, Florian Forster wrote:
| I tried to understand the Solaris swap mechanismn when implementing
| this, but I have to admit that it was a little too weird for me. So I
| ended up copying some code I found on the web.. The URL of the page
| should be in the code somewhere..
| 
| Some days ago I came accross a page that suggested using the `unix,
| vminfo' kstat to gather swap values.. Do you know if that's any better?

/usr/include/vm/anon.h says that using the kstats interface is
more efficient, but it's hard enough to understand (because of
ambiguous terms which aren't always used in the same manner)
that i ended up copying code from Solaris' swap(1M).

Rolling out today, i'll check results sometime next week.
-------------- next part --------------
diff -ru collectd-3.9.3/src/swap.c collectd-3.9.3+swap/src/swap.c
--- collectd-3.9.3/src/swap.c	2006-06-01 17:07:10.000000000 -0400
+++ collectd-3.9.3+swap/src/swap.c	2006-06-09 12:56:26.407514400 -0400
@@ -162,26 +162,27 @@
 		return;
 
 	/* 
-	 * Calculations learned by reading
-	 * http://www.itworld.com/Comp/2377/UIR980701perf/
+	 * Calculations from:
+	 * http://cvs.opensolaris.org/source/xref/on/usr/src/cmd/swap/swap.c
+         * Also see:
+	 * http://www.itworld.com/Comp/2377/UIR980701perf/ (outdated?)
+         * /usr/include/vm/anon.h
 	 *
-	 * swap_resv += ani_resv
-	 * swap_alloc += MAX(ani_resv, ani_max) - ani_free
-	 * swap_avail += MAX(ani_max - ani_resv, 0) + (availrmem - swapfs_minfree)
-	 * swap_free += ani_free + (availrmem - swapfs_minfree)
-	 *
-	 * To clear up the terminology a bit:
-	 * resv  = reserved (but not neccessarily used)
-	 * alloc = used     (neccessarily reserved)
-	 * avail = not reserved  (neccessarily free)
-	 * free  = not allocates (possibly reserved)
+         * In short, swap -s shows: allocated + reserved = used, available
+         *
+         * However, Solaris does not allow to allocated/reserved more than the
+         * available swap (physical memory + disk swap), so the pedant may
+         * prefer: allocated + unallocated = reserved, available
+         * 
+         * We map the above to: used + resv = n/a, free
+         *
+         * Does your brain hurt yet?  - Christophe Kalt
 	 */
-	swap_resv  = pagesize * ai.ani_resv;
-	swap_alloc = pagesize * (MAX(ai.ani_resv, ai.ani_max) - ai.ani_free);
-	swap_avail = pagesize * (MAX(ai.ani_max - ai.ani_resv, 0) + (availrmem - swapfs_minfree));
-	/* swap_free  = pagesize * (ai.ani_free + (availrmem - swapfs_minfree)); */
+        swap_alloc = pagesize * ( ai.ani_max - ai.ani_free );
+        swap_resv  = pagesize * ai.ani_resv - swap_alloc );
+        swap_avail = pagesize * ( ai.ani_max - ai.ani_resv );
 
-	swap_submit (swap_alloc, swap_avail, -1LL, swap_resv - swap_alloc);
+	swap_submit (swap_alloc, swap_avail, -1LL, swap_resv);
 /* #endif defined(KERNEL_SOLARIS) */
 
 #elif defined(HAVE_LIBSTATGRAB)


More information about the collectd mailing list