MD(4)

NAME
md - memory disk

SYNOPSIS
To compile this driver into the kernel, place the following line in your kernel configuration file:

device md

Alternatively, to load the driver as a module at boot time, place the following line in /boot/loader.conf:

    md_load="YES"

To specify the default maximum size of kmalloc(9) backed disks:
options MD_NSECT=20000

DESCRIPTION
The md driver provides support for two kinds of memory backed virtual disks: kmalloc(9) backed and pre-loaded module backed.

The kmalloc(9) backed disks are severely limited in size by constraints imposed by kmalloc(9). Specifically, only one malloc bucket is used, which means that all md devices with kmalloc(9) backing must share the malloc per-bucket quota. The exact size of this quota varies, in particular with the amount of RAM in the system. The exact value can be determined with vmstat(8).

A sector filled with identical bytes does not consume storage, and therefore the storage allocated by a md disk can be freed with a command such as this:

    dd if=/dev/zero of=/dev/md567

The default maximum size of a md disk backed by kmalloc(9) is 20,000 sectors of 512 bytes each. This can be changed with the kernel option MD_NSECT.

At boot time the md driver will search for pre-loaded modules of type ‘md_image’ and instantiate a md device for each of these modules. The type ‘mfs_root’ is also allowed for backward compatibility. These devices are backed by the RAM reserved by the loader(8), and as such not limited by the kmalloc(9) size constraints. However, this also means that the storage cannot be released. For the same reason, the “identical byte” detection is not applicable.

The md driver uses the “almost-clone” convention, whereby opening device number N creates device instance number N+1.

The vmstat(8) utility can be used to monitor memory usage by kmalloc(9) backed md disks, but not those backed by pre-loaded modules.

EXAMPLES
To mount a kmalloc(9) backed md device on /tmp:

    if [ -e /dev/md0 ]; then
    	newfs /dev/md0 && \
    	mount /dev/md0 /tmp && \
    	chmod 1777 /tmp
    fi

SEE ALSO
disklabel(5), disklabel(8), fdisk(8), loader(8), newfs(8), vmstat(8)

HISTORY
The md driver first appeared in FreeBSD 4.0 as a cleaner replacement for the MFS functionality previously used in PicoBSD and in the FreeBSD installation process.

AUTHORS
The md driver was written by Poul-Henning Kamp <phk@FreeBSD.org>.