Today 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
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.
- How to easily record your screen on Linux
- Bitdefender a good antivirus for Linux systems
- Apotheon: A heroic action game released for Linux
Find me on Google+