Jul 042011
 

ramdiskToday Ram disk has saved (at least temporary) one more customer, this time we have moved his Lucene index files from a local disk to /dev/shm; I’m not so sure this is the real solution but at least this gave us better performance and some time to study his application, to see if and where there are bottlenecks.



A RAM disk or RAM drive is a block of RAM (primary storage or volatile memory) that a computer’s software is treating as if the memory were a disk drive (secondary storage).

All the modern Linux distribution use ram disk and allocate some space for it, in the following examples I’ll use Ubuntu for simplicity but these rules usually apply to all distro.

Ubuntu by default uses a half of physical memory (RAM) as ramdisk, and it is mounted onto /dev/shm, it can be used just like normal disk space (create files and folders and manipulate them with better performance rather if they were stored on the hard disk).

The performance of a RAM disk is in general orders of magnitude faster than other forms of storage media, such as an SSD, hard drive, tape drive, or optical drive. This performance gain is due to multiple factors, including access time that is greatly decreased since a RAM disk is solid state, maximum throughput and type of file system.

The file system in use, such as FAT, NTFS, USBFS, ext2, etc, uses extra accesses, reads and writes to the drive, which although small, can add up quickly, especially in the event of many small files vs. few larger files (temporary internet folders, web caches, etc).

Set limit of ram disk

As first thing you can verify the size of your ram disk with the command

df -h /dev/shm
 
Filesystem            Size  Used Avail Use% Mounted on
none                  754M  1.6M  752M   1% /dev/shm

To change this limit you must edit the file /etc/fstab and modify (or add) a line like this one:

tmpfs /dev/shm tmpfs defaults,size=512M 0 0

This will set the maximum size of /dev/shm to 512 MB; you just have to unmount and mount it.
Or you could use the remout option:

mount -o remount,size=512M /dev/shm

Conclusions

There aren’t many more things to say about the RAM disk, but the ways in which it could become very useful to use, anywhere you have a slow hard disk, or you notice a large percentage of your CPU on waiting I/O status, RAM disk may help.

In the past I have used it to put RRD files generated by a Ganglia monitor connected to around a thousand servers, another time to move the log files of Nagios, where this software performs the statistics of availability doing grep on large files (and it was not very effective).

The important thing to remember is that in case of reboot this area is totally deleted, so you have to think about a backup systems (I had a rsync running every 15 minutes to save all /dev/shm on a disk area), and a way to restore it (I had a boot script, in init.d, that copied from the disk area to /dev/shm).

So if you have enough RAM, and your problems are only related to the disks, this could solve them all.

References:

Wikipedia


Popular Posts:

flattr this!

  6 Responses to “Ram Disk on Linux”

  1. Mi ricordo il driver per la ramdisk sotto dos… quanti anni… :(

  2. Sorry, but for the most part, Linux handles both RAM and disk in an efficient manner. RAM disks can help when you run a series of apps that insists on writing to file. That is, one app creates a file. Another one reads it and writes another, and so on. Of course, if these apps were written for UNIX, using the standard of piping the stdout of one to the stdin of another, RAM disks would not be needed. Linux would manage the pipes in RAM itself.

    RAM disks under Linux, have only a limited application.

  3. I’ve written two post about using RAM disks to improve computer performance

    Firefox: http://www.go2linux.org/linux/2010/10/optimize-firefox-780

    Webserver: http://www.go2linux.org/linux/2010/10/create-ram-disk-improve-performance-webserver-791

    Thanks for the great write up.

 Leave a Reply

(required)

(required)


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>