Memory File Systems


OpenBSD's memory file system, or MFS, allows you to create a "virtual hard disk" out of RAM. Essentially, you can use system memory as a hard drive. You can write files to this virtual hard disk just like any other hard disk in your system. Because files on a MFS partition are already in memory, they can be accessed with a memory-to-memory copy. This is extremely fast compared to a disk-to-memory copy. As with everything else in memory, however, you lose all data on that partition when the computer goes down or if you unmount that partition.

You can even use MFS as a "scratch" partition to compile, compress/ decompress, or manipulate files rapidly. If you have enough RAM, a MFS /usr/ obj will vastly accelerate "make build." Some people even store news server history files or database lockfiles on MFS to noticeably enhance performance.

MFS and Swap

MFS is effective in situations where the system swaps regularly. The kernel keeps any information being actively used in memory, while transferring unused information to swap. This is excellent for partitions like /tmp in which small files that are used frequently can be accessed quickly. Files that are less frequently accessed end up in swap, with performance roughly similar to standard UFS. You can even have a MFS partition larger than your physical memory, although if you run short on combined memory/swap your system will still be in deep trouble.

Creating an MFS Partition

Let's start by creating a temporary MFS partition on the command line with mount_mfs(8). Like the other mount commands, mount_mfs(8) takes two arguments, the physical device and a mount point. Memory doesn't have a device name, however, so we use the device name of the system swap space. If you have multiple swap partitions, just pick one.

 # mount_mfs /dev/wd0b /tmp/db/ 

This creates a partition of a size a little bit less than the swap space you chose as a device. It's generally a good idea to specify a maximum size on an MFS partition, so that you will have some memory and/or swap available in case the MFS partition fills up. You can specify the size with the "-s" flag, giving an argument in sectors. A sector is 512K, which isn't exactly a useful measurement these days; multiply the size of your desired MFS partition in megabytes by 2,048 to get the number of sectors. For example, a 256MB partition uses 524,288 sectors. Here, we create a 256MB /tmp/db MFS file system.

 # mount_mfs -s 524288 /dev/wd0b /tmp/db/ 

Mounting MFS Partitions at Boot

You can automatically create a MFS partition at boot time by making the proper entry in /etc/fstab. All you need is the device name of your swap partition, the mount point, and the number of sectors you want this partition to use. You'll make an entry in /etc/fstab, much like those discussed earlier, but with some minor tweaks.

 1 /dev/wd0b   2 /tmp/db   3 mfs   4 rw,async,-s=524288  5 0   6 0 

First we have the 1 device name and the 2 mount point, exactly as in an /etc/fstab entry for a standard UFS file system. The 3 file system type is MFS. Our 4 options are a little different than those used by a FFS partition, however. We can safely mount an MFS partition "async," to enhance performance, because a system crash will result in complete and total data loss on this partition anyway. You might also want "nodev" and "nosuid" options on this partition. We also specify the maximum size of the partition with the "-s" option. Make sure you have the equal sign between the -s and the number of sectors the partition fills; /etc/fstab uses spaces to separate fields, and without the equal sign you'll be dumping this disk at dump levels of 524,288 or higher!

Because the data on a MFS partition is disposable, you usually don't want to back it up, so you can set the 5 dump level to 0. And you should never have to 6 fsck(8) a MFS partition at boot, so the fsck pass number can also be zero.

This entry is the only change you have to make for a MFS partition to appear at runtime.




Absolute Openbsd(c) Unix for the Practical Paranoid
Absolute OpenBSD: Unix for the Practical Paranoid
ISBN: 1886411999
EAN: 2147483647
Year: 2005
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net