Question about zram

an incubator for software projects


Moderator: Forum moderators

Post Reply
User avatar
amethyst
Posts: 2421
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Question about zram

Post by amethyst »

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?

dimkr
Posts: 2436
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1205 times

Re: Question about zram

Post by dimkr »

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.

User avatar
amethyst
Posts: 2421
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Question about zram

Post by amethyst »

Yes, but where can I find the instructions for the compression of the data and which compression method is going to be used?

dimkr
Posts: 2436
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1205 times

Re: Question about zram

Post by dimkr »

rc.sysinit doesn't set the compression algorithm and lets zram use the default chosen at kernel compilation time.

User avatar
amethyst
Posts: 2421
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Question about zram

Post by amethyst »

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?

ozsouth
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

Post by ozsouth »

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]

User avatar
amethyst
Posts: 2421
Joined: Tue Dec 22, 2020 6:35 am
Has thanked: 57 times
Been thanked: 506 times

Re: Question about zram

Post by amethyst »

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).

dimkr
Posts: 2436
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1205 times

Re: Question about zram

Post by dimkr »

amethyst wrote: Mon Jan 15, 2024 11:59 am

Not mentioned anywhere in init (of initrd.gz) either?

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 am

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?

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.

dancytron
Posts: 723
Joined: Fri Dec 13, 2019 6:26 pm
Has thanked: 523 times
Been thanked: 218 times

Re: Question about zram

Post by dancytron »

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.

https://www.forum.puppylinux.com/viewto ... 549#p78549

Post Reply

Return to “Development”