tmpfs nfs swapfile - use one computer's RAM as SWAP for another computer
Previously, I described how to use one computer's RAM as an SSD (OS drive) for another computer. Here, I describe how to use one computer's RAM as SWAP for another computer. Bear in mind that even a RAM disk over gigabit ethernet isn't going to be as fast as a local SSD, but it's still faster and much more responsive than a local spinning hard drive.
This technique of using another computer's RAM as SWAP is a great way to augment RAMboot, as described here:
http://www.linuxquestions.org/questi...-jessie-37165/
Combined with RAMboot, using a tmpfs nfs swapfile gives you the blazing fast speed of RAMboot for when everything fits in RAM, along with the slower but still pretty fast speed of gigabit ethernet (~100MB/sec) for when less used files are offloaded into swap. Basically, the system is in high gear as long as everything fits in RAM, but it shifts to a still pretty fast low gear when RAM starts to run out.
As with my other how-to's in this blog, this is for Debian 8 Jessie.
Basically, the idea is simple - just use an nfs shared file as a swapfile. The only tricky part is figuring out how to share a tmpfs file system via nfs, and the fiddly bits for automatically creating the swap file upon boot.
STEP 1) MODIFY CLIENT FSTAB
On the client, comment out any existing swap entries (if any). You may deactivate any existing swap with swapoff -a
Add two new lines into /etc/fstab for the nfs mount and the swapfile.
Obviously, you'll want to create the mount point with mkdir /srv/tmpsh
STEP 2) MODIFY SERVER FSTAB
On the server, add a line into /etc/fstab for the nfs share:
If necessary, create the shared directory with mkdir /srv/tmpsh
Then, mount the new tmpfs ramdisk with mount /srv/tmpsh
STEP 3) MODIFY SERVER NFS EXPORTS
On the server, apt-get install nfs-kernel-server if necessary.
Restart nfs-kernel-server with systemctl restart nfs-kernel-server
STEP 4) MODIFY SERVER STARTUP SCRIPT
On the server, insert 3 lines above exit 0 in /etc/rc.local, so /etc/rc.local ends like this:
This example creates a swapfile that is 1000MB in size. That means it will eat up 1000MB of RAM in the server. Adjust according to how much RAM is available in the server, and/or how much swap you want for the client.
You can either reboot, or you can manually copy/paste those lines into a terminal. This will create the swapfile, chmod it so only root has access, and then make it a swapfile.
After swapfile is created, you can activate it on the client with swapon -a
That's it! When I did research on how to do this, I thought that I'd have to do some funny stuff with a loop device, but I guess that was outdated info.
This technique of using another computer's RAM as SWAP is a great way to augment RAMboot, as described here:
http://www.linuxquestions.org/questi...-jessie-37165/
Combined with RAMboot, using a tmpfs nfs swapfile gives you the blazing fast speed of RAMboot for when everything fits in RAM, along with the slower but still pretty fast speed of gigabit ethernet (~100MB/sec) for when less used files are offloaded into swap. Basically, the system is in high gear as long as everything fits in RAM, but it shifts to a still pretty fast low gear when RAM starts to run out.
As with my other how-to's in this blog, this is for Debian 8 Jessie.
Basically, the idea is simple - just use an nfs shared file as a swapfile. The only tricky part is figuring out how to share a tmpfs file system via nfs, and the fiddly bits for automatically creating the swap file upon boot.
STEP 1) MODIFY CLIENT FSTAB
On the client, comment out any existing swap entries (if any). You may deactivate any existing swap with swapoff -a
Add two new lines into /etc/fstab for the nfs mount and the swapfile.
Code:
10.42.0.1:/srv/tmpsh /srv/tmpsh nfs auto,rw 0 1 /srv/tmpsh/swapfile none swap sw 0 0
STEP 2) MODIFY SERVER FSTAB
On the server, add a line into /etc/fstab for the nfs share:
Code:
none /srv/tmpsh tmpfs size=95% 0 0
Then, mount the new tmpfs ramdisk with mount /srv/tmpsh
STEP 3) MODIFY SERVER NFS EXPORTS
On the server, apt-get install nfs-kernel-server if necessary.
Code:
/srv/tmpsh/ 10.42.0.0/24(rw,fsid=1,sync,no_root_squash)
STEP 4) MODIFY SERVER STARTUP SCRIPT
On the server, insert 3 lines above exit 0 in /etc/rc.local, so /etc/rc.local ends like this:
Code:
dd if=/dev/zero of=/srv/tmpsh/swapfile bs=1024 count=1024000 chmod 600 /srv/tmpsh/swapfile mkswap /srv/tmpsh/swapfile exit 0
You can either reboot, or you can manually copy/paste those lines into a terminal. This will create the swapfile, chmod it so only root has access, and then make it a swapfile.
After swapfile is created, you can activate it on the client with swapon -a
That's it! When I did research on how to do this, I thought that I'd have to do some funny stuff with a loop device, but I guess that was outdated info.
Total Comments 0