How much memory is left? (Re: Swapping and wmgr)

Lenny Tropiano lenny at icus.UUCP
Sun May 29 07:36:10 AEST 1988


In article <459 at bacchus> darren at bacchus.UUCP (Darren Friedlein) writes:
|>
|>When smgr (found out I had the wrong mgr) displayed the [!!] icon before,
|>the message I got was that phdaemon died because SOMETHING was swapped
|>out, either phdaemon or a program it was monitoring.  This time, smgr
|>quit completely right after the [!!] icon appeared.  From ps, I could
|>see that the system load was real heavy.  This doesn't assure that
|>swapping was the cause, but that would be my best guess.
|>
phdaemon doesn't support (cause I have too much memory and I can't test
it) when the process it is monitoring get's swapped out (written to /dev/swap)
because the 4MB of virtual memory was used up.  If anyone has a piece of
code to add to phdaemon to handle swapped processes, let me know... 

Here's your troublesome function...

char *getcommand()
{
    static struct user users;
    long   upage;

    if (!proc.p_stat || proc.p_stat == SIDL || proc.p_stat == SZOMB)
	return 0;

    if (!(proc.p_flag & SLOAD)) {
	sprintf(buffer,"can't handle swapped process %d (flag=%05x)",
		proc.p_pid, proc.p_flag);
	werror(buffer,1);
    }

    upage = (long)ctob(proc.p_addr[0]);
    read_mem((char *)&users, upage + U_OFFSET, (long) sizeof (struct user));

    return(users.u_comm);
}

The function "werror()" writes to /dev/error by calling eprintf() and
that might be what is crashing your smgr since the smgr reads the /dev/error
device and prints the "[!!] [!]" icons...
|>What is the difference between a process being swapped out and normal
|>VM paging?  I thought the UNIXpc could only support 4M or virtual memory,
|>but when I formatted the drive, it reserved 6M of space.

I assume a process only gets swapped after you use up the 4MB of virtual
memory.  The 6MB you claim is disk storage for the swap partition, not
the virtual memory...they are two different animals.

Here's a short program that will tell you how much memory you have...

$ cc -c -O memory.c 
$ ld -s -o memory memory.o /lib/crt0s.o /lib/shlib.ifile
$ su
Password:
# chown root memory
# chmod 4755 memory
# memory
...
-Lenny

--- cut here --- --- cut here --- --- cut here --- --- cut here ---
#include <stdio.h>
#include <sys/param.h>
#include <sys/types.h>
#include <nlist.h>

#ifndef ctob
#include <sys/sysmacros.h>
#endif

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

struct nlist nl[] = {
#define X_PHYSMEM	0
	{ "physmem" },
#define X_MAXMEM	1
	{ "maxmem" },
#define X_FREEMEM	2
	{ "freemem" },
	{ NULL }
};

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

	/*
	 * Look up system addresses in the kernel
	 */
	if (nlist(UNIX, nl) < 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));

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

	close(kmem);

	/*
	 * Print the numbers.  The internal representation is
	 * in units of core clicks; convert to bytes using ctob macro.
	 */
	printf("Physical machine memory: %d\n", ctob(physmem));
	printf("Max memory available to a process: %d\n", ctob(maxmem));
	printf("Free memory available to a process: %d\n", ctob(freemem)); 

	exit(0);
}

-- 
US MAIL  : Lenny Tropiano, ICUS Computer Group        IIIII  CCC U   U  SSS
           PO Box 1                                     I   C    U   U S
           Islip Terrace, New York  11752               I   C    U   U  SS 
PHONE    : (516) 968-8576 [H] (516) 582-5525 [W]        I   C    U   U    S
TELEX    : 154232428 [ICUS]                           IIIII  CCC  UUU  SSS 
AT&T MAIL: ...attmail!icus!lenny  
UUCP     : ...{mtune, ihnp4, boulder, talcott, sbcs, bc-cis}!icus!lenny 



More information about the Comp.sys.att mailing list