Oracle Blog

Blog for jtc

Thursday May 29, 2008

As memory access is typically orders of magnitude faster than disk access, the idea of using a part of RAM as an in-memory storage device has been one of the earliest performance optimizations realized by the computer science community. Even though today this type of optimization takes place transparently inside modern operating systems (via mechanisms like the disk buffer cache), there are still circumstances where manually creating a RAM disk might still be quite useful.

A Solaris customer using the ramdiskadm(1m) utility to create a Ram disk device for a real-time application posed the following question: "Are RAM disks swappable?". From a real-time perspective, a RAM disk not only yields significantly better seek performance but also provides for more deterministic behavior compared to the traditional rotating disk platter. The customer's concern here is that, under dire circumstances, is it possible for operating system swap out the RAM disk memory? Needless to say, if a swap out occurred it would put a big crimp in the real-time application's predictability.

To get an idea of what's going on when a RAM disk is created, let's use the Solaris kstat(1m) kernel statitics utility to see how memory is being allocated. First let's see what memory looks like before creating a RAM disk:

Let's subtract the original number of pageslocked from the latest
value and multiply by the pagesize:

# pagesize4096# bc(38988-26170)\*409652502528\^D

The increase in locked pages can be attributed to the
creation of the RAM disk (50m + a small amount of overhead). So yes, these pages are locked into memory. But it would be nice to get a definitive statement on what pageslocked actually means. According to McDougal, Mauro and Gregg's Performance and Tools: DTrace and
MDB Techniques for Solaris 10 and OpenSolaris, pageslocked is "Total number of pages locked into memory by the kernel and user processes". Furthermore, the man page for plock(3C), a related library routine which enables programmers to lock memory segments, states that "Locked segments are immune to all routine swapping". What's routine swapping?