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
kernel: Switch to ZSTD compression & manual-config.nix improvements #105777
Conversation
@Mic92 I didn't want to introduce a build time dependency on python3 since the current nixos kernel builds fine without my patch. Was trying to find what config setting calls I've ended up simplifying the |
Required to build with zstd compression. Refs #101108
I guess gawk and zstd in nativeBuilInputs is okay. But where is the python3 patching now ? |
I dropped that change, didn't want to introduce a dependency on python3 just to build the kernel, especially since it's not required for the default nixos builds. |
Ok, everything LGTM :-) |
sry if I missed it: why do we need gawk ? |
It's used in ld-config. The change just makes it an explicit dependency and converts the sed to patchShebang -- it was already used before. (See #105777 (comment)) |
looks good. I wanna merge but I wonder if it shouldn't go into staging instead ? that's what I was asked in a similar PR #106395 |
Users don't directly benefit from this change and it causes a moderate number of rebuilds, I think staging is appropriate. |
Since it's going into staging, I'll go ahead and configure zstd compression as well. |
What's a good way to change the Would this work?
I'm not too familiar with nixpkgs so I don't understand if that's evaluated late enough. |
ztd -> zstd I'd flip the conditional, "you need at least 5.9 for zstd" is clearer in my head. The zstd compressor should probably be given a higher level. ~10 is appropriate I think; that should still compress in under a second and doesn't impact decompression speed significantly. Keep in mind that what you're now touching is NixOS. It uses the module system for combination/evaluation and you need to use |
The levels are not directly comparable though. Based on fedora benchmarks it seems that A few more figures here: https://community.centminmod.com/threads/round-4-compression-comparison-benchmarks-zstd-vs-brotli-vs-pigz-vs-bzip2-vs-xz-etc.18669/ |
Keep in mind that they're compressing a 4.7GiB cpio in those tests. My Level 10 does yield a ~10% reduction over 3 according to your links and the squashfs benchmark shows similar results. It does fall off dramatically from 10-15 though and anything higher is way to slow and outclassed by lzma and others. The Fedora benchmark's ~10MiB/s is rather slow compared to the squashfs benchmark's 10y/o mid-range laptop's ~28MiB/s but even that'd only take a few seconds for a few dozen MiB large initrd which is still acceptable and worth it for 10% space savings IMO. |
Ready for another review, sorry for the delay. Should this be put in the next release notes too? |
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.
LGTM. nixosTests.kernel-latest is affected by this PR's changes and passes just fine.
The initrd compression time is not noticable on my system (Ryzen 3600), despite only using one core. (Which is weird, zstd should be using 6 on this system by default.)
There's one unrelated commit in the bunch but it's just a minor cleanup.
Base should be changed to staging; this doesn't need to go to staging-next.
The regular LTS kernel is not affected as expected (config built with one has a gzip'd initrd) and my 5.10 system boots without problems using the zstd initrd. |
|
Why zstd instead of lz4?
https://smackerelofopinion.blogspot.com/2019/09/boot-speed-improvements-for-ubuntu-1910.html:
|
(Note: LZ4 is by the same author as ZSTD.) ZSTD strikes a nice balance between compression ratio and speed. LZ4 is extremely fast but won't compress as well.
|
I worry that zstd will be a bottleneck on fast drives.
|
If you have an initrd/kernel that's big enough to make a difference there, you've got another problem :) zstd is already about five times faster than gzip which was the default so far. As indicated by Atemu #105777 (comment), the initrd filesize matters more, since we don't want to fill up the boot partition. You're always free to change the |
My initrd is ~35MiB. According to FB's benchmark, that would take ~22ms to decompress with zstd and ~8ms with lz4. If you have a config where 14ms would be a significant part of the boot process, I'd love to see it.
Actually, I don't think you are; that's an internal option. I don't see much reason for it should stay one though.
Last time I checked, it was supposed to default to
I did test to manually set it to |
Hmm I guess it was undocumented? I was using this locally before: https://github.com/archseer/snowflake/blob/master/hosts/hyrule/default.nix#L40
|
Okay, that is fine.
Just so you understand the rational for my personal choice of using lz4: EFI system partitions are typically 260 MiB, so I would rather have the performance improvement over size on my system.
|
Nice find! Made a comment there to add |
|
||
# use zstd for kernel compression if newer than 5.9, else xz. | ||
KERNEL_XZ = { optional = true; tristate = whenOlder "5.9" "y";}; | ||
KERNEL_ZSTD = { optional = true; tristate = whenAtLeast "5.9" "y";}; |
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 don't think optional
is necessary here, since the version check already ensures that it's available, and we probably have some other issue if it's still not available.
@TredwellGit Out of scope for this PR. We don't care what version the CLI tool is, it just has to produce a file in ZSTD format that the kernel can read. |
I posted it just in case any of the new changes would influence the compression options chosen. |
for some reason, this was not closed automatically after #107703 was merged.. closing manually |
Motivation for this change
Switches the kernel and initrd compression to zstd on kernels 5.9 and newer.
Also addresses two issues I've had to patch when using
linuxManualConfig
:Adds
zstd
to nativeBuildInputs, it's required ifKERNEL_ZSTD
is enabled. (I think zstd should be a part of stdenv (refs #101108), just likebzip2 gzip xz
but it's a start.)Certain BPF config options usebpf_helpers_doc.py
which referencespython3
via FHS so it has to be fixed up.Used
patchShebang
instead ofsed
to patch a FHS shebang referencing awk.Closes #101108
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)