Create a RAM Disk in Windows

Create a RAM Disk in Windows

Category : How-to

Get Social!

ImDisk-Virtual-Disk-DriverI’ve been using RAM disks within Linux for quite some time now and I’ve blogged about it with the ramfs and tmpfs file systems. I’m not going to go over the details of a RAM disk again as the principle is the same on whichever operating system you choose; you set aside a portion of RAM to use as a file system.

Currently I’m using Windows 7 at work instead of my usual Linux based OS’s and so my usual out of the box mounting of a RAM Disk simply won’t work. After a spot of Googling I came across ImDisk which promises to be an Open Source Windows Virtual Disk driver (as well as a few other things). I’m not plugging ImDisk specifically, but they do seem to do what I’m after – create a virtual Disk that I can use as a file system.

Installing ImDisk

Installation was quick and easy – simply download the binary from the website and give the .exe two little clicks.

ram-disk-ImDisk-Setup

I disabled a couple of things on the installer because I only want to use it as a RAM Disk driver.

ram-disk-ImDisk-desktop-iconsOnce the installation completes you’ll have two shortcuts on your desktop – that’s assuming you didn’t un-tick them during the installation!

Double click on RamDisk Configuration to create your first Windows RAM Disk and mount it at your chosen drive letter mount point. The options are pretty straight forward, such as size of RAM to use for the RAM Disk, the drive letter top use as the mount point and the format to use for the file system. There were two others that I found to be a little more interesting:

  • Allocate Memory Dynamically – will instruct the RAM Disk driver to allocate all the memory specified under Size straight away, or to only allocate the memory as it’s needed by adding files to the RAM Disk file system. By ticking this option you can keep your RAM free for your computer to use for things like file cache or other applications and it will only be used for the RAM Disk when it’s needed to store the files you save to it. Alternatively  you can un-tick it and allocate the full Size amount and reserve the memory straight from the off.
  • Use AWE physical memory – This is found on the Advanced tab and will force the OS to never page the RAM Disk content, even in the case where the OS decides it’s low on physical memory. Be careful with this setting because it will force your RAM Disk to only use physical RAM. If you set your Ram Disk Size too high you could soon run out of physical memory and cause your computer to become unstable.

ImDisk-create-ram-disk

Click OK when you’re happy with your settings to create your new RAM Disk.

RamDisk-Properties

And that’s all there is to it! You now have a fully functioning Windows RAM Disk that you can use for fast file storage. Don’t forget, anything on the Ram Disk will be lost when you restart your computer.


What is tmpfs?

Category : Knowledge

Get Social!

Linux penguinA disk drive storage is usually persistent, that is, anything that is written to it will always be there exactly as it was written until it’s deleted or modified by an application. Power failures or computer restarts will not (for the most part) effect the data on the storage disk. You are limited in size by the capacity of the disk and the read and write speed will vary depending on the type of drive you have. Generally storage drives tend to be high in capacity and slow in speed.

Does that make sense? Good. tmpfs is nothing like that. tmpfs, as the name suggests, is intended to be for temporary storage that is very quick to read and write from and does not need to persist across operating system reboots. tmpfs is used in Linux for /run/var/run and /var/lock to provide very fast access for runtime data and lock files. It is also often used for /tmp however it’s not always recommended.

tmpfs uses a combination of computer RAM and disk based SWAP space to create a filesystem, such as EXT4, that the operating system can use. Because tmpfs is located in RAM, it’s very fast to read and write data to and from it, several times faster than an SSD. As your computer runs out of RAM, some of the data in tmpfs will be flushed to the systems SWAP storage on disk. This will dramatically decrease the speed that the tmpfs can be used, but stop your computer from receiving out of memory errors.

See my other blog post on tmpfs vs ramfs for more information on tmpfs and an alternative. Or jump straight to creating your own tmpfs mount point.


The Difference Between a tmpfs and ramfs RAM Disk

Get Social!

Linux penguinThere are two file system types built into most modern Linux distributions which allow you to create a RAM based storage area which can be mounted and used link a normal folder.

Before using this type of file system you must understand the benefits and problems of memory file system in general, as well as the two different types. The two types of RAM disk file systems are tmpfs and ramfs and each type has it’s own strengths and weaknesses.

See my other post for details on how to create a RAM disk in Linux.

What is a memory based file system (RAM disk)?

A memory based file system is something which creates a storage area directly in a computers RAM as if it were a partition on a disk drive. As RAM is a volatile type of memory which means when the system is restarted or crashes the file system is lost along with all it’s data.

The major benefit to memory based file systems is that they are very fast – 10s of times faster than modern SSDs. Read and write performance is massively increased for all workload types. These types of fast storage areas are ideally suited for applications which need repetitively small data areas for caching or using as temporary space. As the data is lost when the machine reboots the data must not be  precious as even scheduling backups cannot guarantee that all the data will be replicated in the even of a system crash.

tmpfs vs. ramfs

The two main RAM based file system types in Linux are tmpfs and ramfs. ramfs is the older file system type and is largely replaced in most scenarios by tmpfs.

ramfs

ramfs creates an in memory file system which uses the same mechanism and storage space as Linux file system cache. Running the command free in Linux will show you the amount of RAM you have on your system, including the amount of file system cache in use. The below is an example of a 31GB of ram in a production server.

free -g
       total used free shared buffers cached
Mem:   31    29   2    0      0       8
-/+ buffers/cache: 20 11
Swap:  13    6    7

Currently 8GB of file system cache is in use on the system. This memory is generally used by Linux to cache recently accessed files so that the next time they are requested then can be fetched from RAM very quickly. ramfs uses this same memory and exactly the same mechanism which causes Linux to cache files with the exception that it is not removed when the memory used exceeds threshold set by the system.

ramfs file systems cannot be limited in size like a disk base file system which is limited by it’s capacity. ramfs will continue using memory storage until the system runs out of RAM and likely crashes or becomes unresponsive. This is a problem if the application writing to the file system cannot be limited in total size. Another issue is you cannot see the size of the file system in df and it can only be estimated by looking at the cached entry in free.

tmpfs

tmpfs is a more recent RAM file system which overcomes many of the drawbacks with ramfs. You can specify a size limit in tmpfs which will give a ‘disk full’ error when the limit is reached. This behaviour is exactly the same as a partition of a physical disk.

The size and used amount of space on  a tmpfs partition is also displayed in df. The below example shows an empty 512MB RAM disk.

df -h /mnt/ramdisk
Filesystem Size Used Avail Use% Mounted on
tmpfs      512M 0    512M  0%   /mnt/ramdisk

These two differences between ramfs and tmpfs make tmpfs much more manageable  however this is one major drawback; tmpfs may use SWAP space. If your system runs out of physical RAM, files in your tmpfs partitions may be written to disk based SWAP partitions and will have to be read from disk when the file is next accessed. In some environments this can be seen as a benefit as you are less likely to get out of memory exceptions as you could with ramfs because more ‘memory’ is available to use.

See my other post for details on how to create a RAM disk in Linux.


Create a RAM disk in Linux

Category : How-to

Get Social!

Linux penguinThere are many reasons for creating a memory based file system in Linux, not least of which is to provide a near zero latency and extremely fast area to story files. A prime use of a RAM disk is for application caching directories or work areas.

There are two main types of RAM disk which can be used in Linux and each have their own benefits and weaknesses:

  • ramfs
  • tmpfs

See my other post for the differences between ramfs and tmpfs.

Check the amount of free RAM you have left on your machine before creating a RAM disk. Use the Linux command free to see the unused RAM. The below is an example of a 31GB of ram in a production server.

free -g
       total used free shared buffers cached
Mem:   31    29   2    0      0       8
-/+ buffers/cache: 20 11
Swap:  13    6    7

The free command shows the amount of RAM availale on your system in addition to the amount of memory used, free and used for caching. SWAP space is also displayed and shows if your system is writing memory to disk.

Create a folder to use as a mount point for your RAM disk.

mkdir /mnt/ramdisk

Then use the mount command to create a RAM disk.

mount -t [TYPE] -o size=[SIZE] [FSTYPE] [MOUNTPOINT]

Substitute the following attirbutes for your own values:

  • [TYPE] is the type of RAM disk to use; either tmpfs or ramfs.
  • [SIZE] is the size to use for the file system. Remember that ramfs does not have a physical limit and is specified as a starting size.
  • [FSTYPE] is the type of RAM disk to use; either tmpfsramfsext4, etc.

Example:

mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk

You can add the mount entry into /etc/fstab to make the RAM disk persist over reboots. Remember however, that the data will disappear each time the machine is restarted.

vi /etc/fstab
tmpfs       /mnt/ramdisk tmpfs   nodev,nosuid,noexec,nodiratime,size=1024M   0 0

See my other post for the differences between ramfs and tmpfs.


Visit our advertisers

Quick Poll

Do you use GlusterFS in your workplace?

Visit our advertisers