Make a ramdisk in swap space

Why make a ramdisk into the swap file system.
Because of its nature, everything is kept in memory but when
the memory space became to short the least used files are swapped to disk.

How to accomplish this in openBSD:
Example: Create a ramdisk manually for temporary purposes!
In this example a small ramdisk with a partition size of 512 Kbytes:
is created as follows:

mount_mfs -s 1024 /dev/wd0b /home/test

The -s flag is used to define the partition size in 512 Kbytes and in this example
/home/test is mounted to the swap space.
For more info on flags that are available look at the man pages of mount_mfs.

Question, how to make a ramdisk available at start-up?
An example: Make a website content directory available in memory after boot:
Remark: Putting web content into memory (ramdisk) will increase the
performance of the web site significant.


For this example a web content directory /var/www/htdocs is used.
This directory contains around 7.5 Megabytes of data for a small web site.
To increase the response of the web site this content must run from a ramdisk.
So lets create a new ramdisk directory '/var/www/htdocs2' which
can be used as a mount point for our ramdisk.
Then add the following entry into the /etc/fstab file
to have the ramdisk available at start-up:

/dev/wd0b /var/www/htdocs2 mfs rw,async,nodev,nosuid,-s=15360 0 0


Now the data can be copied from /var/www/htdocs to /var/www/htdocs2.
If this example is used in the real world don't forget to change the web server configuration
to the new ramdisk directory.

Back