Spider.007
Posts: 34
Joined: Sat May 19, 2012 11:24 am
Contact: Website

Tip: Swap over nfs

Thu Jun 07, 2012 8:39 am

I needed some extra memory to compile xbmc, and since the sd-card is slower than my nfs-mount, I wanted to try and get a swapfile setup over nfs. It didn't work without some tweaking (you need to setup a loop device as wrapper for it to work), so for anyone interested I'll post the commands here:

Code: Select all

# create a swapfile of 512 MiB
dd if=/dev/zero of=/mnt/nfs/swapfile bs=1M count=512
# setup a loopdevice to that file
losetup /dev/loop0 /mnt/nfs/swapfile
# use the loop-device to turn the file into swap, and use it
mkswap /dev/loop0
swapon /dev/loop0
I use /mnt/nfs/ here, but you may use any directory where you mounted an NFS drive obviously.

User avatar
geep999
Posts: 28
Joined: Fri May 18, 2012 10:20 pm
Location: East Herts, UK
Contact: Website

Re: Tip: Swap over nfs

Fri Jun 08, 2012 2:46 pm

Neat. It works for me. I put the commands into /etc/rc.local just above the "exit 0" so it's there after every boot.
My actual commands are:

Code: Select all

echo "Setting up swap file over nfs to /space5/raspberry.pi/swap/swapfile on dad 192.168.1.1)"
mount /space5
sleep 2
losetup /dev/loop0 /space5/raspberry.pi/swap/swapfile
mkswap /dev/loop0
swapon /dev/loop0
and in /etc/fstab I have the line:

Code: Select all

dad:/space5     /space5         nfs      noauto,user,rw,exec   0   0
having already created the directory /space5 in /. The sleep 2 may not be necesary, but in the past I remember problems unless I waited a tad for things to settle down.

Cheers,
Peter

tawalker
Posts: 183
Joined: Tue Jan 17, 2012 9:02 am
Contact: Website

Re: Tip: Swap over nfs

Mon Jun 11, 2012 3:35 pm

I'd be interested to try this. My Pi generally stays in our house and is always connected to our home LAN (via Ethernet), and is already mounting four NFS shares from our Synology NAS box (no problems at all there), so I imagine swap over NFS is feasible.

Only thing I'm not sure about: would the access be fast enough? We're still using HomePlugs* at 200Mbps (hahahahahaha, oh stop it, you're killing me :x ), which in reality aren't massively faster than our equally glacial broadband. Would the access be anything like fast enough to make swap-over-NFS a less-than-painful experience?

* - Yes, yes, I know HomePlugs are horrid and make radio amateurs' lives a misery. I'd thread Cat5e (Gigabit) cables throughout our house tomorrow if I could do it without breaking (a) the bank and (b) our paper-thin plasterboard walls, and (c) working out how to run the cable between the floors without it being visible... but that's a rant for another time/place ;)
---
Raspberry Pi Model 3B+ (2019) ("ayeka") - CentOS
Raspberry Pi Zero W (2018) ("mass") - Raspbian
Raspberry Pi Model B (1st-gen - 2012) ("ryo-ohki") - Arch Linux ARM
---

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Tip: Swap over nfs

Tue Jun 12, 2012 1:53 am

tawalker wrote:I'd thread Cat5e (Gigabit) cables throughout our house tomorrow if I could do it without breaking (a) the bank and (b) our paper-thin plasterboard walls, and (c) working out how to run the cable between the floors without it being visible...
http://www.avforums.com/forums/intercon ... pipes.html :?:

Spider.007
Posts: 34
Joined: Sat May 19, 2012 11:24 am
Contact: Website

Re: Tip: Swap over nfs

Wed Jun 13, 2012 5:52 pm

It's very difficult to predict the performance for a setup of swap over NFS. I have a properly wired GBit network with a fast file-server on the other end, but in my experience Homeplug networks rarely offer the performance they promise.

On the other hand, the sd-card is so slow that even ~ 40 MBit would probably improve the situation...

Return to “Advanced users”