3

I have 2 computers and a patch cable, just a straight connection between them with no hub/switch/router/etc. I need more RAM and the other computer has lots of free RAM, how can I use its RAM as swap, over ethernet?

Both systems are running Arch Linux.

  • 3
    You can try networking them to share a filesystem to set up a remote swap file, and even try stashing the file in /dev/shm on the source host, but I have a sneaking suspicion that trying to swapon a swap file on a remote system is a recipe for disaster. – DopeGhoti Aug 4 '17 at 17:12
  • Is your Ethernet faster than your local disk? – Mark Plotnick Aug 4 '17 at 21:31
  • 1
    Probably. Especially when the local disk is in use. – SoniEx2 Aug 5 '17 at 0:49
3

First off, this is generally a bad idea. The moment that the Ethernet connection goes down (or the system providing the swap space shuts down/crashes/reboots), the system that is using the swap space will die because it can't access the swap space. You'll also see even more serious than usual performance issues when swapping (you would need 10GbE and really good NIC's to avoid this, at which point you're better off just getting more RAM).

That said, you've got a couple of options. The simplest and most reliable in my experience for stuff like this is ATAoE (ATA over Ethernet) or NBD. Unfortunately, Arch does not support ATAoE out of the box (it's a lot simpler to set up quickly than NBD, and only requires special software on the side providing the swap space), but NBD is supported. You would need to create an in-memory filesystem on the system with lots of RAM, create a swap file there, and then share that out with NBD and tell the other system to connect to it.

Using NFS to share the file would probably work also, but is likely to be more error prone and less efficient.

  • Can't I configure the swap client to block until the swap server comes back? – SoniEx2 Aug 4 '17 at 18:39
  • 1
    The moment you're sharing RAM instead of disk space, that possibility goes out the window because you can't be sure if the remote system rebooted (and thus anything you had in swap is now lost), or just had an issue with the Ethernet connection. The kernel is agnostic of this and will block indefinitely, but the moment the remote system comes back after anything but transient network issues, the first page swapped in will kill whatever program it was from because it will be empty instead of having the data that was swapped out. – Austin Hemmelgarn Aug 4 '17 at 18:43
  • I'd be ok with that. – SoniEx2 Aug 4 '17 at 19:01
  • Why create a swap file on tmpfs (I assume you mean it)? Why not just create a RAM block device with brd and export this device with nbd? Does tmpfs offer any benefit over brd? – xhienne Aug 5 '17 at 10:03
  • The big one is that files on tmpfs can be pushed out to swap if memory is low, whereas blocks on brd devices can't. There are also some advantages related to handling of memory fragmentation. Alternatively to both, if Arch supports ZRAM block devices (not sure if they do, and can't get to my Arch reference system right now, the module name is zram), that would save space, and might actually perform better than putting the file on tmpfs. – Austin Hemmelgarn Aug 5 '17 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.