LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Blogs > IsaacKuo
User Name
Password

Notices


Rate this Entry

tmpfs nfs swapfile - use one computer's RAM as SWAP for another computer

Posted 10-13-2016 at 10:51 AM by IsaacKuo
Updated 10-13-2016 at 02:11 PM by IsaacKuo

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.

Code:
10.42.0.1:/srv/tmpsh  /srv/tmpsh  nfs   auto,rw   0 1
/srv/tmpsh/swapfile   none        swap  sw        0 0
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:

Code:
none /srv/tmpsh tmpfs size=95% 0 0
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.

Code:
/srv/tmpsh/      10.42.0.0/24(rw,fsid=1,sync,no_root_squash)
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:

Code:
dd if=/dev/zero of=/srv/tmpsh/swapfile bs=1024 count=1024000
chmod 600          /srv/tmpsh/swapfile
mkswap             /srv/tmpsh/swapfile

exit 0
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.
Posted in Uncategorized
Views 3828 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration