AT&T's paging UNIX operating system provides two tools to
analyze memory usage.  The sar(1) package collects statistics
about the amount of free memory in the system, and the number of
pages and processes moved in and out from the disk swap area.
The ps(1) command's "-l" option shows each process' size in pages.
(1 page = 2Kb.)

Unfortunately, neither sar nor ps tells how many pages from each
process are in actually core, and how many have been saved to disk.
To fill this need, I wrote "pages".  "Pages" works a lot like ps(1).
It reads /unix to find kernel symbol addresses, then opens /dev/kmem
and rummages around to find the information it wants.  "Pages" saves
kernel symbol data in /etc/pg_data to speed up execution.  This file
is updated automatically whenever /unix is newer than /etc/pg_data.

"Pages" notes the size and the number of pages in core for each
paging region in the system.  A typical process has three regions:
text (executable instructions), initialized data variables, and
uninitialized variables (called BSS).  Processes may also use
regions to connect to shared libraries, shared memory segments, etc.

After each region has been analyzed, "pages" prints a table of
each process and independent region it has encountered.  The table
shows the process id (if appropriate), the number of pages swapped
to disk, and total number of pages, and the process' name (if appropriate.)

A typical run of "pages" (with no arguments) may look like this:

1:	  PID  NSWAP/TOTL   COMMAND
2:	SHARE      1   23   sh
3:	11308      3    8   sh
4:	18486     12  104   vi
5:	18498     15   46   pages
6:	18496      3    8   sh

Line one is column headings.  The second line shows the shared text region
of the Bourne shell (indicated by the word "SHARE" in column 1.)  One of
its 23 pages is paged out to disk (or was never loaded in the first place.)
The third line is the combined data and BSS regions of a shell, with three
of the 8 pages on disk.  Since the data are not shared, the specific process
id is shown.  Line 6 gives the same information for another shell process.

Line 4 shows that 12 of 104 pages of vi are on disk.  In this case, the
TOTL column represents the combined text, data, and BSS sizes.  If another
user was running vi, a "SHARE" line show the shared text region separately.
Line 5 shows "pages" itself.

By defaults, "pages" only shows processes attached to your current tty.
To alter this behavior, the -e, -a, -t, and -u options may be used.
These options work the same as on "pages" as they do on "ps", and
are explained on the ps(1) man page.  In addition, the -q option may
be used to get a quick look at the system's overall paging status.

"Pages" must run as setuid bin so that it can write the /etc/pg_data file,
and as setgid sys so that it can read /dev/kmem.  The makefile supplied
with this package sets ownership and uid/gid bits when the "install"
target is specified.

Notes on portability:  "Pages" is highly dependent on the System V
Release 3.1 implementation, and it has only been tested on the
AT&T 3B2/400 computer.  "Pages" will probably run on all members of
the 3B2 family, but may run on the 3B15 as well.  As far as release
compatability goes, SVR3.0 is probably OK, SVR2.1 *may* work, and
releases prior to 2.1 didn't have paging.

I had to read and compare /usr/include/sys files and wade through lots of
kernel dumps to find the algorithms for this program.  Anyone who wants
to port "pages" to a truly foreign implementation will have to do the same.
I only have access to the 3B2/400, so you're on your own when it comes
to porting.  Sorry.

Enhancements and bug reports (preferably with fixes) are welcome but
I don't promise to incorporate them immediately.  Since netnews often
expires before I get around to reading it, messages should be sent
via E-mail to ihnp4!chinet!djmolny.

This program is placed in the public domain.  It may be distributed
and modified freely providing this notice is reproduced in its entirety.
This program may not be sold.  Author: DJ Molny, ccom consultants, inc.
