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