Skip to content

Saturate (max out) Memory Utilization

To Max out memory use:

#!/usr/bin/python
 
# To eat 40GB of RAM and hold it for 5 seconds type:
#./memconsume.py 5 40
 
import time
import sys
 
seconds = int(sys.argv[1])
gb = int(sys.argv[2])
 
mem = gb * 1073741824;
cap = 1 * 1073741824;
calls = ( mem // cap );
print "consuming, using %s" % (mem);
 
memstr = []
for call in range( calls ):
    print " adding: %s" % (cap);
    memstr.append(' ' * cap);
 
print "waiting..."
 
time.sleep(seconds)

Categories

Debugging, Linux

TheSoftwareProgrammer View All

I like science and writing software.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: