How to create a temporary ram drive on a Linux box. This is very useful.

Posted: December 3, 2017. At: 6:52 AM. This was 2 weeks ago. Post ID: 11571
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

Creating a ram drive on a Linux box is very useful for storing files in a temporary fashion, and having some very fast scratch space for an application. The ramfs filesystem type may be used, but it will continue to grow until your RAM is used up. The tmpfs filesystem type, does not have this problem. Using, this you may create a fixed size ramdisk that will contain your files.

Firstly, create a directory to mount the ramdisk to.

[email protected]:/mnt/ramdisk$ sudo mkdir ramdisk

Then create the new ramdisk.

[email protected]:/mnt/ramdisk$ sudo mount tmpfs -t tmpfs -o size=1G,noexec,nosuid /mnt/ramdisk/

This gives us a 1 gigabyte ramdisk to put files into.

Now the ramdisk is mounted.

jason@jason-desktop:/mnt/ramdisk$ mount | grep ramdisk
tmpfs on /mnt/ramdisk type tmpfs (rw,nosuid,noexec,relatime,size=1048576k)

Testing with ioping shows me that the filesystem is very fast indeed.

jason@jason-desktop:/mnt/ramdisk$ ioping RAIDInteractiveSimulator4.exe 
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=1 time=15.0 us (warmup)
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=2 time=3.02 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=3 time=3.17 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=4 time=16.5 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=5 time=3.35 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=6 time=3.36 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=7 time=3.46 us (fast)
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=8 time=12.4 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=9 time=14.4 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=10 time=14.2 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=11 time=12.9 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=12 time=3.22 us (fast)
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=13 time=15.2 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=14 time=14.6 us
4 KiB <<< RAIDInteractiveSimulator4.exe (tmpfs tmpfs): request=15 time=13.1 us
^C
--- RAIDInteractiveSimulator4.exe (tmpfs tmpfs) ioping statistics ---
14 requests completed in 132.8 us, 56 KiB read, 105.4 k iops, 411.7 MiB/s
generated 15 requests in 14.4 s, 60 KiB, 1 iops, 4.17 KiB/s
min/avg/max/mdev = 3.02 us / 9.49 us / 16.5 us / 5.48 us

Compare that to my Linux hard disk drive.

jason@jason-desktop:~/Documents$ ioping RAIDInteractiveSimulator4.exe 
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=1 time=9.15 ms (warmup)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=2 time=6.12 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=3 time=261.9 us
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=4 time=8.65 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=5 time=14.2 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=6 time=148.5 us
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=7 time=252.6 us (fast)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=8 time=16.6 ms (slow)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=9 time=225.1 us (fast)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=10 time=6.90 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=11 time=220.4 us (fast)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=12 time=4.59 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=13 time=183.1 us (fast)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=14 time=1.39 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=15 time=302.0 us (fast)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=16 time=5.59 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=17 time=10.1 ms
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=18 time=16.5 ms (slow)
4 KiB <<< RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0): request=19 time=238.7 us (fast)
^C
--- RAIDInteractiveSimulator4.exe (ext4 /dev/dm-0) ioping statistics ---
18 requests completed in 92.5 ms, 72 KiB read, 194 iops, 778.3 KiB/s
generated 19 requests in 18.5 s, 76 KiB, 1 iops, 4.11 KiB/s
min/avg/max/mdev = 148.5 us / 5.14 ms / 16.6 ms / 5.73 ms

And it is obvious that a ramdisk is far faster than a magnetic HDD. So give this a go yourself and see how fast it is for you.

No comments have been made. Use this form to start the conversation :)

Leave a Reply