I run various RPi2 configurations for different applications. I am always interested in finding ways to improve performance. The general consensus is that running a swap file on the RPi will degrade the life of the SD card quicker. Mainly for this reason I run most RPi configurations with the SD just as the boot partition and then have the OS partition running from a good quality USB3 stick.

I realise that the RPi does not have USB3 ports, but for only an extra couple of dollars it still seems to make a difference in performance vs a USB2 stick, possibly because the USB3 stick can utilize the max speed of the RPi USB port.

Regardless of which type of USB stick is used, I am led to believe that running the dphys-swapfile enabled should be more suited to running on a USB OS partition than the normal SD card OS partition. To date this works as a very good solution for me to obtain a good performance boost.

Is there any possible further improvement to be gained either in performance or USB life by using zram on the USB OS partition instead of dphys-swapfile?

  • 1
    I disable swap completely. What are you doing that needs a swap file? It sounds like the Pi is a poor choice for your application,
    – joan
    Commented Aug 7, 2015 at 16:30
  • 2
    I don't have one single application. I have maybe 10 PIs that I use for testing, learning, experimentation, entertainment, automation and remote access tools. Some examples, Kodi with OpenHAB integration, VPN Server, remote desktop access point using Hamachi, web server lamp stack running Drupal and RPI monitor, NFS and FTP server attached to network cameras, syncthing server, WeeWX server. The RPi2 is an amazing device that handles multi tasking applications very well but sometimes there can be spikes in memory usage where a swap file can be useful.
    – Matsta
    Commented Aug 7, 2015 at 17:04
  • Get an Odroid XU4 with more ram and USB3 if you are running into the limitations of the rpi Commented May 20, 2018 at 4:37

2 Answers 2


This question has already been well addressed as far as defining when swap on RPi is usefull vs when it would be considered thrashing. Here's a quote from a memebr of the RaspberryPi forums "Heater" because they've stated it clearly;

https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=13780 A swap partition is not designed to enhance performance and if your program/data is constantly being swapped from RAM to swap space performance will slow by a factor of hundreds or thousands. This would be called "thrashing".

What the swap technique does is help run a lot of programs in limited RAM space reducing the possibility of an "out of memory" failure. This might be useful in a multi-user system or other server system. Imagine a hundred people logged in and editing some files, they are all working quite slowly and the overhead of swapping from one users data to another as needed may be quite acceptable.

In that way swap helps performance by not having things crash out when they run out of memory!

As has been said before I would not put a swap partition on an SD or USB stick because it is slow and for fear of wearing it out.

That being stated I'll direct my energies towords helping you gain a bit more speed and reliobilaty as well as some suggestions for things you may not have heard of.

Here's a guide on RAID setup on how to squeez a bit more performance out of the dirves that you plan on sacrificing as well as the drives used to store data you wish to keep RAID on RPI with encryption support.

However some things to note about this guide that you'll want to modify;

  • leave off encryption if you don't need it; espechially for the swap partition as this would require more recources from the RPi.

  • don't use the swap USB RAID drives for anything else other than swap. Keep these devices marked some how so that they don't get used by some one else that may expect reliability.

    • USB thumb drives and SD cards where not originally designed to handle the constant abuse that swap will put'em through. Keeping it off the SD card is a good start as elinux.org had this to say about the RPi's through-put on SD cards

    maximum throughput of the card reader of the Raspberry Pi is 25 MB/s and that most likely read and write speed won't exceed 22 MB/s.

  • If moving your OS's folder structure to a USB RAID too then keep these RAID drives seperately marked to avoid mixing them up with swap used drives.

Speed performace with RAID on RPi (from the resurch I've already done) only seems to provide a boost to the first two drives. However most build use USB hubs to attach thier drives so hooking two drives per hub and the using multiple hubs directly attached to the RPi may give you even more of a boost... maybe... Or you could try hooking the USB drives directly to the RPi (the modle B has 4 ports) and cut the hub's interfence and speed constraints out of the equasion entirly.

USB read write speeds will be limited by the through-put of the slowest link in the trasfer chain; this includes any plasebo effect that you may have expereanced with 3.0 USB drives. So if using a USB hub then the max through put is the port that it is connected to as well as being limited by the amount of free resources your RPi has for trasfering files.

If you have a spicific task or directory structue to be accessable even faster consider chaining more than one RPi togeather in what is know as a bramble stack; hint search on the YouTubes for an author named TinkerNut, they've a quick two parter on the subject that is great! by using more than one RPi with each having the above sugested boosts your maximum through put would be more limited by the ethernet networking caps of the RPi and attached router.

If you wish to run these RPi for extened periods of time without need of replacing the drives consider solid state or the clasic hard drives for better relioblaty. And I would also advise making a cron job script that backs up improtant files that change to a compleatly seperate device; just to be safe.


First of all, you're confusing zram with swap. zram is basically a compressed version of RAM, and it is still in RAM. Swap, on the other hand, resides in the disk and is utterly slow.

In other words, zram is a compressed swap file that's still placed on RAM. There's no such thing as "zram on the OS partition/disk/dphys-whatever". It's still on the system memory, although in a compressed form. I'm sure you already know what a swap file is, so I won't bother explaining.

No, zram will not help with performance whatsoever except when the Pi is getting low on memory. Then, it will start compressing RAM. If system memory still runs out despite compression, swapping kicks in (based on your vm.swappiness value).

What I would do is:

  1. Disable ZRAM altogether (IMO, it won't help unless you like wasting CPU power)
  2. Check that everything running on the Pi consumes less than 1GB of memory total
    • Since if you were using more than 1GB of memory all the time, the Pi is not your best machine and you should probably get something else
  3. Allocate a generous amount of swap (for the worst case to prevent an OS crash)
  4. Set the vm.swappiness value really low so the Pi only uses the swap file in dire situations

With this setup, you're not wasting CPU power compressing RAM but you still have something to work with in the event that memory does run out.

Note: I'm using RAM and memory interchangeably.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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