Second Life cache in memory under Linux

I just had a conversation with someone about the usefulness of using ramdisks since someone apparently had tried that out with the Second Life cache and gotten good results. To see if that would make sense under Linux I googled around and found tmpfs. While it is not actually a ramdisk it does run in memory but can also move things into swap if necessary.
Tmpfs was easy to set up and ran great, swap stayed empty as usual. Did it actually improve performance? Well, it should and it feels faster, but measuring it is not that easy, especially since the graphics card I tested this with is quite the bottleneck.

Anyway, here are two little scripts that should work fine on most systems. Disclaimer: If it makes your computer explode, it's not my fault, use at your own risk. Also, it would probably make no sense to try this if you don't have several gigabytes of ram.

Load it:

if [ -e ~/.secondlife/cache ]; then
        if [ -e ~/.secondlife/diskcache ]; then
        echo "cache and diskcache exist, can't continue, remove at least one"
        exit 1
        else
        mv ~/.secondlife/cache ~/.secondlife/diskcache
        mkdir ~/.secondlife/cache
        sudo mount -t tmpfs tmpfs -o size=1G,mode=777 ~/.secondlife/cache
        cp -a ~/.secondlife/diskcache/* ~/.secondlife/cache
        fi
else
echo "no cache directory found to transfer"
fi

Unload it:

cp -a ~/.secondlife/cache/* ~/.secondlife/diskcache
sudo umount ~/.secondlife/cache/
rm -rf ~/.secondlife/cache
mv ~/.secondlife/diskcache ~/.secondlife/cache

Just save these two on your disk and make them executable, e.g. chmod +x filename. You can change the value of 1G to whatever you prefer but it should obviously be enough to accomodate the value you set in the Viewer.

Warning: The unloading is necessary to write the cache back to disk. It would not be fatal but you would need to start your cache from scratch and that would be pretty useless.

posts: