1

enter image description here

I usually sleep my laptop. After waking, the swap usage has increased.

3 Answers3

3

The problem is that you've got 8G RAM. The swap file/partition WILL be used... and in fact, you might wish to increase your swap file/partition to 4G. Changing the vm.swappiness parameter might change swap usage, but with 62% of RAM used, as in your example, you WANT it to swap.

With no swap file/partition, or with too little swap file/partition, understand that in the current example (100%-62%=)38% of unused RAM is used a disk/file buffer/cache. With no/little swap, and RAM usage increasing, and disk/file butter/cache being reduced and reduced, and OOM (Out Of Memory) process trying its hardest to keep the machine running, it'll eventually run out of resources, and with no where to go, and it'll hang/crash the computer.

heynnema
  • 70,711
  • @Melebius swap is probably the most misunderstood feature of OS's. In this case, running 8G RAM with no swap, running at 62% memory utilization, will very quickly run out of ALL RAM, and the OOM process will try and do its best to manage a full RAM situation, and the computer WILL hang, and maybe even crash. – heynnema Feb 21 '19 at 13:56
  • So do I understand you correctly that you really meant: “The problem is that you are using nearly all your RAM”? I downvoted because I found the reasoning “that you've got 8G RAM” incorrect. I’ve got a Xubuntu 16.04 VM with 1.5 GiB RAM and almost not swapping at all. I’ll remove my downvote for sure if you edit your answer with the clarification. – Melebius Feb 21 '19 at 14:05
  • 1
    @Melebius The 8G RAM came directly from their image. Understand that the "38%" of unused RAM is used a disk/file buffer/cache. With no swap, and RAM usage increasing, and disk/file butter/cache being reduced and reduced, and OOM trying its hardest to keep the machine running, it'll eventually run out of resources, with no where to go, and it'll hang/crash. Also, Xubuntu running with 1.5G RAM AND a swap file, really can't be compared here, without knowing how it's being utilized, and remember, it's a low resource OS. The OP's question was "how to reduce swap", not how to run without it. – heynnema Feb 21 '19 at 14:14
  • @Melebius and... as you can see from the image, 67% of swap is being used right now. – heynnema Feb 21 '19 at 14:17
0

Run fewer memory-using processes. Swap is used when memory requirements exceed what's available. Without sufficient swap (2*RAM is my recommendation).

waltinator
  • 36,399
  • "2*RAM" = 16G, which would be excessive, even if you were hibernating. – heynnema Feb 20 '19 at 16:54
  • 1
    Good discussion of swap: https://askubuntu.com/questions/184217/why-most-people-recommend-to-reduce-swappiness-to-10-20/184221#184221 – oldfred Feb 20 '19 at 19:20
0

You can manually disable swap usage of any kind through the terminal:
use

swapoff -v [path of associated logical volume]

I believe that you can also reduce that with lvreduce (but look at the man page for that).

zx485
  • 2,426
Norman
  • 9