[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-solaris
Subject:    [kde-solaris] Re: kdebase/ksysguard/ksysguardd/* various patches
From:       Christopher Layne <clayne () anodized ! com>
Date:       2004-10-20 7:59:22
Message-ID: 20041020075922.GB15352 () ns1 ! anodized ! com
[Download RAW message or body]

Updated patch just for kdebase/ksysguard/ksysguardd/Solaris/Memory.c:

The other ksysguardd patches are still valid.

1. Removed malloc/free calls for "struct anoninfo am_swap" entirely. It's a
one time use structure just to grab long ints for swap stats. At most
24 bytes - hardly a contender for malloc here. The difference between this
and the kcontrol/info patch is that I have defined the struct as a static in
file scope. It's contents are regularly overwritten and alloc/free for a
placeholder struct in a cyclic function (updateMemory()) is a waste.

-cl

On Tue, Oct 19, 2004 at 03:16:14PM -0700, Christopher Layne wrote:
> Here are patches to fix:
> 
> 1. Change swap memory statistics reporting entirely from using SC_LIST
> with swapctl() to SC_AINFO. This actually gives us accurate aggregate swap
> information that matches with "swap -s".  The older method did not.
> 
> 2. _FILE_OFFSET_BITS=64 continually breaking builds on Solaris machines w/
> 32-bit arch's due to <sys/swap.h> and  <sys/procfs.h> not allowing it under
> largefile compilation environment (i.e. 32bit arch w/ 64-bit file support).


["Memory.c.patch" (text/plain)]

Index: kdebase/ksysguard/ksysguardd/Solaris/Memory.c
===================================================================
RCS file: /home/kde/kdebase/ksysguard/ksysguardd/Solaris/Memory.c,v
retrieving revision 1.5
diff -u -3 -p -r1.5 Memory.c
--- kdebase/ksysguard/ksysguardd/Solaris/Memory.c	24 Feb 2004 11:30:18 -0000	1.5
+++ kdebase/ksysguard/ksysguardd/Solaris/Memory.c	20 Oct 2004 07:46:17 -0000
@@ -23,11 +23,20 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/stat.h>
-#include <sys/swap.h>
 
 #include "config.h"
 
+/* Stop <sys/swap.h> from crapping out on 32-bit architectures. */
+
+#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
+# undef _FILE_OFFSET_BITS
+# define _FILE_OFFSET_BITS 32
+#endif
+
+#include <sys/stat.h>
+#include <sys/swap.h>
+#include <vm/anon.h>
+
 #ifdef HAVE_KSTAT
 #include <kstat.h>
 #endif
@@ -41,6 +50,7 @@ static t_memsize totalmem = (t_memsize) 
 static t_memsize freemem = (t_memsize) 0;
 static long totalswap = 0L;
 static long freeswap = 0L;
+static struct anoninfo am_swap;
 
 /*
  *  this is borrowed from top's m_sunos5 module
@@ -103,56 +113,32 @@ void exitMemory( void ) {
 
 int updateMemory( void ) {
 
-	struct swaptable	*swt;
-	struct swapent		*ste;
-	int			i;
-	int			ndevs;
 	long			swaptotal;
 	long			swapfree;
-	char			dummy[128];
+	long			swapused;
 #ifdef HAVE_KSTAT
 	kstat_ctl_t		*kctl;
 	kstat_t			*ksp;
 	kstat_named_t		*kdata;
 #endif /* HAVE_KSTAT */
-
-	if( (ndevs = swapctl( SC_GETNSWP, NULL )) < 1 )
-		return( 0 );
-	if( (swt = (struct swaptable *) malloc(
-			sizeof( int )
-			+ ndevs * sizeof( struct swapent ))) == NULL )
-		return( 0 );
+	swaptotal = swapused = swapfree = 0L;
 
 	/*
-	 *  fill in the required fields and retrieve the info thru swapctl()
+	 *  Retrieve overall swap information from anonymous memory structure -
+	 *  which is the same way "swap -s" retrieves it's statistics.
+	 *
+	 *  swapctl(SC_LIST, void *arg) does not return what we are looking for.
 	 */
-	swt->swt_n = ndevs;
-	ste = &(swt->swt_ent[0]);
-	for( i = 0; i < ndevs; i++ ) {
-		/*
-		 *  since we'renot interested in the path(s),
-		 *  we'll re-use the same buffer
-		 */
-		ste->ste_path = dummy;
-		ste++;
-	}
-	swapctl( SC_LIST, swt );
 
-	swaptotal = swapfree = 0L;
+	if (swapctl(SC_AINFO, &am_swap) == -1)
+		return(0);
 
-	ste = &(swt->swt_ent[0]);
-	for( i = 0; i < ndevs; i++ ) {
-		if( (! (ste->ste_flags & ST_INDEL))
-				&& (! (ste->ste_flags & ST_DOINGDEL)) ) {
-			swaptotal += ste->ste_pages;
-			swapfree += ste->ste_free;
-		}
-		ste++;
-	}
-	free( swt );
+	swaptotal = am_swap.ani_max;
+	swapused = am_swap.ani_resv;
+	swapfree = swaptotal - swapused;
 
-	totalswap = pagetok( swaptotal );
-	freeswap = pagetok( swapfree );
+	totalswap = pagetok(swaptotal);
+	freeswap = pagetok(swapfree);
 
 #ifdef HAVE_KSTAT
 	/*


___________________________________________________
This message is from the kde-solaris mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde-solaris.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic