I'm in an odd situation where I have plenty of RAM sitting around (200gb extra) and ALMOST enough SSD to do a read/write intensive process. Is there any way to say "Dear System, please create a temp virtual drive that is a combination of the RAM and SSD, so that for some of the read/write operations that are backed by the SSD they go kinda-fast, and others backed by the RAM go REALLY fast"?

  • Suggestion: Create a filesystem using ramfs and use LVM to combine it with the SSD. Or create a large file on a tmpfs, turn it into a loop device, then use LVM. No idea if it works at all or if it has any performance advantages. Mar 14 at 18:53

Well, yes, but actually no.

While it is possible to create a virtual disk in RAM, it's not handled the same way other disks are. In particular, it doesn't have a device node in /dev, so it isn't visible to features like "LVM" or "mdadm" (which could otherwise be used to join two different disks into one big virtual disk).

There is a way to kinda-sorta do what you're asking, and that's to turn your SSD into swap space, then create a big RAM disk. However, because it's a RAM disk, you won't be able to read directly from the SSD. Each block will be automatically copied into RAM when your program tries to access it, and depending on the exact nature of the process you're running, I think it's highly likely that thrashing will destroy the performance gains you hope to achieve.

If you're bound and determined to go through with this, here are the steps. (Note 1: I'm assuming your SSD is /dev/sdb. Replace this with the actual designation of your SSD drive. Note 2: This will erase your SSD. Make sure you have a copy of any important data before you begin. Note 3: You're going to be using root privileges while playing with tools that could potentially wipe your system, so be really careful, and stop immediately if anything seems even the slightest bit off.)

  1. Format your SSD for swap: sudo mkswap /dev/sdb.
  2. (Optional, but recommended) Use swapon -s to get a list of any swap areas that are currently active, and use sudo swapoff [device] to turn them off.
  3. Activate the SSD swap: sudo swapon /dev/sdb.
  4. Create a directory to mount your RAM disk: mkdir /tmp/ramdisk
  5. Create and mount the actual RAM disk: sudo mount -t tmpfs -o size=[size] myramdisk /tmp/ramdisk (You must use tmpfs for this, since ramfs doesn't use swap.)

And that's it. Now, anything you write to /tmp/ramdisk will be stored in RAM, and anything that's too big for RAM will be swapped out to your SSD. When you're done, everything you did (except formatting your SSD) will be undone by a simple reboot.

  • That sounds a) like it might work and b) like a lot of work! You got me wondering if it all might not be worth it.
    – Benjamin H
    Mar 15 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.