To swap or not to swap?

I recall seeing something to the effect that a swap partition on a Pi was not helpful due to the manner in which the arm processor manages memory or something of the sort. I am not using much of the SSD I have set up as a root partition on my RPi3 so I was wondering what the expert opinion was on this topic. !G of memory isn’t much…does swap on a USB connected SSD do much more?

Hi @wh7qq,

this guy says use a little not a lot?:

Now a little bit of swap is good, a lot isn’t, so we should add in a little bit of swap, however if running Wheezy, then note that you don’t need to do this as it is already using the dphys-swapfile’ package.

https://projects.drogon.net/raspberry-pi/initial-setup1/

I should point out that the link is old (ish) so it may not now apply?. :smiley:

Dphys-swapfile should then put the swapfile in the root directory which is already on the SSD, so a separate swapfile or swap partition would be redundant or useless. Is uMate for the Rpi using this as I have been unable to find a swapfile in my root directory.

Edit:
According to apt-cache policy, dphys-swapfile has an installation candidate but is not installed in uMate for the RPi. So the question becomes, should it be installed or not?

Swap isn’t created by default, for the simple reason of wearing out the SD card and degrading performance.

See these posts:

Based mostly on the above, I decided to try running a swap partition. I repartitioned the SSD with gparted on a different computer running linux and made the necessary changes to /etc/fstab and now the swap partition is in place and is recognized by htop. It does not seem to make a big difference in performance but I have not really extended my memory usage to test it. I did run into some problems trying to run smartctl on the SSD and after much digging found that my Sabrent SATA SSD to USB adapter requires the " -d sat" parameter to be set as in sudo smartctl -d sat -x /dev/sda. Otherwise smartctl fails to recognize the SSD.

A bit of further testing, with 6 windows open in Firefox, I am not seeing the bogging down that I did before adding the swap partition. This would seem to be a good move when using an SSD with the RPi. Htop is showing the swap partition in use so it is definitely working.

Beware that if the system needs to swap a lot (if low on memory a lot), this could wear out the SSD’s limited write cycles. The advantage as you’ve proved with an SSD is that they’re very fast at read/writing like RAM, so performance won’t suffer that much then a mechanical HDD and the SD card.

When the system needs to swap on systems with bottlenecked I/O (i.e. the SD card), that’s where swap probably is a bad idea.

2 Likes

From watching htop a lot during my browsing, swap is rarely used unless I open a lot of tabs so it probably won’t get hit that hard most of the time.