man usemem
NAME
usemem - Allocate memory until failure or paging
SYNOPSIS
usemem [-b base] [-i increment] [-options]
DESCRIPTION
Allocates memory (megabyte units) until failure or until paging occurs.
Knowing maximum viable program size is useful for any environment. Unfortunately,
many operating systems (OS) behave poorly to excessive paging. Once memory has
been exhasuted an OS will typically page older pages/programs out to disk. This
can be a slow process. Responsiveness to the paged programs will certainly suffer.
If system daemons are paged, responsiveness of the system can suffer and can break
any time sensitive daemons or programs. If paging space is exhausted entirely, the
OS will kill processes typically using an algorithm based on least referenced pages
not who is consuming memory. Unrelated programs and also critical system daemons
may get killed.
This program is intented to run to gauge available memory for a single program,
typically it is run on an unloaded system. If the operating system does not sup-
port maxrss from getrusage() then the -f (force) flag must be used and the program
should be monitored in another window via a tool like top or vmstat to know when to
interrupt this program before it can debilitate a system.
Systems which do report maxrss from getrusage():
AIX
IRIX
UNICOS/mp
Systems which do not report maxrss:
Mac OSX
SunOS
Linux
Default invocation is quivalent to:
usemem -b 100 -i 10 -p -z 1
OPTIONS
-base size
Establish initial allocation (heap/data) size in megabyte. Defaults to
100mb.
-increment size
Establish allocation increment (heap/data) in megabytes. Defaults to 10mb.
-max size
Establish maximum allocation (heap/data) in megabytes. Implies -force.
-zzz seconds
Sleep time between allocations, defaults to 1 second. One second is added
on systems which do not support maxrss from getrusage().
-wait seconds
Wait time after allocation completes before exit. Enter a wait loop using
-zzz seconds +4 re-referencing allocated memory before exiting program.
-stack Also grow stack by 1mb per allocation.
-force Force allocation to continue for systems which do not support maxrss or when
paging is ocurring.
-pend Stop allocation when maxrss is less than allocated memory (e.g., paging is
ocurring). This option is a default except when -max specified, specify
after -max if desired. Note, operating systems which do not support maxrss
from getrusage() cannot detect paging.
-quiet Run quieter, do not show allocation loops which complete in -z seconds+1.
-reference
Reference (read) all allocated pages after each new allocation (e.g., ensure
they are paged in).
-use Use pid in output to identify multi-process (e.g., mpi) execution.
-verbose
Run verbose, with -r show memory reference loops.
-?|-help
Display terse usage information.
EXAMPLES
An example from a 16gb AIX 5.3 p575 compute node:
f4n3: uname -a
AIX f4n3 3 5 00C33E9F4C00
f4n3: ulimit -a
time(seconds) 1800
file(blocks) unlimited
data(kbytes) 262144
stack(kbytes) unlimited
memory(kbytes) 262144
coredump(blocks) 20000
nofiles(descriptors) 2000
f4n3: ulimit -d unlimited
f4n3: cc -q64 -o usemem usemem.c
f4n3: ./usemem -b 2000 -i 200
heap -1.0:soft -1.0:hard
stack -1.0:soft -1.0:hard
rss 256.0:soft 1024.0:hard
# 1.3:rss 364:min 0:maj # 10:42:18
# 2002.3:rss 513615:min 0:maj # 10:42:20 2000mb (0, 0)
# 2202.3:rss 564912:min 0:maj # 10:42:22 2200mb (0, 1)
# 2402.3:rss 616215:min 0:maj # 10:42:23 2400mb (0, 2)
...
# 13602.3:rss 3489047:min 0:maj # 10:43:33 13600mb (0,58)
# 13802.3:rss 3540349:min 0:maj # 10:43:34 13800mb (0,59)
# 13894.1:rss 3591644:min 2:maj ! 10:44:29 14000mb (0,60)
f4n3: date
Thu Sep 29 10:47:44 ADT 2005
Things to note above:
Raised ulimit data to unlimited
Compiled with -q64
AIX supports maxrss, usemem stopped itself
Long pause after 13800 indicates
other programs being paged out
Took 3 minutes to end (OS cleaning up)
A second example from the same node with a parallel vmstat to get the OS perspec-
tive:
f4n3: ./usemem -b 2000 -i 200
heap -1.0:soft -1.0:hard
stack -1.0:soft -1.0:hard
rss 256.0:soft 1024.0:hard
# 1.3:rss 362:min 0:maj # 10:49:07
# 2002.3:rss 513622:min 0:maj # 10:49:10 2000mb (0, 0)
# 2202.3:rss 564923:min 0:maj # 10:49:11 2200mb (0, 1)
...
# 13402.3:rss 3437737:min 0:maj # 10:50:21 13400mb (0,57)
# 13602.3:rss 3489037:min 0:maj # 10:50:22 13600mb (0,58)
# 13797.1:rss 3540317:min 6:maj ! 10:50:37 13800mb (0,59)
f4n3: vmstat 1 200
System configuration: lcpu=16 mem=15744MB
kthr memory page faults cpu
---- ---------- -------------------- ----------- --------
0 0 421k 3599k 0 0 0 0 0 0 4 29 309 0 0 88
1 0 421k 3599k 0 0 0 0 0 0 3 21 307 0 0 88
0 0 421k 3599k 0 0 0 0 0 0 1 14 302 0 0 88
1 0 534k 3486k 0 0 0 0 0 0 5 82 316 7 0 81
1 0 749k 3271k 0 0 0 0 0 0 2 19 307 13 0 76
0 0 3691k 330k 0 0 0 0 0 0 1 25 297 2 0 86
0 0 3705k 315k 0 0 0 0 0 0 2 21 305 1 0 87
0 0 3756k 264k 0 0 0 0 0 0 2 20 298 3 0 85
0 0 3808k 213k 0 0 0 0 0 0 2 20 300 3 0 85
1 0 3859k 161k 0 0 0 0 0 0 3 21 298 3 0 85
1 0 3892k 128k 0 0 0 0 0 0 1 20 298 2 0 86
0 0 3910k 110k 0 1 0 0 0 0 3 266 308 1 0 86
0 0 3941k 82k 0 5 438 6k 52k 0 414 19 279 2 1 81
0 1 3941k 82k 0 0 333 0 0 0 498 17 298 0 0 82
0 1 3941k 83k 0 0 307 0 0 0 508 16 302 0 0 82
0 1 3941k 83k 0 0 413 0 0 0 547 14 327 0 0 82
0 1 3941k 83k 0 0 305 0 0 0 509 15 302 0 0 82
0 1 3941k 84k 0 1 387 0 0 0 531 74 338 0 0 82
0 1 3941k 84k 0 0 341 0 0 0 571 14 298 0 0 82
0 1 3941k 85k 0 0 393 0 0 0 486 14 299 0 0 82
2 0 3950k 81k 0 12 514 10k 509k 0 569 14 286 1 8 75
0 1 3950k 83k 0 2 2572 0 0 0 749 98 323 0 1 81
0 1 3950k 86k 0 2 2329 0 0 0 745 15 295 0 1 79
0 2 3957k 82k 0 3 1241 6k 250k 0 568 16 304 0 5 77
0 1 3957k 84k 0 3 1789 0 0 0 626 14 294 0 1 82
0 1 3957k 85k 0 0 891 0 0 0 635 18 307 0 0 82
0 0 3962k 81k 0 2 717 0 0 0 349 28 320 0 0 82
1 0 3597k 446k 0 0 0 0 0 0 1 17 301 0 9 77
1 0 3066k 976k 0 0 0 0 0 0 1 14 301 0 12 75
1 0 2532k 1509k 0 0 0 0 0 0 1 32 312 0 13 76
1 0 2010k 2031k 0 0 0 0 0 0 1 16 309 0 13 76
1 0 1440k 2601k 0 0 0 0 0 0 1 14 307 0 13 76
1 0 859k 3182k 0 0 0 0 0 0 2 17 302 0 13 76
0 0 421k 3620k 0 3 0 0 0 0 7 41 314 0 9 79
0 0 421k 3620k 0 0 0 0 0 0 1 16 299 0 0 88
Things to note above:
Paging activity gets a bit dramatic.
The following example is from a Macintosh OSX system which does not support maxrss
from getrusage(). The program was monitored with "top" and the results are inter-
leaved with usemem execution:
macosx: uname -nmpsr
Darwin dorado-e0.arsc.edu 7.9.0 Power Macintosh powerpc
macosx: top
macosx: ./usemem -f -r
heap 6.0:soft -1.0:hard
stack 8.0:soft 64.0:hard
rss -1.0:soft -1.0:hard
!
! Warning:
!
! This OS does not return maxrss from getrusage(), this
! program cannot determine when paging is occuring.
! Use -f to force the allocation loop to occur.
! Monitor with "vmstat 1 120" or "top" in another window,
! interrupt before paging debilitates the system.
! One second added to the -z sleep between allocations.
!
# -1.0:rss # 10:14:45
# -1.0:rss ? 10:14:45 100mb ( 0, 0)
# -1.0:rss ? 10:14:47 110mb ( 0, 1)
...
# -1.0:rss ? 10:14:59 160mb ( 0, 6)
# -1.0:rss ? 10:15:02 170mb ( 0, 7)
Processes: 111 total, 2 running, 227 threads 10:15:02
CPU usage: 41.6% user, 12.4% sys, 46.0% idle
MemRegions: num= 9494, res= 296M+16.4M priv
PhysMem: 144M active 468M inact 723M used 300M free
VM: 7.04G + 95.6M 87872(0) pageins, 18312(0) pageouts
PID COMMAND %CPU TIME #PRTS #MREGS RPRVT RSIZE VSIZE
4163 usemem 36.1% 0:02.80 12 30 172M+ 172M+ 196M+
4154 top 9.7% 0:43.20 17 26 540K 928K 27.1M
# -1.0:rss ? 10:15:04 180mb ( 0, 8)
# -1.0:rss ? 10:15:07 190mb ( 0, 9)
...
# -1.0:rss ? 10:16:23 450mb ( 0,35)
# -1.0:rss ? 10:16:27 460mb ( 0,36)
# -1.0:rss ? 10:16:31 470mb ( 0,37)
# -1.0:rss ? 10:16:35 480mb ( 0,38)
Processes: 111 total, 3 running, 224 threads 10:16:36
CPU usage: 58.0% user, 17.5% sys, 24.5% idle
MemRegions: num= 9526, res= 590M+16.4M priv
PhysMem: 157M active 738M inact 1007M used 16.6M free
VM: 7.34G + 95.6M 87873(0) pageins, 26330(2894) pageouts
PID COMMAND %CPU TIME #PRTS #MREGS RPRVT RSIZE VSIZE
4163 usemem 59.9% 0:26.73 12 61 482M+ 482M+ 506M
4154 top 10.3% 0:52.69 17 26 540K 928K 27.1M
# -1.0:rss ? 10:16:39 490mb ( 0,39)
# -1.0:rss ? 10:16:44 500mb ( 0,40)
# -1.0:rss ? 10:16:49 510mb ( 0,41)
# -1.0:rss ? 10:16:54 520mb ( 0,42)
# -1.0:rss ? 10:16:58 530mb ( 0,43)
# -1.0:rss ? 10:17:06 540mb ( 0,44)
# -1.0:rss ? 10:17:10 550mb ( 0,45)
Processes: 111 total, 2 running, 224 threads 10:17:10
CPU usage: 6.2% user, 14.2% sys, 79.6% idle
MemRegions: num= 9465, res= 618M+16.1M priv
PhysMem: 597M active 298M inact 1009M used 14.4M free
VM: 7.39G + 95.6M 89846(41) pageins, 43533(0) pageouts
PID COMMAND %CPU TIME #PRTS #MREGS RPRVT RSIZE VSIZE
4163 usemem 0.0% 0:34.74 12 67 535M 529M 566M
4154 top 10.6% 0:55.56 17 26 516K 812K 27.1M
(ctrl/c)
Things to note above:
Needed -f to run, added -r for re-referencing
The to RSIZE tracks usemem allocation until >500mb
Had to interrupt or would have malloc-ed until Mac broke.
NOTES
Compile with -DUSE_MPI to enable mpi.
ACKNOWLEDGEMENTS
Written at the University of Alaska Arctic Region Supercomputing Center (ARSC).
Ongoing maintenance via SourceForge by Denali Sun Consulting.
Suggestions or bug reports can be directed to denalisun907@gmail.com.
RELATED INFORMATION
Commands: ulimit(shell), getrusage(3), vmstat, top, topas(AIX).