How to customize Caching/Buffering levels

Hey people,

I’ve upgraded my system recently and most of my ram remains unused on my daily workload. Is there a way to tell my system to cache more aggressively or do I need to configure this on each application ?

Are there any other ways to take advantage of this extra ram ?

More info would be appreciated. Maybe inxi -Fzx would give a nice overwiew.

1 Like

Sure, but there isn’t really much to it. I have 16GB of RAM but I don’t really get more than 35% usage normally, unless I’m gaming or doing something very uncommon.

System:    Kernel: 5.14.12-200.fc34.x86_64 x86_64 bits: 64 compiler: gcc v: 2.35.2-6.fc34 
           Desktop: GNOME 41.0 Distro: Fedora release 35 (Thirty Five) 
CPU:       Info: 6-Core model: AMD Ryzen 5 5600X bits: 64 type: MT MCP arch: Zen 3 rev: 0 cache: L2: 3 MiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 88792 
           Speed: 2197 MHz min/max: 2200/3700 MHz boost: enabled Core speeds (MHz): 1: 2197 2: 2198 
           3: 2391 4: 4522 5: 2877 6: 3604 7: 2348 8: 2867 9: 2874 10: 2862 11: 2877 12: 3595
Graphics:  Device-1: NVIDIA GP106 [GeForce GTX 1060 6GB] vendor: Gigabyte driver: nvidia v: 470.74 
           bus-ID: 07:00.0 
           Display: wayland server: X.Org compositor: gnome-shell driver: loaded: nvidia 
           unloaded: fbdev,modesetting,nouveau,vesa resolution: 2560x1080~60Hz 
           OpenGL: renderer: NVIDIA GeForce GTX 1060 6GB/PCIe/SSE2 v: 4.6.0 NVIDIA 470.74 
           direct render: Yes 
Drives:    Local Storage: total: 931.51 GiB used: 376.02 GiB (40.4%) 
           ID-1: /dev/sda vendor: Western Digital model: WD10EZEX-00WN4A0 size: 931.51 GiB temp: 30 C 
Info:      Processes: 346 Uptime: 13h 20m Memory: 15.5 GiB used: 3.18 GiB (20.5%) Init: systemd 
           runlevel: 5 Compilers: gcc: 11.2.1 Packages: 9 note: see --pkg Shell: Bash v: 5.1.8 
           inxi: 3.3.06 

I have 32 G ram and am running some very cpu intensive processes (~95% loaded with 6 cores/12 threads) with only 8 G of ram (25%) and 750M swap (ZRAM in memory) occupied.
I am not sure what you are looking for in tweaking use of memory, but the system does a pretty good job of managing it.

I know, but since I usually have a lot of free memmory I wanted to take advantage of it, especially because my storage is kinda slow.

You can reduce your “swappiness”.
This is a kernel parameter that affects on which point the data is loaded into swap.
The default value is 60. That means that if your RAM usage reaches 40 %, it starts using your swap file.
100% - 60% = 40%

Well, that’s how it used to work, I belive. Nowadays using zram and zones it woks different.

In order to switch your swap off, set the value to 0. (Depends on the Kernel, for me it switches it off.)
If you want to start using your swap late, set it to 10.
But even if you set it to 100, it won’t always start swapping, just earlier, might be at 75% of RAM-Usage, for example.

Just to be clear, reducing the swappiness actually does significantly reduce the amount of hard drive memory is being used. If you fully consumed your RAM, the swap may still be useful. So it generally is not a good idea to switch it off.

You’ll have to try a bit. Using SSDs you won’t feel much difference while swapping.
A swap there can even fastening things, cause more of fast free RAM might be available.

How to do it:
sudo sysctl -w vm.swappiness=10

→ This just changes the setting in memory and does not survive a reboot.

To change it permanently:
sudo echo "vm.swappiness = 10" > /etc/sysctl.d/98-swappiness.conf
(For example. The precedence is in alphabetic order. The file name needs to end with .conf)

And load all your configured kernel parameter:
sudo sysctl --system