Enabling ZRAM in EndeavourOS

You can set that in your ZRAM config.

My systems with 8 GB or 16 GB RAM work well with 50% ZRAM size. No slowdowns.

On my old desktop with a dual core processor and 4 GB RAM, I couldn’t go past 25% (i.e. 1 GB ZRAM).

So its dependent on your system specs.

Talking about use case, ZRAM comes in very handy when I’m multitasking, running many apps at once, and usually also having VM running in background. On the other hand, when compiling applications, I rarely ever see significant ZRAM usage.

Once you go out of memory, system will slow down, irrespective of your storage backend. Have swap space, so that your system doesn’t suddenly become unresponsive. Again, ZRAM will surely help with this.

I don’t know your exact use case, but I don’t see a reason why you would want a normal swapfile if ZRAM can do what you want to.

Technically, speaking it should be. (unless my memory is going haywire)

LZO and LZ4 are almost similar. ZSTD is slightly slower, but offers slightly better compression too.

PS. I’m not an expert at compression algorithms, so if someone spots a mistake, please comment :slight_smile:

1 Like

What is the difference between ZRAM and SWAP

zram is compressed swap in ram.

zswap is is a compressed cache that sits in front of your normal swap.

1 Like

I installed Fedora on my laptop. It has 8 GB of RAM and Fedora sets zram-size to 8 GB. I was surprised when I first saw that, but this is in fact the default setup for 8GB RAM. Nicely explained in this wiki article.

https://fedoraproject.org/wiki/Changes/SwapOnZRAM

This article also answers your questions about the net memory gain of zram. It reads:

  • A system has 16 GiB RAM. The proposed defaults suggest the /dev/zram0 device will be 4 GiB. If the workload completely fills up swap with 4 GiB of anonymous pages, what’s happened? The zramctl command will display the true compression ratio. If 2:1 is really obtained, it means 4GiB swap data is compressed to 2GiB. Therefore 2GiB is the actual RAM usage, and is also the net effective eviction. i.e. 4 GiB anonymous pages are evicted, but are then compressed and pinned into 2 GiB RAM, for a net memory savings of 2 GiB.

In an nutshell: 50 % of the zram-size is the netto gain in memory.

3 Likes

Is my zswap disabled?
I checked the wiki, it says the same on how to disable.

[csaba@csaba-mini ~]$ sudo dmesg | grep zswap    
[sudo] password for csaba: 
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-linux-zen root=UUID=5570a0d2-c1ef-4128-af09-0e7f8a2d5b34 rw nowatchdog quiet nvme_load=YES loglevel=3 zswap.enabled=0
[    0.024231] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-linux-zen root=UUID=5570a0d2-c1ef-4128-af09-0e7f8a2d5b34 rw nowatchdog quiet nvme_load=YES loglevel=3 zswap.enabled=0
[    0.594933] zswap: loaded using pool zstd/zsmalloc
[csaba@csaba-mini ~]$ grep -R . /sys/module/zswap/parameters
/sys/module/zswap/parameters/same_filled_pages_enabled:Y
/sys/module/zswap/parameters/enabled:N
/sys/module/zswap/parameters/max_pool_percent:20
/sys/module/zswap/parameters/compressor:zstd
/sys/module/zswap/parameters/non_same_filled_pages_enabled:Y
/sys/module/zswap/parameters/zpool:zsmalloc
/sys/module/zswap/parameters/accept_threshold_percent:90

I think this shows that it is disabled. The N would mean that none of the parameters listed in your output would actually have any effect I guess.

Sorry for asking questions after 7+ months from the last reply. What I understood from this post that I shall disable zswap and only leave zram enabled for efficient use. Do I have to set a dedicated partition for swap as I want my machine to be suspended while I am away? I guess hibernate won’t be necessary as it’s a laptop, always stays on desk.

1 Like

No, you do not need a swap file or swap partition for the suspend state like you do for hibernation.

If down the road you change your mind and would like to set up hibernation, it’s pretty easy to make a swap file for that.

2 Likes

Thank you so much for the clarification.

1 Like

No problem. :slightly_smiling_face:

By the way, welcome to the community @endeavouros-user. :wave:

1 Like

can anyone tell me where i set the swappyness for zram i forgot

1 Like

See https://wiki.archlinux.org/title/Zram. This page shows some recommended settings which are already set on my system.

Generally:

  • if you want to set values you can define them in files in /etc/sysctl.d . Then they will be taken after boot.
  • if you want to set a value in a running system use sysctl
3 Likes

ok

1 Like

Hey, I followed you youtube video but zram is not created for me, the script is totally changed please could you look into it, My pc has 7.1GiB ram + 512MB integrated graphics:

# This file is part of the zram-generator project
# https://github.com/systemd/zram-generator

[zram0]
# This section describes the settings for /dev/zram0.
#
# The maximum amount of memory (in MiB). If the machine has more RAM
# than this, zram device will not be created.
#
# "host-memory-limit = none" may be used to disable this limit. This
# is also the default.
host-memory-limit = none

# The size of the zram device, as a function of MemTotal, both in MB.
# For example, if the machine has 1 GiB, and zram-size=ram/4,
# then the zram device will have 256 MiB.
# Fractions in the range 0.1–0.5 are recommended.
#
# The default is "min(ram / 2, 4096)".
zram-size =  ram / 2

# The compression algorithm to use for the zram device,
# or leave unspecified to keep the kernel default.
compression-algorithm = lzo-rle

# By default, file systems and swap areas are trimmed on-the-go
# by setting "discard".
# Setting this to the empty string clears the option.
#options =

# Write incompressible pages to this device,
# as there's no gain from keeping them in RAM
writeback-device = /dev/zvol/tarta-zoot/swap-writeback

# The following options are deprecated, and override zram-size.
# These values would be equivalent to the zram-size setting above.
zram-fraction = 0.5
max-zram-size = 4000

Where did you save the config file you posted? (The exact path.)

Please also post the output of:

inxi -j

I copied the example conf file from:
/usr/share/doc/zram-generator/zram-generator.conf.example

and saved it to:
/etc/systemd/zram-generator.conf

edited the file
then: systemctl daemon-reload
then: systemctl start /dev/zram0

inxi -j

Swap:
  Alert: No swap data was found.

The example conf file was:

# This file is part of the zram-generator project
# https://github.com/systemd/zram-generator

[zram0]
# This section describes the settings for /dev/zram0.
#
# The maximum amount of memory (in MiB). If the machine has more RAM
# than this, zram device will not be created.
#
# "host-memory-limit = none" may be used to disable this limit. This
# is also the default.
host-memory-limit = 9048

# The size of the zram device, as a function of MemTotal, both in MB.
# For example, if the machine has 1 GiB, and zram-size=ram/4,
# then the zram device will have 256 MiB.
# Fractions in the range 0.1–0.5 are recommended.
#
# The default is "min(ram / 2, 4096)".
zram-size = min(ram / 10, 2048)

# The compression algorithm to use for the zram device,
# or leave unspecified to keep the kernel default.
compression-algorithm = lzo-rle

# By default, file systems and swap areas are trimmed on-the-go
# by setting "discard".
# Setting this to the empty string clears the option.
options =

# Write incompressible pages to this device,
# as there's no gain from keeping them in RAM
writeback-device = /dev/zvol/tarta-zoot/swap-writeback

# The following options are deprecated, and override zram-size.
# These values would be equivalent to the zram-size setting above.
#zram-fraction = 0.10
#max-zram-size = 2048


[zram1]
# This section describes the settings for /dev/zram1.
#
# host-memory-limit is not specified, so this device will always be created.

# Size the device to a tenth of RAM.
zram-size = ram / 10

# The file system to put on the device. If not specified, ext2 will be used.
fs-type = ext2

# Where to mount the file system. If a mount point is not specified,
# the device will be initialized, but will not be used for anything.
mount-point = /run/compressed-mount-point

Just a sanity check - did you use sudo? And did either of the command report errors when you ran them?

Also, could you share the output of this command:

systemctl status /dev/zram0

and

zramctl

That’s a detailed example outlining the configuration for advanced users.

You maybe want to set a maximum RAM size and that’s it. No need to specify anything else.

[zram0]
zram-size = ram / 2
2 Likes

I agree that the configuration file you are using is likely the cause of your issue. It is only meant to be an example file, to show some of the options which are possible.

Some of those options need to be set up first before you can use them. For example, you have a writeback device in your config but those need to be configured on their own first: https://wiki.archlinux.org/title/Zram#Enabling_a_backing_device_for_a_zram_block. It is possible the configuration you have specified is simply invalid.

I think the suggestion to set up a simple config with only the zram size is a good one. Then reboot and check that it works as expected. After that, you can add additional options in one at a time if there is something else you want to configure.