Introduction To RAM Disks in Linux

Intro To RAM Disks in Linux

Ram Disk is a resourceful feature that let’s the user convert an unused portion of RAM into a temporary high speed disk for storing and retrieving files. The RAM disk feature is well known to the pro Linux users but remains rather unpopular among the amateurs. This post is aimed at providing an introduction to RAM disks to new Linux users and the procedure for creating one on most Linux distributions. A detailed definition of RAM disk is available here.

What is a RAM disk?

Like discussed before, RAM disk is a portion of the unused RAM that is converted to a temporary virtual disk. RAM being faster than any hard disk and most SSDs, will provide very high data transfer rates at no extra cost.

Advantages of Using a RAM Disk

  • Upto 200 Times Faster Than Typical Hard Disks
  • No Extra Hardware Required
  • Easy to Setup
  • Reversible

Disadvantages of Using a RAM Disk

  • Volatile (Temporary)
  • Can Affect System Performance as It Occupies a Portion of System Memory
  • Size is Limited and Usually Small

Uses of RAM Disks

RAM Disks can come in handy at a variety of scenarios. Here are a few of the uses of RAM disks to begin with

  • Running Virtual Machines (Enhances Performance of VMs)
  • Gaming
  • Rendering Videos
  • Compression of Large Files

Filesystems For RAM disks

There are multiple filesystems available in Linux for RAM disks. The most important ones are:

  1. ramfs
  2. tmpfs

RAMFS

ramfs being an older filesystem comes with certain disadvantages, the major ones being the inability to set a memory threshold and to determine the size of the mounted RAM disk. The inability to set a memory threshold will lead to a situation where the memory consumption continues until there is no longer enough memory for the system to run and crashes.

TMPFS

tmpfs is a relatively newer filesystem that lets the user set a limit to the RAM disk as well as view the size and consumption statistics of the RAM disk. Since this is the standard filesystem for RAM disks that is being used these days, we shall stick to the tmpfs filesystem in this post.

After all that evaluation, if you’re convinced that you are ready to try it out, Here’s how you get it done.

How to create a RAM Disk on a Linux Distro

The procedure for creating a RAM disk is fairly simple and straight forward.
First, check the size of free memory on your system, using the free command

free -mh

Now, we shall create a mount point in the /mnt directory

mkdir -p /mnt/rmdsk

Next, we shall create and mount a RAM disk to /mnt/rmdsk using the following command

mount -t tmpfs -o size=8192M tmpfs /mnt/rmdsk

In the above example, I’ve created an 8GB RAM disk. Depending on your available system memory, you will have to set a custom size while creating the RAM disk.

That’s all it takes to create a RAM disk. I hope you found the post resourceful.
Feel free to leave your precious comments below.

Sreedev Kodichath

Sreedev Kodichath, a passionate software engineer, an avid blogger & an eloquent orator is the author of DevTechnica.

You may also like...

1 Response

  1. Karthikeyan N C says:

    Super da thampi

Leave a Reply

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