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

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.


Just run :

echo {1..1000000000}

Explanation :

The Shell, Before giving the command to the kernel, Expands all the regular expressions and short-hands. The expanded command is temporarily stored in RAM. The above command expands to a very large command and hence it will completely fill the RAM (tested on 8GB).

WARNING : This is not a controlled way of filling RAM. You might get stuck after running this command. I advice you to keep your system monitor open (for watching RAM usage) and try with smaller numbers.


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.


As prophecy201 suggested, stress is a great tool to use up your system's memory. Adding more workers will use up more RAM, but it will also use up more CPU, which is pretty ineffecient if all you want is to test RAM. Not to mention that the CPU will be needed by zram for compression.

Instead, you should increase the amount of RAM that is used with the --vm-bytes flag. For example, to use up 4 GB of RAM with one worker:

stress -m 1 --vm-bytes 4G

You may also find the --vm-keep flag helpful as it will hold the memory allocation instead of continually reallocating, so the memory usage will be constant instead of fluctuating:

stress -m 1 --vm-bytes 4G --vm-keep

Lastly, take a look here to make sure zram is what you really want; since you do have swap, zswap may be a better solution: zram vs zswap vs zcache Ultimate guide: when to use which one


I would suggest to use the program stress, installable from the repositories with sudo apt-get install stress.

To test your RAM use stress -m x where x is the number of workers which will fill up the ram. Choose more workers to use more RAM.