How much memory & probing /dev/kmem
Allan M. Schiffman
parcplace!ams at sun.com
Wed Jan 18 15:46:00 AEST 1989
I have an interactive program which runs for hours (or days or weeks)
which is very demanding of physical memory and virtual address space, and
has a complex internal memory management regime. It would be very useful
if this program had a way to estimate how much physical memory it would be
likely to get and how much data segment address space it could allocate
(using sbrk()) if it needed to. I'd like any code which makes these
estimates to work on SunOS 3.x & 4.0+. It's OK if these estimates are
wrong occasionally, since the information is only used for tuning the
program's memory management policies.
For the purposes of this discussion, let's call the two values MaxRSS and
MaxVirtual. Also, let's leave rlimit out of the picture. Of course,
neither value is knowable to great precision since MaxRSS depends on the
available physical memory plus the time-varying memory demands of both my
program and all others running; MaxVirtual depends on the size of swap
space and the time-varying address space demands of all processes. Still,
if we assume that my program is the only hog running, then MaxVirtual
could be computed as a function who's first-order term would be swap space
size; MaxRSS could be computed as a function who's first-order term would
be the size of physical memory on the machine.
Now to the questions:
0. What's the best way to estimate MaxRSS and MaxVirtual?
1. How can I get these values without opening /dev/kmem? Most
SunOS 4.0 installations don't give read permission to world and I
don't want to run setuid or setgid. I *have* done
popen("/usr/etc/pstat -s | awk '<extract allocable/available>'")
...to get the available swap space and
popen("/bin/ps au | awk '<extract (sigma RSS / sigma %MEM)>' ")
...to get the estimated 'available memory'. Pretty disgusting, huh?
What should I do instead?
2. Let's say I open /dev/kmem first (and fall back to strategy #1
above only if it lacks read permission, because the popen stuff is
so slow). But which kernel locations do I want and how do I
interpret them? For instance:
a. /usr/include/sys/systm.h has maxmem, which is documented as
"actual max memory per process", but the value I get on my 8Mb
3/60 running 3.4 is 7272Kb (actually I get 909 pages). This
sounds unreasonably high. Does it include VM buffers, etc?
b. /usr/include/sys/systm.h has physmem, which is documented as
"physical memory on this CPU", but the value is two pages shy
of 8Mb. Anybody know why?
c. With SunOS 3.4, /usr/include/sys/systm.h has nswap, which is
documented as "size of swap space", gave me the value 50184,
but pstat -s gives:
9944k used (3784k text), 14636k free, 1976k wasted, 0k missing
max process allocable = 13296k
avail: 13*1024k 2*128k 7*64k 12*32k 9*16k 92*1k
I could guess that nswap's units are 512-byte blocks, but it
still doesn't work out. What are the units for nswap and what
does it measure?
d. SunOS 4.0 doesn't have nswap. Is there something else I
could find in kmem that gives the size of swap space?
3. Is there something I can do with /dev/drum to find out its size?
4. Has anyone used libkvm.a on SunOS 4.0 (library for reading kmem).
Why is kvm_open(0, 0, 0, O_RDONLY, 0) so s-l-o-w?
Thanks for your patience with this too long message.
Allan M. Schiffman
ParcPlace Systems
ams at parcplace.com
More information about the Comp.sys.sun
mailing list