this post was submitted on 07 Apr 2025
56 points (95.2% liked)

Selfhosted

45940 readers
1084 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 2 years ago
MODERATORS
 

This is an old desktop I use for some small self hosting services. I never use all my RAM and I don't see any RAM spikes other than when I install/compile things which I haven't done in months. I restarted the machine a couple of times, but the SWAP will eventually go right back up to 100%.

I have an Ubuntu server/yunohost setup and found: https://askubuntu.com/questions/157793/why-is-swap-being-used-even-though-i-have-plenty-of-free-ram

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?

EDIT: Found out what it is, its the matrix server that is running on the system. Its taking up a significant amount of swap. Found out via:

smem -s swap -r -p

turning that off, the system is now using 90% less SWAP. /opt/yunohost/matrix-synaps was the process.

you are viewing a single comment's thread
view the rest of the comments
[–] naomi@lemmy.amethyst.name 58 points 1 week ago (6 children)

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.

[–] WhyJiffie@sh.itjust.works 4 points 1 week ago (4 children)

"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."

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 10 points 1 week ago (1 children)

That's why you can adjust swappiness, or designate a different high-endurance storage device for it.

[–] WhyJiffie@sh.itjust.works 2 points 1 week ago* (last edited 1 week ago) (1 children)

my swappiness is 0. yet my swap usage isn't. plenty of "available" memory (as in, multiple GB)

or designate a different high-endurance storage device for it.

good luck with that on a laptop. maybe the swapiness setting could just work sensibly

[–] aBundleOfFerrets@sh.itjust.works 1 points 1 week ago (1 children)

“sensibly” “intuitively” and “performant” are all different objectives and I assure you kernel devs working on such a central subsystem are primarily optimizing for one.

[–] WhyJiffie@sh.itjust.works 1 points 1 week ago* (last edited 1 week ago)

the meaning of zero really shouldn't be an objective thing. it means: don't do that

the kernel is literally eating my soldered eMMC chip

load more comments (2 replies)
load more comments (3 replies)