Swap and Swappiness Discussion

Swappiness is a comparison between the relative I/O (input/output) cost of swapping and filesystem paging.

At swappiness = 100, it considers swapping and filesystem paging to have equal I/O cost, and will thus apply memory pressure to the page cache and swap-backed pages equally. Lower values signify more expensive swap I/O, higher values signify cheaper.

So if you've got a slow spinning-rust hard drive as your swap drive, and lots of RAM, you'd want swappiness to be low (only used when you've used all the available RAM) to keep system speed higher.

If you've got a really fast hard drive setup (RAID array or ZFS mirrored drives), you'd want swappiness to be higher (I have mine set to 100, with 3 mirrored ZFS drives improving read speed and 2 mirrored SLOG drives improving write speed. Even at swappiness = 100, the system doesn't swap until it reaches the set high mark of RAM usage (which I've set as 85% of total RAM)).

If you've got your swap drive on a SSD (not recommended), you want swappiness low, to prevent bit-burnout of the SSD.

If you could somehow get your hands on a RAM-based drive on a really fast interface, or if you're running zram or zswap, you can push swappiness beyond 100, to as high as 200... that'll preferentially push data onto the (compressed) in-memory zram or zswap swapfile. The zram or zswap will fill up first, and since it's compressed, that can significantly increase the perceived memory size.

I don't believe that concern for swapping will improve PC performance in any efficient way. There would be little performance impact from swapping infrequently accessed data that would be subject to priority swapping.

1 Like

Well, it won't affect much unless you're running zswap, which sets up a RAM-based swapfile (and swaps to disk when it gets full) which is compressed.

Because it's compressed, it's more beneficial to swap than to do filesystem paging... it holds the data that was going to be swapped out to disk in memory and compresses it, so access to that data is faster.

Say you've got half your RAM set up as zswap, and say you've got 16 GB RAM. With 3:1 compression and swappiness set to 200, the machine now acts as if it's got 32 GB of RAM.

In /etc/sysctl.conf:


The settings above change the file content in /proc/sys/vm. Don't try to overwrite the files in /proc/sys/vm, just set the settings you want in /etc/sysctl.conf.

The above prevents the OS from committing memory in excess of the swap space plus 85% of RAM. That leaves enough free RAM such that you can use the system as admin to kill a memory-hogging process.

1 Like

I generally have increased the swap size from 2GB to 6GBs and have never had any issues. I would rather have a little to much than not enough. (Running off NVME SSD with default Swappiness)


In /etc/fstab:

# Set up swap drive partitions.
UUID=de1a46a0-1e14-4158-b93f-a94971d01683	none	swap	discard,noatime,pri=1	0	0
UUID=8580f890-b596-4391-ac13-b727aabd50c5	none	swap	discard,noatime,pri=1	0	0

Note the "pri=1" bits... that sets the priority for each swap partition. If two (or more) partitions have the same priority, the system will use those swap partitions in round-robin fashion. Higher-priority swap partitions will preferentially be used first.


/dev/sdb2	partition	24G		0B		1
/dev/sda2	partition	24G		0B		1

The number of swap partitions you can have has varied over the years... nowadays it's safe to say you can have up to 29.

Excellent write up, I would also add to the myths that if swap is setup correctly does it not degrade nvme drives, which can be quite controversial to hear for some folks.

1 Like

An example:

You have 8Gb of DRAM, your installing something & just for a brief time your machine needs 9Gb of DRAM, Would you rather the machine freeze & maybe corrupt you install.?
Would it be a good idea to have DRAM backup, to do the demanding task?

SWAP is a Backup for DRAM. :+1:

Hope this may help

@rolltide101x , Good work,
That's the way, adjust it until it suit's your needs :+1:

Cheers for your kind words. :slight_smile:
I remember a statement somewhere awhile back.
"You could write 20Gb a day to an SSD & the SSD should last 10yr's,"
In saying that, Over writing continually to the same sector/file, can render a part of the drive as useless.
This can be over come by creating a new sector/file,

Bottom line: your SSD's Should last around 10yr Just like thumb drives.
As a preventative maintenances, It's a good idea to swap-out your drives, every 10yr.
Just like the BIOS battery, has a life span of 5-10yrs.
Hope this may help :+1:

Such a situation can be resolved even with default settings.

There are always a workaround for most things.
As Zorin OS/Website is based on new users to Zorin/Linux.
This Tutorial is just based on, explaining what SWAP & SWAPPINESS, Is.
As are the Examples, being based on Explaining the concept of SWAP & SWAPPINESS.

This is not meant to help fix issue's or to show workarounds. Hence i tried to keep it as basic as possible for those that just want to know what is SWAP/SWAPPINESS. :+1:

Discussion portion moved to new thread to preserve the readability of the Tutorial Here.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.