Friday, January 16, 2009

RAMDisk on Solaris

What is a RAMDisk?
Consider it as your harddisk (HDD) in RAM. So you can access it just like another directory on your system only that it is much much faster since it is in RAM has no hardware disk operations.
For those who prefer the long version refer - Ram Disk on Wikipedia

Ok now that we know what it is and the advantage of having one, how do we create it?
I haven't created one on windows, don't know why would anyone want one on windows (no pun intended). On Unix, creation of a RAM Disk involves creating an in memory device, then identifying the device as a disk, then formatting that disk with a file system (FS), that the OS will understand. Here, the beauty is that we can have a different FS than the native FS of the OS.

Since this blog is more walk than's the command sequence

ramdiskadm -a ramdiskdevice 4g (create a 4 Gig RAM disk device - RDD)
ls -l /dev/ramdisk/ramdiskdevice (just to check that you can list the RDD
mkdir /opt/ramdir (the directory that will mount the RDD)
zpool create ramzfspool /dev/ramdisk/ramdiskdevice (create a pool for the FS)
zfs create ramzfspool/ramdiskdevice (lay the FS on top of the pool and format)
zfs set mountpoint=/opt/ramdir ramzfspool/ramdiskdevice (mount the FS on the dir)
chown -R user:group /opt/ramdir (change permissions so that people can access it)

*If ramdir is already created and the machine is not rebooted since the last ramdisk creation, then remove the subdirectories within the ramdir individually and start using it as a fresh RDD directory.
*If the machine is not rebooted and the ramdiskdevice (/dev/ramdisk/ramdiskdevice) exists then you do not need to re-create it.
*If you do need to re-create, then follow the procedure above, taking care that the system might hold on to the resources from its earlier creation, hence increment the numbering for the pool or the ramdiskdevice as needed by appending a number to the name.

If the system does not allow you to create a larger capacity RAMDisk, since the default limit is about 25% of physical memory, then editing the /etc/system file to add the following line will help
set ramdisk:rd_percent_physmem=40
The above line will allow allocation of 40% of physical memory for RAMDisk.

Additional Reading:
Solaris RAM Disk (Sun wiki)
Comprihensive ZFS guide from Sun (PDF)

No comments :

Powered by Blogger.