1

I think the default size of the swap file for Raspberry Pi Zero W is 100 MB. I would like to increase this in an effort to improve performance, but don't want to make it too large as the Pi Zero W has only 512 MB of ram.

Can someone help me with the suggested range of values for swap, and how to change the value?

1

You can, in theory, set the swap size to be as large as you like—or at least as large as can fit on your SD card or storage medium. There is no practical limit I'm aware of that you would hit for a Raspberry Pi in terms of swap file size—more powerful computers often have many gigabytes of swap if necessary.

As for suggested values, that depends to some extent on what you'll be doing with the Pi. If you search around you'll hear many different recommendations for swap; usually some multiple of your RAM size. The most common ones I hear are 0.5x your memory, 1x and 2x your memory. That puts you somewhere between 256 MB and 1024 MB.

If you're likely to be doing anything memory intensive (e.g. running a GUI, playing a video, running a web browser, ...) you may want to have a larger amount of swap, but if you're just using the terminal you may need less. It is worth remembering that if you run out of memory and swap space, either processes are terminated or the system crashes.

In short:

  • there is no practical limit to the amount of swap you can allocate
  • using swap is slow and best avoided, but it is usually better to swap than crash your system
  • you can configure your swap by editing /etc/dphys-swapfile.
0

A larger swap file has never helped in performance. It only helps you to the extent that your application forces other processes to be swapped out (and an idle Raspbian distro usually takes about 100MB). If your application starts to use that much memory that portions of it are going to be swapped out, your are going to run much slower but omit the out of memory force quit. The SD-Card used by the raspberry Pi is so slow that it is not practcal to have a larger swap file and expect the system to remain responsive. Also keep in mind that you are running a 32bit linux on a 32bit machine. So each process cannot exceed 4GiB of addressable memory no matter whether it is swapped out or not. Also I believe (correct me if I'm wrong) it might be even as low as 2GiB for any given process. So creating a 16GiB swap file for instance won't help you.

tl;dr Do not increase the swap file and hope to get more performance. Only increase it if you are really running out of memory.

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.