Tags:
Linux,
Python,
RAM,
RAM disk,
RAM drive,
RAMdisk,
RAMdrive,
rdmanage Posted under
Programming,
Server,
Technology,
Tutorial by
Zebedee Pedersen on July 10th, 2011.
8 Comments »

I’m currently developing a piece of server software which needs to be able to create, modify, serve up and dispose of many temporary files many times every second. Because a great number of I/O operations will be occurring, the program requires very rapid disk access – ideally, it would run on a RAID array or a solid-state disk. Because the server I’m using doesn’t have either, I’m using RAM disks as a substitute.
RAM disks take a portion of your system RAM memory and make it available for storage by mounting it in your file system. Using a RAM disk, you gain a working folder with speed way far in excess of any hard disk or even solid state drive. The usual rules of RAM apply – this is volatile memory, so anything stored on a RAM disk will be erased when the power is cut – but it’s perfect for temporary file storage.
I’ve written a very simple program for Linux called ‘rdmanage’ to help create and manage RAM disks easily at the command line.
Operation:
There are three modes of operation for this program – create a new RAM disk, create a RAM disk from an existing folder, and remove existing RAM disk. As promised, the program is very simple to operate:
To create a RAM Disk:
$ ./rdmanage create [size in mb]
For example, to create a 100MB RAM disk:
$ ./rdmanage create 100
To create RAM Disk from an existing folder:
$ ./rdmanage from /path/to/folder
For example, to create a RAM disk from the folder ‘/home/randymarsh/sim’:
$ ./rdmanage from /home/randymarsh/sim
To remove an existing RAM Disk:
$ ./rdmanage remove
Notes:
- When using the ‘from folder’ mode, the maximum size of the folder is 512MB
- You will need root permissions to mount the RAM drive
- The ‘remove’ mode will commit the state of the RAM drive to disk in a folder called ‘ramdisk.contents’
- All operations will occur within the current working directory (i.e. the folder you’re presently in). To check which folder you’re in, type ‘pwd’ at the command prompt.
- Depending on how you download the program, you might have to set the file as executable:
$ chmod +x rdmanage
- If you want to check the status of your drive, it will be listed when you use the ‘df’ command
- For program help, type:
$ ./rdmanage help
Download
You can download the program by right-clicking here and selecting ‘Save As’/'Save Target As’, or if you would prefer to download straight to your Linux machine from the command line, use wget:
$ wget http://zebpedersen.co.uk/python/rdmanage
Hopefully this program can save you a bit of time creating and managing your RAM disks. Enjoy!