nfs local caching with fscache and cachefilesd on Lenny
Table of Contents
The idea is to put a caching layer between filesystems, that tend to be slow, and the user, who is impatient. This is accomplished by the fscache kernel module, and the cachefilesd user space daemon. The kernel module intercepts what would be disk/network access and redirects it to the daemon. The daemon uses local media, which supposedly is faster, to cache recent data.
The new Linux native implementation is very generic, and can be used to accelerate anything like floppies and CD-ROMs. I am interested in this because I find NFS slow.
Read more about it at Linux Magazine.
I must come clean. I don’t yet know how well this all works. But I have really high expectations.
building kernel #
-
build a v2.6.30 kernel that supports fscache and nfs local caching
Here is what I put in my
.configfile:CONFIG_FSCACHE=m CONFIG_FSCACHE_STATS=y CONFIG_FSCACHE_HISTOGRAM=y CONFIG_CACHEFILES=m CONFIG_CACHEFILES_HISTOGRAM=y ... CONFIG_NFS_FSCACHE=yThis step is not debian specific. I’ll skip the boring details. If you need help with building a kernel, google for it :)
building debs #
If you’re on Sqeeze, you might be able to skip this building section and just install the debs from Squeeze. However, because Lenny doesn’t come with support for fscache you’ll have to do the following:
-
build a
cachefilesd(you don’t have to build as root)
This is pretty easy on Debian. You need to add
deb-srcfromtestinginto your/etc/apt/sources.list…# grep deb-src /etc/apt/sources.list deb-src http://ftp.debian.org/debian/ testing main contribThen download the index:
# sudo apt-get updateInstall dependencies for the build:
# sudo apt-get build-dep cachefilesdGet the daemon source package:
# apt-get source cachefilesdBuild:
# cd cachefilesd-*/ # dpkg-buildpackage -bInstall:
# cd .. # sudo dpkg -i cachefilesd_*_*.deb -
build the new
mount.nfscommand (from nfs-common):(again, don’t build as root)
Install dependencies for the build:
# sudo apt-get build-dep nfs-utilsGet the daemon source package:
# apt-get source nfs-utilsBuild:
# cd nfs-utils-*/ # dpkg-buildpackage -bInstall:
# cd .. # sudo dpkg -i nfs-*_*_*.deb
configure #
Now you have all the software ready, you just have to enable it.
-
remount the hard disk that
/var/cacheis on withdir_index,user_xattroptions:# mount -o remount,dir_index,user_xattr /( note that for you it may be another location, not
/) -
enable the daemon
# sed -i -e 's/^#RUN=yes/RUN=yes/' /etc/default/cachefilesd # /etc/init.d/cachefilesd start -
remount the nfs filesystems with the fsc option
# mount | awk '/type nfs/ { print $3 }' | xargs -n1 mount -o remount,fsc( this may not work for you, it’s been inconsitent for me; remounting the directory cleanly, or rebooting should work if you follow the next step )
-
modify
/etc/fstabto make things persistent:-
add the
fscflag to the nfs mounts -
add the
dir_index,user_xattrto the filesystem that holds/var/cache
-
Does it work? #
-
the only proof I have of it working is that it’s wasting space on my local disk when I use NFS :)
# du /var/cache/fscache/ -s 40 /var/cache/fscache/ -
and doing
cat * >/dev/nulldoes seem faster, even after a clean remount