0

My PC has swappiness set to 60.

cat /proc/sys/vm/swappiness
60

Even so, swap only occurred when the PC runs out of RAM. So, every time I fill the RAM, it stops responding for a while while it is swapping into its HDD.

I thought that with swappiness of 60, proximately 60% of (full size of) RAM would be mirrored on swap so it is already there when needed to be swapped out... But that is not what I am experiencing.

I've read the manual and many different answers here but none is about having swappiness on the right value and swap not occurring until the very last moment.

Contents of free -h

              total        used        free      shared  buff/cache   available
Mem:            15G        9,9G        266M        4,7G        5,4G        508M
Swap:           30G        3,2G         27G

swapon:

NAME      TYPE       SIZE USED PRIO
/dev/dm-1 partition 30,5G 3,5G   -2
brunoais
  • 165

2 Answers2

2

Your free -h shows...

              total        used        free      shared  buff/cache   available
Mem:            15G        9,9G        266M        4,7G        5,4G        508M
Swap:           30G        3,2G         27G

indicates that you have enough RAM and SWAP (you ARE using hibernation).

Tuning your system with regards to swap is a tricky procedure.

It involves:

  • how much RAM you have
  • how much SWAP you have
  • whether swap if FILE based or PARTITION based
  • what applications you run and how much RAM they use
  • whether you use hiberation, or not

Setting up appropriate swap space is open for large debate. GENERALLY speaking, swap space should be 50-120% of total RAM. Larger amounts of swap are used in a hibernation configuration.

Assuming that you have enough RAM and swap, vm.swappiness is a parameter that you can adjust to optimize the use of RAM vs swap. To see your current setting:

sudo sysctl vm.swappiness

it's normally set to 60.

To temporarily change this setting:

sudo sysctl vm.swappiness=nn

where nn=0 to 100.

Lower settings make more use of RAM and less swapping. Higher settings reduce RAM use and increase swapping.

After determining the optimum value for your configuration, to set it permanently, edit /etc/sysctl.conf. Add this value to the bottom of the file:

vm.swappiness=90

we've determined that 90 is a good value for your use. This setting MAY slow down your system a bit, as swapping is based on slow disk I/O.

then reboot.

heynnema
  • 73,649
0

Swappiness is just a parameter that the kernel uses to calculate a swap tendency. I read the manual and I was unable to find where it states that /proc/sys/vm/swappiness is some kind of threshold.

About this topic, Red Hat Knowledge Base states:

this parameter sets the kernel's balance between reclaiming pages from the page cache and reclaiming pages by swapping out process memory

Also, another answer in Ask Ubuntu states:

Swapping is a slow and costly operation, so the system avoids it unless it calculates that the trade-off in cache performance will make up for it overall, or if it's necessary to avoid killing processes.

A lot of the time people will look at their system that is thrashing the disk heavily and using a lot of swap space and blame swapping for it. That's the wrong approach to take. If swapping ever reaches this extreme, it means that swapping is your system's attempt to deal with low memory problems, not the cause of the problem.

Hence, I think you are working on a misconception about how swap and swappiness works.