Comment on Why is my home server using so much RAM for cache + buffer?
brucethemoose@lemmy.world 6 days ago
I disagree with most here.
You need to reduce swappiness even more, and tweak some other variables (like the memory “threshold” Linux starts to swap, and disk cache aggressiveness) to stop Linux from swapping so opportunistically under such a light load.
IMO, Linux is configured for “old” systems by default: slow HDDs, and constrained RAM pools, where disk IO really, really needs caching, and where idle background processes take a large fraction of RAM.
You have superfluous RAM for your workload. And very fast disk IO that isn’t such a hindrance to apps anyway. And a disk you don’t want to wear. This is the opposite scenario: you don’t want Linux to swap unless it absolutely has to.
For reference, this is part of my config. It’s rather niche and you probably shouldn’t use it, but you should consider looking up the variables:
‘’‘
Keep min reserve reasonable for 8GB usable space
vm.min_free_kbytes = 262144 # Lower absolute minimum to 256MB
vm.watermark_scale_factor = 10 # Lower to 0.1% (which is ~128MB on 128GB)
Disable watermark boosting completely
vm.watermark_boost_factor = 0
Normal-ish metadata pressure so desktop doesn’t stutter on disk reads
vm.vfs_cache_pressure = 120
Allow reasonable swapping of inactive anonymous desktop pages, could be lower
vm.swappiness = 10
Dirty bytes limits to limit caching
vm.dirty_background_bytes = 67108864 vm.dirty_bytes = 268435456
Disable compaction & proactive scans to stop freezing with large portions of RAM blocked
vm.compaction_proactiveness = 0 vm.compact_unevictable_allowed = 0
vm.page-cluster = 0 # 4kb pages for SSD ‘’’
It makes a night-and-day difference for some workloads on my system, that would otherwise swap pointlessly, just tank performance and even de-stabilize the system.
non_burglar@lemmy.world 6 days ago
I agree that hitting swap is not ideal, but messing with swappiness sysctl is almost never the answer and very often leads to more problems than it solves.
If you want to tune for workload without needing fairly deep understanding of how Linux manages memory, use a sysctl that sets a whole system behaviour like CPU governor presets.
Not really a matter of opinion, and not true since kernel 5.1 when ssds became first class citizens.
brucethemoose@lemmy.world 6 days ago
I mean… it’s clearly an issue for some. OP’s system is swapping the SSD when it clearly should not be doing it. My system had horrible usability issues in some scenarios without tons of configuration, and thrashed my SSD for no benefit.
The default heuristic is not good for our systems.
And support for TRIM and whatever else was added for SSD support is not really the issue, here.
non_burglar@lemmy.world 5 days ago
No, sorry. We don’t know enough to say this. What were the options when configuring ext4? What record size is grafana using? Mariadb or postgres? Is there contention with another db? Is there a mounted NFS path in the same ext4 partition with weird block settings? There are lots of legitimate config reasons for op’s problem, but there are so many parts of op’s setup we don’t know, we similarly can’t possibly know what the issue is.
Swappiness works as intended in most default scheduler configurations and seeing high swap is a symptom, not an issue. It is almost always more productive to find out why the swapping is happening.