This is an old desktop I use for some small self hosting services. I never use all my RAM and I dont see any RAM spikes other than when I install/comile things which I havent done in months. I restarted the machine a couple of times, but the SWAP will evenually go right back up to 100%.
I have an Ubuntu server/yunohost setup and found: askubuntu.com/…/why-is-swap-being-used-even-thoug…
My cat /proc/sys/vm/swappiness
value is indeed 60. Im not sure what would reduce the SWAP space usage.
Would changing this swappiness value help? Anyone come across this issue before?
naomi@lemmy.amethyst.name 1 week ago
The naive approach of thinking of swap as “extra ram that is slow” and so “why is my system using swap when I have ram” is not really the best analogy. It’s better to think of ram as a place that holds memory pages, and disk as a place that holds file blocks/extents. Ram happens to be very fast and disk happens to be very slow, but conceptually programs access both memory pages and file blocks as they are running.
There is no reason that memory pages must live in ram, and no reason that file blocks must live on disk, especially in the modern world with virtual memory, and so sometimes it is more efficient for the kernel to say “hey, this memory page is never used and this file block is used a lot, so I’m going to put the memory page on disk and the file block in memory and everything will be faster.”
When a memory page is moved to disk, this is called swapping and the place it is stored on disk is swapspace. When a file block is stored in memory, this is called cache (or in some cases, buffers). So if you have plenty of ram free, it can still be beneficial for the kernel to move unused memory pages to swap to make space for cache. And once it is in swap, there’s no good reason to move it back until you need it, so even if space frees up in ram, the kernel won’t preemptively move it back into ram.
sugar_in_your_tea@sh.itjust.works 1 week ago
It also takes a while to move stuff between RAM and disk, so it’ll park stuff in swap of it’s not used much to make room for burst RAM needs.
Generally speaking, don’t worry about it as long as the system is responsive, but if things start sucking, consider closing stuff so the kernel can free it.
WhyJiffie@sh.itjust.works 1 week ago
except when not, like when I just copied a multi GB file, it was cached in RAM to be not read again for long, but at least half of my running programs are swapped out. Additionally if swap is o SSD, it has put totally unnecessary wear into it by doing this
mlfh@lemmy.sdf.org 1 week ago
That’s why you can adjust swappiness, or designate a different high-endurance storage device for it.