Swap & Swappiness Explained

------------------ What is SWAP? -------------------

  • A:
    SWAP is a backup to DRAM.
    SWAP is the action of moving DRAM file's to your Hard drive.

---- How SWAP works ----

  • SWAP is a dedicated partition/file (space), created to assist the physical memory (DRAM). When the DRAM is full, or reaches the set parameters, the system will move idle App's (Process), to the SWAP space. This action frees up the DRAM. Thus running the Priority Process needed. (Making the machine preform better).

------------ What is Swappiness? ---------

  • A:
    Swappiness is the set parameters for when SWAP should happen.

----- Configuring the Swappiness: -----

  • First lets understand the parameters of swappiness values:
    Swappiness parameter values are between 0-100.

  • The higher you set the Swappiness value, the earlier SWAP will happen.
    Eg; vm.swappiness=90 will start running SWAP at 10% of DRAM usage.

  • The lower you set the Swappiness value, the Later SWAP will happen.
    Eg; vm.swappiness=10 will start running SWAP at 90% of DRAM usage.]

------------ MYTHS -----------

  • Myths:
    SWAP is not just for Older/low spec machines.
    It also plays a roll in Sleep/Suspend/Standby Mode

  • Swappiness set to (Zero) Does not Disable swap,
    It will only swap when needed, SWAP will still happen with quick peeks/spike of DRAM demand (Bottle necking), this can happen at any % of RAM usage.

----- Problems that may occur relating to SWAP: -----


  • Your machine is Lagging, a shuffling mouse cursor, little shutters, etc.

Not often, but lets say:

  • Your running your DRAM at 40% capacity, (by default this is the SWAP switching parameter on Zorin/Ubuntu-Ditro's) More so on low spec machines HDD/etc.
    If 40% DRAM usage is normally where your system runs, It would be a valid reason to increase the SWAP value, by decreasing the Swappiness value.

  • Solution: Change the Swappiness parameters. (Set SWAP at 60-80% of full DRAM) So Swappiness value would be;
    (vm.swappiness=40 or 20).

  • Note:
    It's ok to have large SWAP Space to help, but you need to understand how it works (When & where to use a large SWAP space).

-------- Hibernation issue's: -------

  • If your machine has 8Gb of DRAM & 8Gb of SWAP space. so now the machine can have up to 16GB of memory (8Gb DRAM + 8Gb SWAP).
    Let say you have 10Gb in use.
    This will not hibernate due to, 10Gb's will not fit into the 8Gb SWAP space.

So if your machine will not hibernate, or just goes to Sleep instead, the above reason may apply.

-- What happens to DRAM/SWAP on Sleep/Shutdown --

Sleep/Suspend Mode & Standby:

  • Saves your "Last state" in RAM , (due to power still being available to the system ( uses more power ))

Hibernation Mode or Shutdown:

  • Saves the "Last state" to your Hard drive ,( allows the machine to power down ( Like, Shutdown ))

11 posts were split to a new topic: Swap and Swappiness Discussion

Not sure if this is theplace to ask: When you install Zorin with the "Erase disk and install Zorin OS" option, does it create a swap partition / file?

If not, how easy is it to create one after installation?

Yes, it creates a 2gig swap file for you.

It is quite easy and a quick search on the web can bring you to multiple guides that will safely guide you through Swap File creation step by step.

A Swap Partition is a bit trickier- but also only needed if you are manually setting up Hibernation.

1 Like


Another myth:
Swappiness maxes out at 100, and that means it tries to swap everything. Swappiness is a measure of RAM usage.

In reality, swappiness is a comparison between the I/O cost of freeing memory and swapping that data to the swap drive... if you increase swappiness above 100, it'll preferentially swap before it tries 'garbage collection'.

On modern systems, swappiness maxes out at 200.

I'm currently running swappiness at 133, meaning it's approximately 33% more likely to swap excess data than to try to clean it up (and thus potentially having to close programs in a low-memory condition).

I do this because I've got three drives on three USB 3.1 drive interfaces for the swap drives (and all those swap drives have the same priority, so the data will get round-robin written)... I can swap quite fast, so there's less cost to that than closing out a program during a low-memory condition.

If you set swappiness to 100, it's just as likely to swap the data as it is to clean it up.