-
Notifications
You must be signed in to change notification settings - Fork 15
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
Auto-configure zram with optimal settings #163
Conversation
4f3077d
to
ce66ae2
Compare
99b5064
to
3ef876f
Compare
Please consider keeping things simple and using well known standards. zram-generator is a well known and documented ZRAM manager, it even allows using flexible rules to manage the amount of ZRAM according to the machine RAM: https://github.com/systemd/zram-generator/blob/main/man/zram-generator.conf.md Like other systemd services, it is possible to create a simple drop in file like: /etc/systemd/zram-generator.conf.d/50-pop-zram.conf with the desired rule (the one suggested in the link above looks very good, for both machine with low RAM and otherwise). And sysctl values should go to the default place as well, for instance: /etc/sysctl.conf.d/99-pop-zram.conf This would use standards, as well as making it very easy to find where the settings are stored, and also allows user customization. |
@lfom We already have a sysctl config file for things that make sense to be applied universally by default (see the PR). In this particular case, it's not a good idea to have conditional parameters stored in a permanent configuration file. The sysctl parameters are applied in the script because they need to be evaluated at runtime ( As mentioned in the PR's description, I'm really not sure zram-generator is so necessary to add as a dependency when the complexity isn't needed for a system default. If someone wants a more complex setup, they could add zram-generator to their system and use that instead. And this way it's easier to opt out of the Pop config. I'm also trying to avoid including any config files that are not easily disabled. I only have one optional user-defined env file at I'm a fan of simple solutions. This is a pretty basic 20 line bash script to automatically evaluate and apply the recommended system defaults. At it's core, we're talking about a script that's just running modprobe zram num_devices=1 && sync
zramctl --size "${SIZE}M" --algorithm "${ALGO}" /dev/zram0
mkswap /dev/zram0 && sync
swapon -p "${PRIORITY}" /dev/zram0
sysctl -w "vm.page-cluster=${PAGE_CLUSTERS}" "vm.swappiness=${SWAPPINESS}" Regardless, we'd still need a system service to apply the sysctl tweaks when using the default configuration provided by Pop. |
If the main reason for doing all this is to check the current user configuration for systems already running Pop!_OS, then this can be done during the package installation. This would prevent problems for any user who already changed the default swap configuration IMO. Besides the additional rules in the post-installation script to check the current swap configuration, it would require only enabling zram-generation and placing the two text configuration files. |
Enabled this on my HP Dev One with 64gb of RAM. Everything is working as expected with no performance degredations. It currently feels a bit snappier under a basic load, and I'll continue to test it with more intensive things. |
0dfd0c0
to
ebd0d09
Compare
Thank you for this great find, it works wonderfully on my PC with 8GB RAM, and I got a solid boost from sometimes 80 fps to 120fps (my refresh rate) and other times from 80fps to 90 fps. I have a burning question for some time though and this seems like a good moment to ask it : Pop by default enables zswap and it defaults to lzo/zbud, but wouldn't it be better if it would default to zstd/z3fold ? Or lz4/z3fold ? So maybe those are some other optimizations that can be made by defaulting to zstd/z3fold and by using a tuned swapspace package (instead of running out of memory as is the default case currently) for Pop. |
@woutheijnen This defaults to zstd |
I know but it defaults to zstd for zram only, not for zswap. This is for a similar optimization (zswap) to maybe make it default to zstd/z3fold instead of lzo/zbud and maybe swapspace could be handy too for Pop_Os systems in case of systems having low RAM just an optimization suggestion |
It seems that because we're using zstd, and zstd has a much higher compression ratio than lzo, it would make sense to increase the default to 16 GB of uncompressed memory. 8 GB limited the size of the zram block device to no greater than ~2.4 GB after compression. Fedora has recently changed their zram configuration to 100% of RAM size, and I've been doing well with this configuration for a few days of compiling and web browsing on a system with 16 GB.
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 looks good. I saw no regressions. I tested on RAM configurations between 4GB and 64GB. On older machines with low RAM (i.e., 4-8GB RAM) the difference was most notable. I had no issues with using zram-generator and the bash script worked as expected. On machines with 16GB daily tasks like browsing, docs and spreadsheets, and streaming (although a bit jittery at times) are still very responsive. This was with a 60GB game downloading and Firefox compiling.
The most extreme case of this making a difference was a 10 year old ThinkPad with 8GB of RAM. I was able to play Control for a while at around 30 FPS. It did still crash, but it was working for a bit. Without this PR it showed around 11 FPS as it loaded the menu and then crashed.
I played around with different swappiness values, but was not able to see a noticeable difference. Though this may vary with different hardware configurations.
It did regenerate itself on the next boot after changes to RAM in the machine (e.g., removing 8GB from a 16GB).
I have also had this running on several machines I use on a regular basis for a few days now doing normal day to day tasks and have seen no problems that I could attribute to this PR.
Note: Tested on many different machines with Intel and AMD hardware with and with out dedicated graphics.
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.
After running through the same testing as before I can confirm I am getting the same results as stated above.
This looks good to me.
FYI the settings for Zram will change the defaults for normal swap too. So if Zram is disabled the existing zram swappiness settings are left causing swap to be prioritized over ram. |
@mmstick it could be a consideration to:
The reason I say this is because of the charts in the Reddit post you linked: https://imgur.com/a/linux-zram-benchmarks-bUSBlm1. Or was extensive profiling done by the Pop team?
|
Testing
180
swappiness, we might want to try with a lower value to see if this is really the ideal default for a zram environment.Note that you can disable and recreate the zram device with
Running
zramctl
displays the compression algorithm, max size of block device, memory stored inside of it and its compressed size.Rationale
vm.swappiness=180
andvm.page-cluster=0
withzstd
comp_alogorithmImplementation
pop-default-settings-zram
systemd service that runs /usr/bin/pop-zram-config on system startupzram
device already exists on the system, script exits and no configuration changes are made/etc/pop-zram
, which has a default example in/etc/default/pop-zram
.vm.watermark_scaling_factor = 125
, andwatermark_boost_factor = 0
, a default sysctl value, as recommended here