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