-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zramSwap: by default disable zSwap and set sysctls #351002
base: master
Are you sure you want to change the base?
Conversation
8c606aa
to
e491f8e
Compare
I updated the commit to add to the zramSwap description. I also set the optimized sysctls to be disabled by default. |
cf08ca5
to
3f2bace
Compare
nixos/modules/config/zram.nix
Outdated
This option when enabled, adds the `zswap.enabled=0` kernel | ||
parameter when you also enable the zramSwap module. | ||
|
||
Defaults to `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to have these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it is off by default, I guess. If someone does later add a zswap option in a different module, there ought to be a warning as @K900 suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The option search already shows the default value of options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be okay with "When zramSwap is enabled, this defaults to true
." ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the disableZswap
option, which should be removed entirely.
3f2bace
to
826ba0e
Compare
826ba0e
to
4f2c4f9
Compare
4f2c4f9
to
8ccdf3e
Compare
[zswap](https://www.kernel.org/doc/html/latest/admin-guide/mm/zswap.html). | ||
Zswap applies more suitable heuristics in this case when using disk swap. | ||
|
||
Zswap can be enabled using `boot.kernelParams = [ "zswap.enabled=1" ];`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a good time to introduce a zswap module then? We could then direct users to the right options, or even add a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to do this in a second PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I really don't like is that we have information in the zram docs that's not very relevant to zram, and we could have automation take care of this instead of relying on users to read things (which they never do).
I am adding two improvements to the zramSwap module. The module can configure a NixOS machine such that it creates a zram block device which is then mounted as swap. This is useful in situations where it makes sense to avoid storing swap onto a physical storage device. The kernel starts to swap anonymous memory pages (like application data) when a lot of memory is either requested by applications and / or when files from physical storage are accessed frequently while application memory is never touched. By creating this setup, anonymous pages can be compressed in memory instead of forcing the kernel to try other memory freeing techniques like compaction and reclaiming. Applications will pretty much always waste memory for example by allocating a variable on the stack when launching and initializing but never touching it again until the program exits. Also most program data is highly compressible.
These changes are taken and / or inspired by the Archwiki page on Zram and the discussions linked in this Pop_OS! PR.
So here are the main new options I added and enabled by default:
vm.swappiness = 150
getting file data even from a fast SSD is gonna be much slower than decompressing some pages, so let's swap more frequentlyvm.watermark_boost_factor = 0
watermark boosting kicks off kswapd when there is memory fragmentation and someone needs a continous area. Even when using a swapfile this seems to maybe cause longer pauses as seen here. But because swapping is gonna lead to more allocations this seems counterproductive. Let reclaim do its thing instead.vm.watermark_scale_factor = 125
again let's kick off kswapd earlier rather than wait for memory starved situations as swapping to zram will increase pressure more.vm.page-cluster = 0
prefetching multiple pages from swap seems silly when we are in RAM anywayThings done
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.