RAMdisks are virtual partitions that reside in memory except all data is lost when power is removed from the system. Reads and writes are lighting fast in comparison to standard mechanical and NAND based storage. There can be real performance benefits when used correctly.

Today we will review how to create one on using a Debian-based distribution.

Before starting  verify whether your system has enough RAM. On our system we can see there is 27G free.

free -hg
       total   used   free   shared buff/cache  available
Mem:     31G   2.4G    27G     182M       1.9G        28G
Swap:   2.0G     0B   2.0G

Start off by creating a directory that you will use to mount the RAMdisk

sudo mkdir -p /media/RAMDISK-16GB

Next create the RAMdisk and mount it. Here we are creating one that is 16GB in size.

sudo mount -t tmpfs -o size=4096m tmpfs /media/RAMDISK-16GB

Add it to the fstab so that it will automatically mount each time the system boots

sudo vi /etc/fstab
tmpfs    /media/RAMDISK-16GB tmpfs    defaults,size=16384M   0 0

That was pretty simple, so how fast is it? dd allows you to perform simple sequential performance benchmarks.

Throughput

Write Test

dd if=/dev/zero of=/media/RAMDISK-16GB/zero bs=1G count=9 conv=fdatasync
9+0 records in
9+0 records out
9663676416 bytes (9.7 GB) copied, 2.08909 s, 4.6 GB/s

Flush buffer-cache

echo 3 > /proc/sys/vm/drop_caches

Read Test

dd if=/media/RAMDISK-16GB/zero of=/dev/null bs=1G count=9
9+0 records in
9+0 records out
9663676416 bytes (9.7 GB) copied, 0.982379 s, 9.8 GB/s

Latency

Write Test

dd if=/dev/zero of=/media/RAMDISK-16GB/zero bs=512b count=1000 conv=fdatasync
1000+0 records in
1000+0 records out
262144000 bytes (262 MB) copied, 0.0463806 s, 5.7 GB/s

Flush buffer-cache

echo 3 > /proc/sys/vm/drop_caches

Read Test

dd if=/media/RAMDISK-16GB/zero of=/dev/null bs=512b count=4000
4000+0 records in
4000+0 records out
1048576000 bytes (1.0 GB) copied, 0.0891466 s, 11.8 GB/s