SUMMARY: How to determine physical memory?

From: Paul Ferroni,TCC (cpferron@cs.hh.ab.com)
Date: Wed Oct 27 1993 - 15:13:12 CDT


 
I posted the following a week ago:

> Does anyone have a quick program that returns the amount of physical RAM
>on a SparcStation? I know you can get it from the messages log file, but
>we rotate it weekly into the bitbucket, and the information isn't there if
>the machine has been up a long time.

and rec'd several responses. Thanks to everyone who responded. Especially
to Ingolf and Richard for both the C programs (at end of this posting) that return
the answer directly.

Thanks again for the helpful info.

Paul Ferroni
Allen-Bradley, Inc
Highland Hts, OH

Below is a summary of various methods:

-------------------
Per aad@dvorak.amd.com (Anthony A. Datri),
    "Anna Pluzhnikov" <besp@midway.uchicago.edu>,
    carl@oversteer.library.uwa.edu.au (Carl Brewer),
and guy@auspex.com (Guy Harris):

> Use a program called sysinfo which can be FTP'ed from "usc.edu", in the
> directory "pub/sysinfo"
   
   You need to have read permissions on /dev/kmem unless you're root...

-------------------
Per doc <josh@pogo.cqs.washington.edu>,
and edavid@clipper.ens.fr (Erwan David) :

> grep for mem from dmesg output.

    This is OK if your dmesg buffer isn't overrun with other messages
    (which mine are, since le0 is complaining of giant packets
    occassionally -- another problem for another time...)

-------------------
Per jth@ll.mit.edu (Joe Healey):

>
> BSD derived systems, like SunOS 4.X, have a kernel variable named:
> _physmem
>
> This stores the number of physical pages. So
> _physmem * pagesize = physical memory.
>
> Now there is a gotcha in SunOS. The prom monitor "steals" a
> few pages at system powerup/bootup.
>
> The following script should help. I ran it on my 670MP.
>
> You can use the kvm(3) libraries to access the kernel physmem
> variable.
>
> --------------script------------------------
> Script started on Fri Oct 22 20:20:39 1993
> dspsim1% adb /vmunix /dev/kmem
> not core file = /dev/kmem
> physmem/D
> _physmem:
> _physmem: 32676
> $q
> dspsim1% uname -a
> SunOS dspsim1 4.1.2 1 sun4m
> dspsim1%
> dspsim1% pagesize
> 4096
> dspsim1% ^D
> script done on Fri Oct 22 20:21:27 1993

-------------------
Per Dan Stromberg <strombrg@hydra.acs.uci.edu>:

> adb -w -k /vmunix /dev/mem should give a relevant report, upon
> invocation. It's not total memory, but memory left after OS overhead.
>

-------------------
Also per Dan Stromberg <strombrg@hydra.acs.uci.edu>
and venaas@nvg.unit.no (Stig Venaas):

> What about wc -c /dev/mem

> Doing the wc /dev/mem works on some machines, not others; I don't know
> about sparcs. If the memory address space is fragmented, this should
> give a seg violation or something. If the memory space contains
> memory-mapped I/O registers that do interesting things on read, you
> could well crash the machine or even zot some info on some media, like
> a disk - though it's not that likely, odder designs have been known.

   This works, but takes relatively lots of time and cpu to get an answer
   on a larger machine.

-------------------
Per rossen@sfu.ca:

> You know, that should be a really simple bit of information to find, but
> I've been looking through the online manuals for two days now and I STILL
> can't find a command or program to do this! This is one way that I found
> to get a rough estimate: go "ps -u" and you will get the long version
> of the process info for anything you have going. In the RSS column they
> give "resident set storage" (or something like that) in kilobytes that
> tells you how much real memory the process is using. There is also a
> %MEM column that tells you what fraction of the real memory your process is
> taking up. REAL_MEM(kbytes)=RSS/(%MEM*0.01). This gives about 6 megs for
> my machine.

-------------------
Per stevek@apertus.com (Steve Kappel)

> The "node 'memory' Size" produced by /usr/etc/devinfo -v (on SunOS 4.1) is > the hex size of RAM.

-------------------
Per markhof@ls12i.informatik.uni-dortmund.de
 

/*
 * mem.c - print physical memory installed in a machine
 *
 * $Author: kensmith $
 *
 * $Date: 90/03/12 14:18:18 $
 *
 * $Log: mem.c,v $
 * Revision 1.2 90/03/12 14:18:18 kensmith
 * misc. cleanup
 *
 * Revision 1.1 90/02/09 21:43:41 kensmith
 * Initial revision
 *
 */

#include <stdio.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/file.h>
#include <nlist.h>

static char rcsid[] = "$Id: mem.c,v 1.2 90/03/12 14:18:18 kensmith Exp Locker: kensmith $";

struct nlist nls[] = {
        { "_physmem" },
#define PHYSMEM 0
        { "" },
};

int fd, physmem;

char *name; /* program name */
char *rindex();

main(argc, argv)
        int argc;
        char *argv[];
{
        if ((name = rindex(argv[0], '/')) == NULL)
                name = argv[0];
        else
                name++;
        if (nlist("/vmunix", nls) < 0) {
                perror("nlist");
                exit(1);
        }
        if ((fd = open("/dev/kmem", O_RDONLY)) <= 0) {
                perror("/dev/kmem");
                exit(1);
        }
        if (nls[PHYSMEM].n_type == 0) {
                fprintf(stderr, "%s: physmem symbol not found\n", name);
                exit(1);
        }
        lseek(fd, nls[PHYSMEM].n_value, L_SET);
        read(fd, &physmem, sizeof(physmem));
        printf("%dK bytes of memory\n", ctob(physmem) / 1024);
}

-------------------
Per richard@langeoog.gmd.de (Richard Czech)

/*
 * Figure out how much memory there is on a machine. This works under
 * Berkeley UNIX. It should work under System V if you change the
 * UNIX define to "/unix" instead of "/vmunix".
 *
 * Of course, if you don't have read permission on the kernel and
 * kernel memory, this won't work.
 *
 * Dave Curry
 * Purdue University
 * Engineering Computer Network
 *
 * Hacked by Larry Breniser 10/1/91
 * Pagesize is now determied dynamically, not at compile
 * time, as it varies from host to host (server vs workstation)
 *
 * davy@intrepid.ecn.purdue.edu
 * $Header: /usr2/larryb/c/RCS/physmem.c,v 1.3 91/10/02 17:51:10 larryb Exp $
 * $Log: physmem.c,v $
 * Revision 1.3 91/10/02 17:51:10 larryb
 * Added Version string to executable for ident.
 *
 * Revision 1.2 91/10/02 17:46:21 larryb
 * Added RCS log comments.
 *
 */
#include <sys/param.h>
#include <sys/types.h>
#include <nlist.h>
#include <stdio.h>

char version[] = "$Header: /usr2/larryb/c/RCS/physmem.c,v 1.3 91/10/02 17:51:10 larryb Exp $";

#define UNIX "/vmunix"
#define KMEM "/dev/kmem"

struct nlist nl[] = {
#define X_PHYSMEM 0
        { "_physmem" },
#define X_MAXMEM 1
        { "_maxmem" },
        { NULL }
};

main()
{
        int kmem;
        int maxmem, physmem;
        int pagesize;

        /*
         * Look up addresses of variables.
         */
        if ((nlist(UNIX, nl) < 0) || (nl[0].n_type == 0)) {
                fprintf(stderr, "%s: no namelist.\n", UNIX);
                exit(1);
        }

        /*
         * Open kernel memory.
         */
        if ((kmem = open(KMEM, 0)) < 0) {
                perror(KMEM);
                exit(1);
        }

        /*
         * Read variables.
         */
        lseek(kmem, (long) nl[X_PHYSMEM].n_value, 0);
        read(kmem, (char *) &physmem, sizeof(int));

        lseek(kmem, (long) nl[X_MAXMEM].n_value, 0);
        read(kmem, (char *) &maxmem, sizeof(int));

        close(kmem);

        pagesize=getpagesize();

        /*
         * Print the numbers. The internal representation is
         * in units of core clicks; convert to bytes.
         */

        printf("Pagesize: %d\n", pagesize);

        printf("Physical machine memory: %d\n", pagesize * physmem);
        printf("Max memory available to a process: %d\n", pagesize * maxmem);

        exit(0);
}



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:27 CDT