Conventional hard drives are great for storing large amounts of information at low-cost, but their speed is not that great. A SSD boosts the speed to extreme levels in comparison, but they’re still quite expensive. By storing data on a RAM disk, you can get more than the speed of an SSD, without paying the extra cost for the SSD. A RAM disk stores the information on the system memory it self, which is very fast, usually many times faster than the most expensive SSDs. This is great if you need to process a large amount of information or lots of files at great speeds. This speed increase comes from two things:
1 – The CPU can directly access the files on the RAM chips. Such can’t be done with conventional hard drives or SSDs
2 – The seek time, the time it takes to actually find where the files are located on the storage media, is inherently a lot lower on RAM chips than on mechanical hard drives.
By default Ubuntu has RAM disk that is mounted on /dev/shm/ directory. You can copy/move files to that directory and use that as the RAM disk. This is particularly useful for use-cases where you need to read or write large amounts of data fast, and further processes these. I usually use the RAM disk for reading and consolidating large amount of text divided among many files. This results in a great increase in speed for such applications.
You should not exceed the amount of RAM on your system while using this approach since it will force your PC to swap the data to the hard drive, leading to a loss of speed. System crashes might also happen when you exceed the amount of RAM in your system. It is therefore a good practice to set an upper limit of how much you can store on your RAM disk. The code below shows how this can be done.
mkdir -p /tmp/ram sudo mount -t tmpfs -o size=512M tmpfs /tmp/ram
This code snippet creates a directory, and mounts it in the RAM. The size
argument here can be adjusted to your needs.