Wednesday, July 9, 2014

RAM disks

So RAM disks are still around in Solaris 11.
Well, of course, they are great if used consciously, I suppose.
In other words, this means they shouldn't be abused.

The key points about RAM disks are:
 
  • They consume precious physical RAM.
    According to ramdisk(7D) they can use up to 25% of RAM;
    (as far as I suppose its pages aren't swappable)
    (perhaps ipcs(1) and pmap(1) could help as in ISM run sample 3.0)
      
  • They are ephemeral.
    (they do not persist across reboots)
      
The main CLI/shell interface is the ramdiskadm(1M) command.
Naturally, at first no RAM disks exist in the system by default:

# ramdiskadm

# ls -al /dev/ramdisk
/dev/ramdisk: No such file or directory

# swap -sh
total: 1.9G allocated + 1.8G reserved = 3.7G used, 6.8G available

 
To create a RAM disk I must specify its name and size.
If you specify a size that cannot be honored and error message is printed out.
Otherwise, the new device name associated with the disk is printed out.

# ramdiskadm -a cache-01 512m
ramdiskadm: couldn't create ramdisk "cache-01": 
Resource temporarily unavailable

# ramdiskadm -a cache-01 256m
/dev/ramdisk/cache-01


# ramdiskadm
Block Device                    Size  Removable
/dev/ramdisk/cache-01      268435456    Yes

 
# swap -sh
total: 1.9G allocated + 1.8G reserved = 3.7G used, 6.5G available


The associated block file name is:

# ls -l /dev/ramdisk
total 1
... cache-01 -> ../../devices/pseudo/ramdisk@1024:cache-01


The associated raw file name is:

# ls -l /dev/rramdisk
total 1
... cache-01 -> ../../devices/pseudo/ramdisk@1024:cache-01,raw

   
In case the RAM disk must be disposed of before the next reboot:
(perhaps a RAM shortage is taking place and space must be freed)

# ramdiskadm -d cache-01
  
As an example, a RAM disk could perhaps be used as the raw device for a temporary ZFS pool intended for some very specialized scenario.