Creating RAM disc – Linux

Reading Time: 2 minutes

Since it happened to me to have this task as my homework assignment in the Telerik’s software academy Linux administration course, I decided to have this valuable knowledge shared here.

For starters lets first define RAM disc: basically we might refer to this as a RAM memory turned into a storage device instead  of random access memory.

What are the pros and cons: If we have to point the good sides of RAM memory when used as storage device there’s a point that always matters: Performance. Yes, RAM is the fastest performing memory if you need to read fast and write fast from your discs, and by fast I mean way faster than any HDD configuration, even SSD.

Here’s a small figure showing some numbers:

RAMdisc

Obviously results speak for themselves.

Bad sides: Well as we all know life’s unfair and every performance gain we have, comes on a high price, including RAM discs, too. Being a volatile memory, RAM will be completely erased and all your data – lost, if your computer powers off. So be careful keep that in mind and be prepared to store all your valuable data on your hard drives if you have plans to power off.

Here’s some quick steps to create a RAM disc on Linux.

First you need a spare RAM, that’s for sure and as you can guess if are going to make the RAM disc bigger than 4 GB you will need 64 bit OS.  You can easily check the amount of free memory with the ‘free’ command with parameters ‘-m’ for megabytes or ‘-h’ for human readable format.

See also  Today we fight back against mass surveilance

Lets say we want to create a 2 GB RAM disk. We first witch to Root:

[code language=”bash”]
$ su
# mkdir /tmp/ramdisk; chmod 777 /tmp/ramdisk
# mount -t tmpfs -o size=2048M tmpfs /tmp/ramdisk/
[/code]

 

2048 here stands for the size of RAM we want to relocate as RAM disc. Needless to say, the amount of RAM should be less than your free RAM, otherwise you will include swap memory, and that will be the end of your performance.

As a conclusion we might say using a RAM disc is really a good choice when it comes to performance and low cost but we need to be careful about what data we put in there if our machine is not powered on 24/7.

Please follow and like us:

Mr.Slavchev

Senior software engineer in testing. The views I express here are mine, they don't represent any position held by any of my employers. Experience in mobile, automation, usability and exploratory testing. Rebel-driven tester, interested in the scientific part of testing and the thinking involved. Testing troll for life. Retired gamer and a beer lover. Martial arts practitioner.

More Posts - Website

Follow Me:
LinkedIn

1 thought on “Creating RAM disc – Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.