VFS cache and Swappiness

sudo micro /etc/sysctl.d/99-sysctl-performance-tweaks.conf

In this config file, the vm.swappiness and vm.vfs_cache_pressure behave as follows.
Reducing vfs pressure reduces amount of caching that is reclaimed when more memory is used that is it reclaims the memory used for cache for whatever application you are using.
If you increase swappiness, less ram and more swap storage will be used. it is recommended to use less swappiness for HDDs since they significantly slow down the system when used as swap.

Recommended values:

For under 16gb ram and SSD:
swappiness:20-30
vfs pressure: 80-90(lower ram higher value)

For 16 gb and more and SSD:
swappiness: 20-30
vfs pressure: 65-75

you get the gist. more ram less swappiness. faster ssd more swappiness. more ram less vfs pressure, high cpu usage due to decompression=increase in vfs pressure.
default values garuda sets are usually good for most use cases but in case you get out of memory or high cpu usage due to vfs decompression and want to tweak them this is the guide.

Sources:
https://wiki.archlinux.org/index.php/Swap
https://www.kernel.org/doc/html/latest/admin-guide/sysctl/vm.html

5 Likes

Any suggestions for HDD?

I have old machine, with 4 GB RAM and HDD.

I have swappiness set to 15. Haven't changed anything else. Working fine so far, but would welcome any suggestions. :grinning:

How is this affected by Garuda using ZRAM by default?

What evidence or guidance are you basing these changes on?

2 Likes

I learnt some from archwiki and linux kernel docs.please do correct me if I made any mistake in the interpretation.

I think that's a good value for your machine. You have to increase zfs pressure (not necessary)

Links to the related information is always good to include in a tutorial post.

3 Likes

Your wish is my command senpai.

2 Likes

I think adding this to the wiki is a good idea. it will help newbies learn how to handle their particular amount of RAM and swap. Will help avoid OOM problems which seem to be ubiquitous.

1 Like

I use different computers with from 4 to 32 GB of RAM. I have always set my swapiness factor to 10 long before I started using Garuda.

If feel that is a good default for many different machines. I'm not saying that tweaking that number isn't a good thing. I simply feel that 10 is a good default value, and that changing that number is not required.

3 Likes

it helped me, so I agree, this will help newcomers to garuda linux.

1 Like

I wonder about the accuracy of this thread. Even with swappiness of 10, systems with 16gigs of ram will start swapping with only 4gigs of ram usage. That's slowing things down by swapping with 12gigs of ram still free. Swappiness of 20-30 as a recommendation surprises me. When I find my system swapping early, I change my swappiness to 2 or 3 and it clears up the problem and still swaps when needed. Some argue that less than 5 isn't recommended, to which I reply, "Yes it is... it's recommended by me." If anyone sets their swappiness to 20 or 30, watch all the swapping that will be going on slowing down your system while you still have 2 shrimploads of free ram. I personally don't like to see any swapping until I'm around 12 out of 16GB ram usage. But I don't know everything.

1 Like

It is certainly not complete. In modern HW/SW there are too many parameters and too many combinations to consider. It's mainly a per case subject, for each user and HW set.
The original author was confident (just like yourself :stuck_out_tongue_winking_eye: ) to provide some sane settings.

Garuda uses zram and btrfs (COW) by default.
Arch uses zswap by default.

IMHO the real difference that needs investigating for the proper values combination to many parameters is for HDD and SSD disks, which require different approach.
Also, the users' important applications and their requirements have a strong influence on the final magic recipe.
And the risk of data loss is an important factor. Having everything on RAM with a power supply failure, or a crash, will make decisions differ :wink: .

IMO there is only one sane advice:

Take your own risks!

6 Likes

Does changing these settings require re-login to take effect?

If tou change the .conf file, yes.
But you may change them without a need to reboot. Read how.

2 Likes

I have just checked my 99-sysctl-garuda.conf file

It is nothing like the custom values I entered post-installation.

All of my custom TCP/IP stack-hardening entries are gone.

VFS cache entry is gone.

Swappiness is set at 133. (WTF?)

What gives?

It was likely overwritten during a package update.

You can check which package owns the file with pacman -Qo /path/to/file .

2 Likes

Thanks for this. The suggested command returns "error: No package owns /path/to/99-sysctl-garuda.conf"

I rewrote the file with my preferred settings and all seems well. (I've also backed up a copy so I can copy and and paste it all back if needed.) I'm not delighted the file can be overwritten in this fashion, especially not with such an insane swappiness value.

You can write a pacman hook to ensure your settings are preserved if you wish.

See the Arch Wiki:

https://archlinux.org/pacman/alpm-hooks.5.html

2 Likes

That's because you have to provide the actual path, not the placeholder text.

2 Likes

Sorry, I had a derp moment. The file is owned by garuda-common-settings.

I'll try writing the pacman hook that @tbg suggests and keep a careful eye on package updates.

1 Like