An article worth reading if you want deeper understanding of swappiness



That's almost exactly 20 years old.

I suspect the fundamentals are the same but that the code itself will have changed in the interim.

It's still worth looking at.
 
That's almost exactly 20 years old.

I suspect the fundamentals are the same but that the code itself will have changed in the interim.
One change I know of is that max. swappiness value was increased from 100 to 200.

But I'm not sure about the formula itself, according to more recent article from redhat (year 2021) the formula remains the same:
swap_tendency = mapped_ratio/2 + distress + vm_swappiness;
source:
 
Yup. That's about what I'd figured. From your link:

Changes to this parameter should be made in small increments and should be tested under the same conditions that the system normally operates.

Which would be the main takeaway (in my opinion).
 
@KGIII
Another interesting fact I didn't know about is the orange bar in htop, example:

htop.png


The orange bar in memory bar is cache (files from disk loaded into memory and read from it, instead of from disk or SSD),
This file cache does not constitute consumed memory but rather free to use one, hence why it says 3.41G used memory in the screenshot instead of cca 60%

As soon as the memory bar fills up the orange bar will be swapped out to disk to make more memory space for actual memory needs, ex. used (green) shared (purple) or buffers (blue).

Swappiness of 10 should make cache (orange bar) fill up entire memory and release it as needed, but I haven't done extensive tests yet for higher values than 10.

This in addition to swap partition saves a lot of disk I\O for file read\writes other than swap only.
 
I run LM21.3 on 32GB ram, and have zero swap
 
I run LM21.3 on 32GB ram, and have zero swap
What about your file cache and memory bar (orange portion)?
You know it won't be shown in htop because it will be read from disk which is almost the same as using swap.
without swap you're forcing cache to be read\write to disk.
 
Swappiness of 10 should make cache (orange bar) fill up entire memory and release it as needed, but I haven't done extensive tests yet for higher values than 10.

I have swap enabled but leave the configuration as the default. It works. I figure if it uses swap when swap is available, I should make swap available. I am not smarter than the kernel.
 
all depends what do you want to use: RAM or swap
if RAM to use (and has 32GB):
vm.dirty_ratio = 10
vm.dirty_background_ratio = 2
user.max_user_namespaces = 0
vm.stat_interval = 10
vm.swappiness = 100 -> make it 100 for nice balance
vm.vfs_cache_pressure = 50
# for RT kernel only
vm.overcommit_memory = 2
vm.max_map_count = 16777216

I would check what these ^ do of course. Safe for laptop (battery) of UPS. if not much RAM forget other parameters as they push everything to RAM.

is ZSWAP modify and add:
vm.swappiness = 180 <- change
vm.watermark_boost_factor = 0 <- add
vm.watermark_scale_factor = 125 <- add
vm.vfs_cache_pressure = 75 <- change
vm.page-cluster = 0 <- add

also define percentage of RAM used for ZSWAP and ZSWAP size if plans are to use ZSWAP
 
Last edited:

Staff online


Top