Move Chromium's Cache to MFS Memory Disk on FreeBSD

It is possible to use FreeBSD’s MFS Memory Disk to speed up access times of cached web objects.

From md(4):

The md driver provides support for four kinds of memory backed virtual disks:

swap:
Backing store is allocated from buffer memory. Pages get pushed out to the swap when the system is under memory pressure, otherwise they stay in the operating memory. Using swap backing is generally preferable over malloc backing.

Chromium’s cache is at $HOME/.cache/chromium, and so, my /etc/fstab contains:

1
2
3
# 256M mfs for google chrome
/dev/md0 /home/ootput/.cache/chromium mfs rw,-s256m,-wootput:ootput,noauto 2 0

From mount_mfs(8):

-s256m specifies a memory reservation of 256 M;

-wootput:ootput hands ownership of the mountpoint from root to the user; and

noauto prevents the system from failing to boot properly if the mountpoint does not (yet) exist.

The following additions to /etc/rc.conf were also made:

1
2
3
4
mdconfig_md0="-t swap -s 256m"
mdconfig_md0_owner="ootput:ootput"
mdconfig_md0_perms="1777"

which lists arguments to mdconfig(8) for device md0.

At mininum the -t type must be specified and either a -s size for malloc or swap backed md(4) devices or a -f file for vnode backed md(4) devices.

The redundancies found in fstab and rc.conf allows automatic mounting at boot, or manual mounting after boot.

To test the changes made, as root:

# /etc/rc.d/mdconfig restart

On to the $USER/bin/pack_chrome executable script that will both mount the md device, and/or sync contents from the cache at RAM to a backup cache on the HDD:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/local/bin/bash
CACHE="$HOME/.cache/chromium"
BACKUP="$CACHE.bak"
for DIR in $CACHE $BACKUP; do
if [ ! -d "${DIR}" ]; then
mkdir -p ${DIR}
fi
done
if test -z "$(/sbin/mount | grep -F "$CACHE" )"; then
sudo /sbin/mount "$CACHE"
fi
if test -f "$CACHE/.synced"; then
rsync --exclude '.synced' --exclude '.snap' --delete -avrPx
"$CACHE/" "$BACKUP"
else
rsync --delete -avrPx "$BACKUP/" "$CACHE"
touch "$CACHE/.synced"
fi

The script requires that the $USER is in sudoers(5), and is able to use the /sbin/mount command.

Finally, after $ crontab -e:

1
2
*/30 * * * * $HOME/bin/pack_chrome >/dev/null 2>&1

.. and the script gets called every half-hour by cron to automate the syncing process. This also requires that $USER is specifically allowed in /var/cron/allow.

Flash and Java for Google Chromium in FreeBSD 8

According to the official FreeBSD handbook (Ch 7.2 Browsers), perform the following steps to have a Java and Flash capable Chromium browser for FreeBSD 8:

As root:

# portmaster www/chromium \ java/openjdk6 \ java/icedtea-web \ www/nspluginwrapper \ www/linux-f10-flashplugin10

Then:

# mkdir -p /usr/local/share/chromium/plugins

# ln -s /usr/local/lib/IcedTeaPlugin.so /usr/local/share/chromium/plugins/

# ln -s /usr/local/lib/npapi/linux-f10-flashplugin/libflashplayer.so \ /usr/local/lib/browser_plugins/

The Linux process file system, linprocfs(5) has to be mounted on /compat/linux/proc:

# mount -t linprocfs linproc /compat/linux/proc

To mount the proc fs at each system boot, in /etc/fstab, have:

1
linproc /compat/linux/proc linprocfs rw 0 0

As a user:

% nspluginwrapper -v -a -i