11

Kindly tell me the difference between ramdisk and ramfs.

0

4 Answers 4

6

"RAM disk" is a device driver that merely creates block devices that store their data in memory (fixed max size, allocated gradually by need), which you can use for any purpose, e.g. create ext2 filesystem on it and then mount to some location in filesystem. Many Linux distributions are by default configured to automatically create and present these devices as /dev/ram0, /dev/ram1, ...

"ramfs" is a filesystem driver. To utilize it, you use "mount" command, just specify filesystem type (ramfs) and target directory; device is not required (e.g. "none" can be used): mount -t ramfs none /path/to/location

Regarding usage, the major difference between two is that "ramfs" reuses existing kernel caching mechanisms to store its data. In other words, when you write to "ram disk" your data is saved to memory allocated by that ram disk, plus that data is saved in RAM by kernel caching mechanism, so we get duplication here. When using ramfs, no duplication happens, as ramfs directly uses those caching mechanisms as its own (ramfs) implementation.

See also: https://www.kernel.org/doc/Documentation/blockdev/ramdisk.txt https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt

5

A RAM disk implements a virtual disk in volatile memory. A RAM filesystem implements a virtual filesystem in volatile memory.

In other words: the difference between a RAM disk and a RAM filesystem is the difference between a disk and a filesystem.

2
  • So what then is the difference between a disk and a filesystem? To me it sounds like a box and a crate -- different word, same thing. Please elaborate. Danke! Commented Dec 1, 2010 at 18:35
  • 3
    @torbengb: a disk is a physical device, i.e. hardware that stores unstructured 0s and 1s, without meaning. A filesystem is a data structure, i.e. software (very much like a database, actually -- in fact, a filesystem arguably is a database) that stores structured directories and files (and file metadata such as permissions, ownership, creation date etc.) which have actual meaning. Commented Dec 1, 2010 at 19:17
1

Ram disk is a fixed size disk in memory. RamFS is a File system in memory that can use up all the memory and cause a system crash. Other than that the performance of the 2 is very similar.

0
0

ramfs and ramdisk:

The older “ram disk” mechanism created a synthetic block device out of an area of RAM and used it as backing store for a filesystem. This block device was of fixed size, so the filesystem mounted on it was of fixed size. Using a ram disk also required unnecessarily copying memory from the fake block device into the page cache (and copying changes back out), as well as creating and destroying dentries. Plus it needed a filesystem driver (such as ext2) to format and interpret this data.

Compared to ramfs, this wastes memory (and memory bus bandwidth), creates unnecessary work for the CPU, and pollutes the CPU caches. (There are tricks to avoid this copying by playing with the page tables, but they’re unpleasantly complicated and turn out to be about as expensive as the copying anyway.) More to the point, all the work ramfs is doing has to happen anyway, since all file access goes through the page and dentry caches. The RAM disk is simply unnecessary; ramfs is internally much simpler.

Another reason ramdisks are semi-obsolete is that the introduction of loopback devices offered a more flexible and convenient way to create synthetic block devices, now from files instead of from chunks of memory. See losetup (8) for details.

Source: https://docs.kernel.org/filesystems/ramfs-rootfs-initramfs.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .