Making and Mounting a RAM Disk
As fast as they are, sold state drives aren’t really my thing. Not that I don’t want one, but rather the cost of the drive simply isn’t worth the benefits.
Of course, there are times when fast read/write times can be hugely beneficial. Take, for instance, video processing. The faster that the CPU can access a video, the faster the processing can be completed. In fact, its likely that copying the video onto a high speed hard drive where the CPU can get to it faster could reduce the total time despite the copy time. And that’s where a ramdisk can come in handy.
Linux has tmpfs, which allows you to make a partition from memory on the RAM. This partition is dynamically allocated - meaning that it changes the size of memory used in RAM based on how much is being stored in it.
To make a ramdisk and mount it run the following as root with appropriate values:
mount -t tmpfs tmpfs /path/to/mountpoint -o size=size_in_gigsG
.
The G at the end is appended to the numerical value for the number of gigabytes in the partition. This can be changed to other values, a M
resulting in megabyte sized partitions and a K resulting in kilobyte size partitions. There appears to be a lower limit to the size of the partitions at 4 kilobytes.
An example in which a two gigabyte partition is mounted to the /media/temp_part
directory follows
mount -t tmpfs tmpfs /media/temp_part -o size=2G
.
If you’ve got a large amount of RAM (like my four gigabytes worth) this could greatly decrease processing times on small media files. If you have an absurd amount of RAM - lucky you (of course you’ve also probably got a solid state drive).
But wait, there’s more. You can add a ramdisk into fstab
so that it will mount at boot. This lends itself to being used for caching - for example it would be no hard feat to mount a ramdisk to /tmp
the default location for caching.
The format for adding a ramdisk to fstab follows:
tmpfs /path/to/mtmpfs /media/temp_part tmpfs uid=eugene,size=2048M 0 0
Applying this, using the same locations as in the previous example would be:
tmpfs /media/temp_part tmpfs uid=eugene,size=2048M 0 0
For more about tmpfs, see Wikipedia.