Enabling ZRAM in EndeavourOS

ZRAM is very efficiently compressing information in the RAM and creates a kind of the virtual SWAP device, which actualy do not takes physical space on yours SWAP partition.
It comes with a tradeoff of the a little bit perfomance that’s being taken to compress and unpack data. but ZRAM is active by default even on the android so it’s not hard to guess how little we’re paying for having more RAM out of nothing.

  1. Install it.
sudo pacman -Syu zram-generator
  1. Create config file
sudo nano /usr/lib/systemd/zram-generator.conf

Paste this in ctrl+shift+v in terminal or use gedit/kate isntead of nano:

[zram0]
zram-size=ram
compression-algorithm=zstd
swap-priority=60
  1. Activate it
sudo systemctl daemon-reload
sudo systemctl start /dev/zram0
  1. Check with htop, you should have now a Swp parameter, or if you already had swap file, it’s size should increace on the same value as a RAM that you have.
    If not, try to reboot.
  • Also you can check is it working by the other way -
sudo dmesg | grep zram     
  1. To prevent conflicts, Arch wiki recommending to disable zswap, so lets do it. I have no idea why on wiki there’s no info that you can disable it in the grub.
sudo nano /etc/default/grub

In the line locate GRUB_CMDLINE_LINUX_DEFAULT add in the end zswap.enabled=0"
image

    1. sudo grub-mkconfig -o /boot/grub/grub.cfg
  1. Check that the zswap is disabled.

sudo dmesg | grep zswap    
  1. Reboot.
8 Likes

Absolutely not, there are a lot of people like myself who have enough RAM to never use or care about any valid reasons to use swap at all.

That should be left to user.

4 Likes

Idk, in my opinion there’s never enough RAM.
Besides of that, we already have zswap running by the default, which in most of the cases is inferior.

Sure, but it doesn’t work if you doesn’t use swap

The difference compared to zram is that zswap works in conjunction with a swap device while zram is a swap device in RAM that does not require a backing swap device.

(c) https://wiki.archlinux.org/title/zswap

1 Like

The question of “defaults” is rather tricky. What works for you might not work for others. Any distro (not just EndeavourOS) is most probably being run on a variety of hardware and for various use cases. Its not possible to ship such defaults that suit everyone.

For example,

this is probably a good configuration for you, it certainly is not suitable for my hardware or use case. Yes, the user can change it as per their preferences, but how many will actually change it?

While its won’t harm to ship some sane defaults, its better to stick to vanilla.

All this is personal opinion

That being said, thanks for the guide!

I can relate :melting_face:
*running two virtual machines, while compiling applications on host and sending this message via Firefox on the same machine

3 Likes

zram-fraction and max-zram-size are obsolete. zram-size is all you need.

3 Likes

Many thanks.

erm this part didnt work for me: 1. grub-mkconfig -o /boot/grub/grub.cfg
/usr/bin/grub-mkconfig: line 265: /boot/grub/grub.cfg.new: No such file or directory

erm is this the dracut thing?
does anybody know how to update dracut one? Sorry if someone already posted it… I’m a noobbbb…
many thanks!

That command needs sudo. It won’t work as a regular user.

What does swap-priority 60 do?

When having only one swap device, the priority doesn’t matter.

When using multiple swap devices, you want to edit priorities so as to let both swap devices be used equally.

From swapon manpage

Priority
       Each swap area has a priority, either high or low.  The default
       priority is low.  Within the low-priority areas, newer areas are
       even lower priority than older areas.

       All priorities set with swapflags are high-priority, higher than
       default.  They may have any nonnegative value chosen by the
       caller.  Higher numbers mean higher priority.

       Swap pages are allocated from areas in priority order, highest
       priority first.  For areas with different priorities, a higher-
       priority area is exhausted before using a lower-priority area.
       If two or more areas have the same priority, and it is the
       highest priority available, pages are allocated on a round-robin
       basis between them.

This is not to be confused with swappiness.

3 Likes

swap-priority=
Controls the relative swap priority, a value between -1 and 32767. Higher numbers indicate higher priority.
If unset, 100 is used.

:eye: https://man.archlinux.org/man/zram-generator.conf.5

2 Likes

Would enabling ZRAM not slow down a system that already has more than enough ram, like I have 32gb of ram, Why would I need to enable ZRAM?

If you are not utilizing all your ram, you don’t need zram in the first place.

However, if your ram usage is shooting past 32gb, then zram will help. Keep in mind, if you make the zram size too large, it will probably backfire under higher load.

1 Like

Because running out of RAM is problematic unless you are running an OOM killer. In most cases, it will result in a a hard freeze.

The answer that most people don’t like to hear is that there is not a simple “right answer”. Whether to use a swap partition, a swap file, zswap, zram, no swap or some combination depends on the individual’s workload and hardware.

I will say that using zram is actually a pretty good default for most desktop use cases.

2 Likes

Yes I just have one swap zram0 setup for 4GB. I have 16GB.

Btw do you have a YouTube channel where you did a video on zram? I remember a similar name.

Thanks for the tips

1 Like

Yes, that’s the one. I remember watching it.

Great content for new users

So if I enable this, it will use all my ram as a compressed swap? Aproximately how much more ram space I will get out of this? 10%? Or more?

I have 14 gigs, and I had situations where it wasn’t enough and the system slowed down a lot, even with a nvme ssd. But I guess, I will still need a regular swapfile.

Is lz4 the fastest?

Yes.

However an obligatory note : the config format has changed after I made the video. As usual, the new config too is “readable”. Rest of the steps remain same.

1 Like