Swap & Swappiness Explained

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

  • A:
    SWAP: is a backup for DRAM.
    SWAPPING: 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 kernel will move (called: "Swapping in" or "Paging in") idle App (Data), to the SWAP space. This action frees up the DRAM. Thus running the Priority Process/Data needed. (Making the machine perform better).

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

  • A:
    Swappiness is the set parameters/Threshold for when swapping 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/more swapping will happen.
    Eg; vm.swappiness set @ 90, will start swapping at 10% of DRAM capacity.

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

_________What happens when swapping occurs ______

  • For the example i will be playing a game online & have my email open in the background. On a 5Gb DRAM machine.
    The game uses 4Gb of DRAM, my system had shifted my 1Gb of email data to the swap file due to set swappiness value.
    While playing i received an email,
    The system then has to put the email data back in to the DRAM ( Called: swapping out or paging out),
    so you can use the email. when you resume your game, the system will swap back the email data to the swap file if needed again.

------------ MYTH -----------

  • Myth:
    SWAP is not just for Older/low spec machines.
    It also plays a roll in hibernation Mode.

  • Swappiness set to (Zero). Does not Disable swap. It will only swap when needed.
    Swapping will/can still happen at anytime due to peeks/spike of DRAM demand, 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/slow.
    If 40% DRAM usage is normally where your system runs, It would be a valid reason to increase the swapping, by decreasing the Swappiness value.

  • Solution: Change the Swappiness parameters. (Set SWAP at 50% of full DRAM) So Swappiness value would be;

  • 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.( 8Gb in DRAM +2Gb in swap file)
    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)

Hibernation Mode or Shutdown:

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

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.

Hello, what are the precise commands to check current swappiness and change it?

try looking at this