When I look in rc.sysinit I see the commands to create the swap in RAM but I do not see the instructions to compress the data. Where do I find that?
Question about zram
Moderator: Forum moderators
-
- Posts: 2436
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1205 times
Re: Question about zram
zram is a compressed block device, data gets compressed every time it's written to this virtual device. When you put a swap partition on a zram device, pages written to swap are compressed.
-
- Posts: 2436
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1205 times
Re: Question about zram
rc.sysinit doesn't set the compression algorithm and lets zram use the default chosen at kernel compilation time.
Re: Question about zram
So it's kernel and distribution dependent. Not mentioned anywhere in init (of initrd.gz) either? I'm not convinced that the data is being compressed though. Wouldn't it be better to stipulate the compressor and settings in rc.sysinit? Also - You say the default is set in the kernel, which I suppose to also mean that zram is invoked automatically. So if that is the case, why the section on creating the zram swap in rc.sysinit?
-
- Posts: 1588
- Joined: Sun Jul 12, 2020 2:38 am
- Location: S.E. Australia
- Has thanked: 246 times
- Been thanked: 711 times
Re: Question about zram
From wikipedia zram entry:
zram supports multiple compression streams and multiple compression algorithms. Compression algorithms include DEFLATE (DEFLATE), LZ4 (LZ4, and LZ4HC "high compression"), LZO (LZO-RLE "run-length encoding"),[2] Zstandard (ZSTD), 842 (842). From kernel 5.1, the default is LZO-RLE,[2] which has a balance of speed and compression ratio. Like most other system parameters, the compression algorithm can be selected via sysfs.[3]
Re: Question about zram
Getting there: https://www.kernel.org/doc/Documentatio ... v/zram.txt May as well add the user configuration to rc.sysinit in create swap section for zram which I think should be a logical approach. Anyways I can see the default values in /sys/block/zram0 so I suppose it's working correctly (in terms of default values).
-
- Posts: 2436
- Joined: Wed Dec 30, 2020 6:14 pm
- Has thanked: 53 times
- Been thanked: 1205 times
Re: Question about zram
No, because the default is part of the kernel. You can check the settings the kernel was compiled with:
Code: Select all
zcat /proc/config.gz | grep ^CONFIG_ZRAM
It is possible to make rc.sysinit force certain settings and override the kernel defaults (like forcing use of LZO if the kernel is configured to use xz as the zram default, a very bad idea unless you have a super fast CPU), but that means people have to change rc.sysinit to change zram settings and also replace the kernel, if the kernel they use doesn't support the algorithm they want to use (two steps instead of one).
amethyst wrote: Mon Jan 15, 2024 11:59 amI suppose to also mean that zram is invoked automatically. So if that is the case, why the section on creating the zram swap in rc.sysinit?
No. rc.sysinit creates the block device, puts a swap partition it, and enables it. Without this, the kernel supports zram but that's it, nothing actually uses zram.
-
- Posts: 723
- Joined: Fri Dec 13, 2019 6:26 pm
- Has thanked: 523 times
- Been thanked: 218 times
Re: Question about zram
Maybe mostly of historical interest, but here is a link to the Debian Wheezy (i think) era way of doing zram that still worked the last time I checked.
IIRC I changed the script to support lz4 because Fred's kernels support lz4.