Ram Disk

From ConShell
Jump to navigation Jump to search

About

A "RAM Disk" can give a major performance boost under the right circumstances, namely speedy access to volatile data that is write-heavy and doesn't need to persist across reboots.

Linux

tmpfs is an incarnation of RAM disk on Linux.

Current Linux distros typically mount one or more tmpfs automatically.

Debian/Ubuntu

$ df -k /run
Filesystem     1K-blocks  Used Available Use% Mounted on
tmpfs             401168  1236    399932   1% /run

$ mount | grep tmpfs
none on /sys/fs/cgroup type tmpfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)


RedHat/CentOS

# uname -a
Linux centos5.mdf2.loc 2.6.18-371.3.1.el5 #1 SMP Thu Dec 5 12:47:01 EST 2013 i686 i686 i386 GNU/Linux

# df -k /dev/shm
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                   257428         0    257428   0% /dev/shm

# mount | grep tmpfs
tmpfs on /dev/shm type tmpfs (rw)


Options

Here's an excerpt from mount(8) man page.

Mount options for tmpfs
       size=nbytes
              Override default maximum size of the filesystem.   The  size  is
              given  in bytes, and rounded up to entire pages.  The default is
              half of the memory. The size parameter also accepts a  suffix  %
              to limit this tmpfs instance to that percentage of your physical
              RAM: the default, when neither size nor nr_blocks is  specified,
              is size=50%

       nr_blocks=
              The same as size, but in blocks of PAGE_CACHE_SIZE

       nr_inodes=
              The  maximum  number of inodes for this instance. The default is
              half of the number of your physical RAM pages, or (on a  machine
              with  highmem)  the number of lowmem RAM pages, whichever is the
              lower.

       The tmpfs mount options for sizing ( size,  nr_blocks,  and  nr_inodes)
       accept  a  suffix k, m or g for Ki, Mi, Gi (binary kilo, mega and giga)
       and can be changed on remount.

       mode=  Set initial permissions of the root directory.

       uid=   The user id.

       gid=   The group id.

FreeBSD

Under FreeBSD a ram disk can be created using mdconfig.

See http://ryanbowlby.com/blog/2009/09/30/freebsd-ramdisk-mdconfig/ for a nice write-up.

Options

See mdconfig(8) and md(4) man pages for options.