Score:0

why does my swap grow bigger day by day until I re-boot?

de flag

ubuntu 20.04lts on Gateway E-475M laptop

I do not normally shut down daily, but suspend onto battery overnight, but notice the SWAP usage (2GB RAM / 2GB SWAP) grows each day until it gets almost maxed out, where I have to reboot and it's usage drops to zero. I use the laptop to browse only (read local newspaper in morning, watch 30 min news stream, check GAB and PARLER once daily, once in awhile do search...). Any way to 'clear out' the SWAP without rebootin'?


OK - so increased SWAP from 2Gb to 4Gb and get this now:


free -h

              total        used        free      shared  buff/cache   available
Mem:          1.9Gi       1.1Gi        97Mi       187Mi       802Mi       556Mi
Swap:         4.0Gi        51Mi       3.9Gi

grep -i swap /etc/fstab

/swapfile                                 none            swap    sw              0       0

...so, I'm forgetting my "clear SWAP" answer as when SWAP is large, there's not enough RAM so it lockes up everything - major crash... Just hope the double size helps with the slow down when the SWAP was getting big... thanks!


All this may be irrelevant as while messing with this swapfile stuff, I just got HIBERNATE working, so now will be hibernating, not suspending to RAM, overnight... found info here that worked for hibernate: - - - - - - - - - - askubuntu.com/questions/1240123/… - - - - - - - - - - then made keyboard shortcut super+H... awesome!

heynnema avatar
ru flag
The REAL problem is that you don't have enough RAM, and your swap is too small. [Edit your question](https://askubuntu.com/posts/1346118/edit) and show me `free -h` and `grep -i swap /etc/fstab`.
Score:3
cn flag

Linux spares your memory. When something is not needed into memory, it is swapped. If something else later on, it is swapped. If two days later, something is not needed, it is swapped. It will only be retrieved when you need it. That saves RAM so active processes have more memory and performance is better. Only parts of swap that potentially may be needed again are kept. There is no unused unallocated garbage accumulating there.

Linux is good in memory management. You can trust it.

That is to the "why".

To learn how you can manually clear the swap, see the answer of The MAJOR. A sudo swapoff -a followed by a sudo swapon -a will do. If you feel the need to run these commands, do that only if you are sure there is sufficient memory. Otherwise, the system will attempt to terminate processes to free needed memory. But, really, there is no need. Let Linux manage memory. It does so in a way that performance for you is maximized.

Score:-2
de flag

Disable all the swap using this command:

sudo swapoff -a

Now turn the swap back on:

sudo swapon -a

That’s it. This simple exercise will clear the swap in your Linux system.

from: linuxhandbook.com/clear-swap (give credit where credit is due...) warning found: Before clearing the swap, check that you have enough free RAM available to take all the pages from swap. In other words, you should have more free RAM available than the current swap in use. what happens if there isn't enough 'spare' RAM... lockup? YEP - so this 'answer' is worthless!

Raffles avatar
in flag
Hello MAJOR, instead of adding thoughts as comments, edit them into your answer
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.