SUMMARY: SunOS 4.1.3 memory problems??

From: Sven Ole Skrivervik (svenole@sdata.no)
Date: Wed Apr 21 1993 - 10:53:11 CDT


Thanks for all the answers on this one.

The information that I feel is critical to know here is that
vmstat is kind of lying on free memory here. All free memory
is used as file cache. These pages are still in the kernel cache list
and are not "freed" in the sence that vmstat would report the memory
as available after the copy is done. However if a process needs
them it'll get them and there should not be any paging/swapping
problems after such a copy. If this is so the reason is probably
because of sudden, large demands for memory.

I've done some tests with a program that allocates a certain amount
of memory and exits. Running this program after the copy will make
the memory pages free in the sence that vmstat will report the memory
as available.

Other solutions like using the gnu cp program, umounting the filesystem
and so on didn't quite solve my "problem", but thanks anyhow.

Thanks to:

strombrg@hydra.acs.uci.edu
stern@sunne.East.Sun.COM
nadkarni@Solbourne.COM
mharris@jpmorgan.com
jim@pi-chan.ucsb.edu

- Sven Ole

The malloc program:

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/lock.h>

#ifdef DGUX
#include <sys/mman.h>
#endif

extern char *malloc();
extern int plock();
extern unsigned sleep();
extern void perror();
extern int errno;
long size,i;
char *mem;
int status, seconds;

extern char *optarg; /* parameters for getopt */
extern int optind;
char **ppeker; /* parameters for strtol */
char *peker;
int base = 0;

long mbytes; /* Number of bytes to malloc */
long wbytes; /* Number of bytes to write */
long fbytes; /* Number of bytes to fix */

main (argc, argv)
int argc;
char **argv;
{

     int c;
     int errflg;
     char *marg = 0, *warg = 0, *farg = 0;
     int mflg = 0, wflg = 0, fflg = 0;
     long apar;
     errflg = 0;
     ppeker = &peker;
     if (argc < 2) errflg++;
     while ((c = getopt(argc, argv, "m:w:f:")) != -1)
          switch (c) {
          case 'm':
               printf(" m option : \n");
               mflg++;
               marg = optarg;
               break;
          case 'w':
               printf(" w option : \n");
               mflg++; wflg++;
               marg = optarg;
               break;
          case 'f':
               printf(" f option : \n");
               mflg++; wflg++; fflg++;
               marg = optarg;
               break;
          case '?':
               errflg++;
          }
     if (errflg) {
        (void)fprintf(stderr,"usage: malloc -<option> <size> \n");
        (void)fprintf(stderr," <option> m: malloc only \n");
        (void)fprintf(stderr," <option> w: malloc and write \n");
        (void)fprintf(stderr," <option> f: malloc, write and fix. \n");
        exit (2);
     }
     if (mflg) {
          apar = strtol(marg, ppeker, base);
          mbytes = apar;
          printf(" Memory buffer.");
          c = **ppeker;
          switch (c) {
          case 'k': case 'K':
               mbytes = apar * 1024;
               printf(" %ld Kbytes. ",apar);
               break;
          case 'm': case 'M':
               mbytes = apar * 1024 *1024;
               printf(" %ld Mbytes. ",apar);
               break;
          }
          printf(" Total %ld bytes \n",mbytes);
     }
     wbytes = mbytes;
     fbytes = mbytes;
     if (mflg) {
          printf (" Start malloc.\n");
          fflush(stdout);
          mem = malloc(mbytes);
          if (mem == NULL) {
               printf("\nMalloc failed, errno : %d\n",errno);
               perror("");
               exit(errno);
          }
     }
     if (wflg) {
          printf (" Start writing.\n");
          fflush(stdout);
          for (i=0;i<wbytes-512;i+=512) {
               mem[i] = i;
          }
     }
     if (fflg) {
          printf (" Start locking.");
          fflush(stdout);

#ifdef DGUX
          status = mlockall(MCL_CURRENT|MCL_FUTURE);
          printf (" (mlock) \n");
#else
          status = plock(DATLOCK);
          printf (" (plock) \n");
#endif
          if (status != 0) {
            printf("\nPlock failed, status: %d, errno: %d\n",status,errno);
            perror("");
            exit (status);
     }
     }
     printf ("\n Ready.\n ");
/* seconds = 1000000;
     printf("\nStop the program by using <Ctrl C> or <kill> command\n");
     sleep(seconds);
*/
}



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:07:45 CDT