2

I have read in many places that increasing your swap file size, or making a big swap partition; can boost the memory of your system as temporary files can go there instead of in RAM. However, on Raspberry Pis, it is advised against creating a swap on the SD card as it can wear it out - SDs weren't designed for RAM-style usage. It is also advised not to create swaps on SSDs or flash storage you plug in, as it can likewise wear it out.

A very good option I thought of is to create the swap on a high-RPM HDD, as they can be written to many more times over than an SSD. However, when building a cluster of 16 or so Pis that I am doing, it is really not cost effective or practical to buy a HDD drive, and SATA-USB adapter, for every Pi. It would also use tons of power.

So my question is: Can I create a swap file (or swap partition) on another machine? If possible, I would like to do a few per machine so, with 16 Pis, I only need 4 "Swap machines" (and then 4 hard drives and adapters are fine). Connect them all via a Gigabit switch, and... bob's your uncle? ???

Is this even possible? Can it be done? I am willing to spend lots of time on this, so it doesn't need to be easy. Secondly, will it actually degrade the performance of my Pi if it takes, say, 20ms to get a few KB of data and a second to get a MB?

  • Network swap is a bad idea. Have you done any benchmarking to see if you even need separate swap partitions (ie. what makes you think you need a swap in the first place)? – stevieb Feb 25 at 17:19
  • I may be working on tasks that require a lot of "stuff" stored in memory, but only being accessed every 10 or so seconds. Thank you for your help, though. – PrinceOfCreation Feb 25 at 17:21
  • This sounds like premature optimization. I'd put my time into getting everything working, then doing actual tests to see if you do run into any issues or not. If you're running into severe issues, that's the time to consider other options. – stevieb Feb 25 at 17:23
  • Thank you, you're right I realise. I am just preparing for the worst, and it seems like I won't need my preparations. After all, the 3B+ (the one I'm going to use) does have a gig of memory! – PrinceOfCreation Feb 25 at 17:27
  • 1
    @goldilocks I agree with you there. In all honesty, I have one Raspberry Pi that has a dedicated hardware platform that tests all of the functionality of my RPi::WiringPi Perl series of distributions in a CI fashion (pulls from Github every 10 minutes and runs the gamut of my unit tests). There is a LOT of disk-IO happening when many of these tests are done, and this system has been running for the most part for nearly two years. This is all on a Kingston 32GB SD card. – stevieb Feb 25 at 19:00
3

Network swap is a bad idea. The whole purpose of swap is to replace memory, but it's only feasible if this is done locally.

I believe you're going through some premature optimization. I'd put my time into getting everything working, then doing actual tests to see if you do run into any issues or not. If you're running into severe issues, that's the time to consider other options.

If you do have issues after your testing, you could build a proper server with tons of RAM and CPU power, and shovel high memory tasks to this server, then the RPi can decide what to do based on what is returned from the server.

Swapping over network will slow things down drastically (and I'm not even sure if modern OSs would allow this).

So, in essence, my advice is to build up as many scenarios as you can think of, test it by monitoring RAM (and CPU) use, and if you do in fact have a severe bottleneck, investigate your other options (I'm not even sure that USB->SSD would work that well, but I've never tested it).

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.