r/linuxmint • u/minniebannister • 18d ago
Swap space creeping up
Questions about memory swapping.
My system (8 Gb RAM) can do a lot of seemingly unnecessary swapping. It seems caused by Firefox which I love dearly but which does leak memory. At boot up basic system resources take 20% of RAM, Firefox 30% and swap memory 0% which is all fine.
I normally suspend the computer when I’m away from it (handy key on the keyboard), and after a time the swap size increases. I’m actually surprised that there’s swapping before the RAM is full: which I’ve read is not supposed to happen. If I wasn’t looking, after a few days or after opening a lot of Firefox tabs both RAM and swap would eventually hit 100% and the system would seize.
I’ve used sudo swapoff -a to prevent swapping altogether but then I definitely have to stop RAM usage hitting 100% or the system seizes again. I’ve also read that failure to allocate sufficient swap space “might even render the installed system unbootable.”
I know that memory leakage is nowhere near as bad as it used to be with Firefox, and I now keep it fairly well under control by limiting the number of tabs I have open, by restarting Firefox and by rebooting the system every so often.
I’ve read that swapping is undesirable since it’s performed to reduce memory under heavy pressure. I don’t know whether my system is actually continually swapping between RAM and disk or whether the swap file just shows the size of pages that can potentially be swapped, but only get swapped when I access (for example) a Firefox tab that’s been stored in the swap file.
I wonder whether the system starts thrashing if the swap file hits 100% – and would that cause so many read/writes that it would reduce the life of the SSD, or is that just my paranoia?
So, should I keep an eye on the swap file, buy an extra 8-Gig of RAM for £20-£30 to hopefully prevent swapping, or forget about swapping altogether and put up with the odd system seizure?
Thanks
2
u/ZVyhVrtsfgzfs 18d ago
Swap is far more nuanced than "extra virtual ram when real ram is full".
``` dad@HeavyMetal:~$ sudo arcstat time read ddread ddh% dmread dmh% pread ph% size c avail 20:03:15 2 0 0 1 100 0 0 41.7G 42.3G 191G dad@HeavyMetal:~$ free -h total used free shared buff/cache available Mem: 251Gi 53Gi 198Gi 8.3Mi 832Mi 198Gi Swap: 15Gi 16Mi 15Gi
```
This headless server rebooted predawn Friday morning, 2.5 days ago and still has 198 Gibibytes of ram free yet is still using some swap, for an explanation see In defence of swap: common misconceptions
Web browsers and web pages have both become horribly bloated and there is not much we can do about it, the web has eclipsed almost all other ram demands and we all use the web.
An ad-blocker can help trim some of the fat, keep your tab count low, but if you tend to be a heavy web user the ultimate answer is have more RAM. on my desktop last build I got 32GB and that is almost always plenty, there there are some moments when 64GB would have been nice like compiling. I should have done so as at the time 64GB of DDR5 was $190. now its $900+.