I’ve installed a FreeBSD system using gmirror onto a couple of USB drives. I’ve noticed that there’s a considerable lag when I’m doing certain things (running top
for example). I’ve narrowed it down to the /tmp
and /var
file systems. These two file systems get written to often during normal system operation. I’ve recently aleviated this problem using the md
facility–which creates a ramdisk.
Since I’m using USB drives for the root (a d the default /tmp
and /var
), the write latency is higher than read latency. In addition, gmirror
exacerbates this tendency.
Update 2011-03-05 (again)
I now have everything contained within /etc/fstab
. /tmp
exists in memory (md
), /var
sits on USB, but a few key subdirectories of [/var] exist in memory as well. My /etc/fstab
looks like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Device Mountpoint FStype Options Dump Pass# /dev/label/swap0 none swap sw 0 0 /dev/label/swap1 none swap sw 0 0 /dev/mirror/gm0s1a / ufs rw,noatime 1 1 # orig /tmp on USB flash gmirror: # /dev/mirror/gm0s1d /tmp ufs rw,noatime 2 2 /dev/mirror/gm0s1e /var ufs rw,noatime 0 0 md /tmp mfs rw,-s32M,noatime 0 0 md /var/run mfs rw,-s32M,noatime 0 0 md /var/log mfs rw,-s256M,noatime 0 0 md /var/tmp mfs rw,-s32M,noatime 0 0 # if using rc.conf to set up md mounts: # /dev/md0 /tmp ufs rw,noatime 0 0 # /dev/md1 /var ufs rw 0 0 /dev/mirror/gm0s1f /usr ufs rw,noatime 2 2 /dev/gpt/ports /usr/ports ufs rw,noatime 2 2 |
I’ve commented out all the md-related lines in /etc/rc.conf
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# -- sysinstall generated deltas -- # Fri Jan 28 19:21:01 2011 # Created: Fri Jan 28 19:21:01 2011 # Enable network daemons for user convenience. # Please make all changes to this file, not to /etc/defaults/rc.conf. # This file now contains just the overrides from /etc/defaults/rc.conf. hostname="server" zfs_enable="YES" ifconfig_re0="DHCP polling" ipv6_enable="YES" sshd_enable="YES" samba_enable="YES" # mdconfig_md0="-t swap -s 32mm" # mdconfig_md1="-t swap -s 512m" # mdconfig_md1_cmd="mkdir -p /var/log/samba; mkdir -p /var/db/samba; mkdir -p /var/run/samba" |
Update 2011-03-05
I’ve since this concluded that most of FreeBSD expects certain things within /var to be persistent across boots (namely /var/db). I’ve since put /var back on my USB drives. However, I’ve followed the advice given here: http://www.cabstand.com/usbflash.html#flash_parts and set noatime
on my mounts, so that a read access doesn’t require a write. The system generally seems pretty responsive. My fstab
now looks like:
1 2 3 4 5 6 7 8 9 10 |
# Device Mountpoint FStype Options Dump Pass# /dev/label/swap0 none swap sw 0 0 /dev/label/swap1 none swap sw 0 0 /dev/mirror/gm0s1a / ufs rw,noatime 1 1 # /dev/mirror/gm0s1d /tmp ufs rw,noatime 2 2 /dev/mirror/gm0s1e /var ufs rw,noatime 2 2 /dev/md0 /tmp ufs rw,noatime 0 0 # /dev/md1 /var ufs rw 0 0 /dev/mirror/gm0s1f /usr ufs rw,noatime 2 2 /dev/gpt/ports /usr/ports ufs rw,noatime 2 2 |
I may go forward and make /var/run
and /var/log
md files as advised in the above link.
Update 2011-02-14
The below procedure had problems with samba. Unfortunately, samba puts a bunch of stuff in /var/log/samba
, /var/run/samba
and /var/db/samba
. Not sure why you’d want another level of indirection below each of these directories. Unfortunately, this behavior is hard-coded into the samba ports Makefile
. To get around it, you can either follow the original instructions using fstab below and modify /usr/local/etc/rc.d/samba
with:
[cce_bash]
samba_start_precmd() {
mkdir -p /var/log/samba /var/run/samba /var/run/samba
# XXX: Never delete winbindd_idmap, winbindd_cache and group_mapping
[/cce_bash]
Which ensures that the directories are created before samba is started. Or, you can use the method with rc.conf
. Either way, you’re editing two files: A)/usr/local/etc/rc.d/samba
and /etc/fstab
; or B)/etc/rc.conf
and /etc/fstab
.
Original Instructions (using fstab)
So, moving the /tmp
and /var
file systems into RAM makes things go much faster. It’s pretty easy to do so. You only have to edit /etc/fstab
.
Here’s my /etc/fstab
:
1 2 3 4 5 6 7 8 9 10 11 |
server# cat /etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/label/swap0 none swap sw 0 0 /dev/label/swap1 none swap sw 0 0 /dev/mirror/gm0s1a / ufs rw 1 1 # /dev/mirror/gm0s1d /tmp ufs rw,async 2 2 # /dev/mirror/gm0s1e /var ufs rw,async 2 2 md /tmp mfs rw,-s32m 2 0 md /var mfs rw,-s512M 2 0 /dev/mirror/gm0s1f /usr ufs rw 2 2 /dev/gpt/ports /usr/ports ufs rw 2 2 |
You can see that I labeled two new USB drives (4G each) to contain swap. I called them swap0
and swap1
. The memory-based file system will use swap as a backing store (it’ll spill over into the swap space if the system runs low on RAM).
Alternative method using /etc/rc.conf and /etc/fstab
Edit /etc/rc.conf
to look like so:
[cce_bash]
mdconfig_md0=”-t swap -s 32m”
mdconfig_md1=”-t swap -s 512m”
mdconfig_md1_cmd=”mkdir -p /var/log/samba /var/db/samba /var/run/samba”
[/cce_bash]
This instructs rc.conf (really mdconfig and mdconfig2 startup scripts) to create a md0
of size 32 MB and md1
of size 512MB. It also runs a command to create the directories samba expects (but does not create).
Unfortunately, you also have to add entries to fstab to mount the md
devices as file systems:
1 2 3 4 5 6 7 8 9 10 11 |
server% cat /etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/label/swap0 none swap sw 0 0 /dev/label/swap1 none swap sw 0 0 /dev/mirror/gm0s1a / ufs rw 1 1 # /dev/mirror/gm0s1d /tmp ufs rw,async 2 2 # /dev/mirror/gm0s1e /var ufs rw,async 2 2 /dev/md0 /tmp ufs rw 0 0 /dev/md1 /var ufs rw 0 0 /dev/mirror/gm0s1f /usr ufs rw 2 2 /dev/gpt/ports /usr/ports ufs rw 2 2 |
Fixing portsnap
One problem with the above is that portsnap
tends to dump things to /var/db/portsnap
. Since /var
is now in a memory file system, it’ll get cleared on each reboot. Instead, I now store portsnap fetches in /usr/local/portsnap
. (This is the default if you install portsnap
from the ports collection, but the base install of FreeBSD includes a portsnap
which stores it in /var/db/portsnap
.)
To make this change, I edited /etc/portsnap.conf
:
[cc_bash]
# Default directory where compressed snapshots are stored.
# WORKDIR=/var/db/portsnap
WORKDIR=/usr/local/portsnap
[/cc_bash]
One Comment