Ubuntu – Testing the system, I need a script that will use as much ram and swap as possible

13.04ramscripts

I'm testing my system with zram, I need a script that will use as much ram as possible. This script should fill up my ram with random stuff not just zeros.

Best Answer

memtester is a user space program designed to allocate memory (any amount you specify) and test it with random patterns. It will avoid swap usage though. But if you take all memory away with memtester first (check with free -m) and then start anything else that uses a lot of memory (gimp, firefox, ...), that should get the swap going.

Another alternative would be something like openssl rand -base64 $((1024*1024*1024)) | less and in less use > to jump to the last line; this will cause 1GB of base64 encoded random data to be loaded in memory (but it's slow).

If you're looking for something more efficient, a small script in any scripting language (e.g. Python) might do.

#!/usr/bin/python2
import numpy
result = [numpy.random.bytes(1024*1024) for x in xrange(1024)]
print len(result)

That would allocate 1G of memory with random data and print the number of MB allocated before terminating. If you want more than 1024M, adapt the xrange value accordingly.