Skip to content

Conversation

@EliasTheGrandMasterOfMistakes
Copy link
Contributor

@EliasTheGrandMasterOfMistakes EliasTheGrandMasterOfMistakes commented Mar 10, 2025

from: https://wiki.archlinux.org/title/Zram#Optimizing%20swap%20on%20zram

"Explanation of the configuration:

These values are what Pop!_OS uses. That Pop!_OS GitHub pull request also links to some testing done by users on r/Fedora, which determined that vm.page-cluster = 0 is ideal. They also found a high swappiness value to be ideal, which matches what is suggested by the kernel docs:

The default value is 60.
For in-memory swap, like zram or zswap, as well as hybrid setups that have swap on faster devices than the filesystem, values beyond 100 can be considered. For example, if the random IO against the swap device is on average 2x faster than IO from the filesystem, swappiness should be 133 (x + 2x = 200, 2x = 133.33).

On a system with a hard drive, random I/O against the zswap device would be orders of magnitude faster than I/O against the filesystem, so swappiness should be ~200. Even on a system with a fast SSD, a high swappiness value may be ideal." - Arch Wiki

# Based on https://wiki.archlinux.org/title/Zram#Optimizing%20swap%20on%20zram
SYSCTL{vm.watermark_boost_factor}="0"
SYSCTL{vm.watermark_scale_factor}="125"
SYSCTL{vm.page-cluster}="0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already set via sysctl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is just vm.page-cluster? because vm.watermark_scale_factor i can't found in usr/lib/sysctl.d

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that isn't set yet. I think I'm generally fine with it, considering some other distro is shipping it. Can you move it to the sysctl file tho? It's more appropriate to place it there.

@ventureoo thoughts on settings vm.watermark_scale_factor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have removed this since this increased the ram usage (cache) like x2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have removed this since this increased the ram usage (cache) like x2

sorry, this means that is best to not set it? and just increase zram in 180?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or this parameter can be set when just using zram?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently set swapiness to 150, as you see in the below comment. Im unsure, if 180 will make a huge difference?

You can also test yourself with the above values - they go way over the roof. We have debugged this "issue" very long time, till we found this is coming from there.

This was removed in commit 451836f (#55)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my test looks that zram usage is more than using 150, idk if this are a placebo effect, but this makes zram be used more early when running applications that uses high ram. i has reduced zram priority from 100 to 0 too.
I think that can be good if has more results, but for now can be just priority or a placebo

Copy link
Member

@ventureoo ventureoo Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that isn't set yet. I think I'm generally fine with it, considering some other distro is shipping it. Can you move it to the sysctl file tho? It's more appropriate to place it there.

@ventureoo thoughts on settings vm.watermark_scale_factor?

To be honest, I'm not sure. Basiclly that is just makes kswapd less aggressive when RAM usage is low, and in turn it actually increases memory consumption since most of unused pages stay in memory. This is positive effect for CPU in case of ZRAM and makes some users happy, because they don't like earlier swap usage for whatever reason, but on other hand creates discomfort for others as the increase can be quite large [1]. Probably we just need to pick a some reasonably balanced value, as we have done with other non-obvious parameters.

I also want to separately note that kswapd is not only about swap, but also about freeing unused file pages, i.e. flushing page cache, which is in my view the main reason for the increased consumption here even when there are no pages that actually need to be swapped into ZRAM.

[1] - https://unix.stackexchange.com/questions/729275/why-does-setting-the-vm-watermark-scale-factor-property-increase-ram-consumption

SYSCTL{vm.swappiness}="180"

# Based on https://wiki.archlinux.org/title/Zram#Optimizing%20swap%20on%20zram
SYSCTL{vm.watermark_boost_factor}="0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already disabled in the kernel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, i has made a forced push to remove

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already disabled in the kernel.

Well, actually it's not. It's just we have patch that enables it by default, but user can use other kernels.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already disabled in the kernel.

Well, actually it's not. It's just we have patch that enables it by default, but user can use other kernels.

Yeah, that's what I meant. Do we really want to care about other kernels though? It's far more likely that outside users would use the kernel more than our settings. There's a high chance that their already using our kernel too when they opt to use our settings. Other kernels such as zen and tkg also disable this via patch too AFAIK.

@1Naim 1Naim requested a review from ventureoo March 10, 2025 18:23
@ptr1337
Copy link
Member

ptr1337 commented Mar 10, 2025

The zram rules are handled here:
https://github.com/CachyOS/CachyOS-Settings/blob/master/usr/lib/udev/rules.d/30-zram.rules

The reason for this, is to only apply the changes, when zram is found.

@EliasTheGrandMasterOfMistakes
Copy link
Contributor Author

The zram rules are handled here: https://github.com/CachyOS/CachyOS-Settings/blob/master/usr/lib/udev/rules.d/30-zram.rules

The reason for this, is to only apply the changes, when zram is found.

thank you, i has added in this file 30-zram.rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants