I figured out how make the Raspberry Pi swap to a network storage device. Basically, I create and mount a disk image on the network storage and then create and use a swapfile on that disk image:
mount -t cifs //storageserver/myShare /media/remote
truncate --size=2G /media/remote/raspberry.img
mkfs.ext4 /media/remote/raspberry.img
mount -t ext4 -o loop /media/remote/raspberry.img /media/remotedisk
dd if=/dev/zero of=/media/remotedisk/remoteswap.swap
mkswap /media/remotedisk/remoteswap.swap
swapon /media/remotedisk/remoteswap.swap
I know, this is not the most performant way of swapping, esp. compared with local media. However, it is an easy and cheap way to prevent out-of-memory situations on the Raspberry Pi.
The real questions are:
- Is this a good idea in terms of stability?
- Is there even a risk that required filesystem drivers (e.g., cifs) are swapped out and create a deadlock?
- What are the stability requirements (e.g., latency) to the network and storage system?