Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount (Read 629 times) previous topic - next topic
0 Members and 4 Guests are viewing this topic.

[SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

So, I have installed zramen on my Artix with runit init and enabled it. But when I modify ZRAM_SIZE percentage at /etc/runit/sv/zramen/conf, it never surpasses the actual RAM amount, even if I put a value above 100% for ZRAM. I would know how to solve this issue. I remember that on Debian, I could exceed the actual RAM amount for zRAM,

Re: Zramen configuration for zRAM size doesn't exceed the actual RAM amount.

Reply #1
I'm using runit too:

Remove zramen and user /etc/rc.local:
Code: [Select]
#!/bin/sh
modprobe zram && echo lz4 > /sys/block/zram0/comp_algorithm && echo $(grep 'MemTotal:' /proc/meminfo|awk '{print $2}')K > /sys/block/zram0/disksize && mkswap -q /dev/zram0 && swapon -p100 /dev/zram0
exit 0

Use this  for 2*:
Code: [Select]
echo $(($(grep 'MemTotal:' /proc/meminfo|awk '{print $2}')*2))K
or this for 3/2 (150%):
Code: [Select]
echo $(($(grep 'MemTotal:' /proc/meminfo|awk '{print $2}')*3/2))K
or what ever you want.

lz4 ist fast and compress around 1:2, zstd is slower, but compress around 1:3

Re: Zramen configuration for zRAM size doesn't exceed the actual RAM amount.

Reply #2
To solve the problem, I have typed this on /etc/rc.local and I have made sure whether it was an executable file or not:

For setting zRAM twice the RAM amount size and set lz4 compression:

Code: [Select]
#!/bin/sh

modprobe zram
zramctl /dev/zram0 --algorithm lz4 --size "$(($(grep MemTotal /proc/meminfo | tr -dc '0-9')*2))KiB"
mkswap -U clear /dev/zram0
swapon --priority 100 /dev/zram0
exit 0

Re: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

Reply #3
Just to mention but the zramen script sets the size to a fraction of the ram (1/5), recommended size is a half or less, not double.
Setting zram too high worsens performance if whatever is in memory isn't compressible.

Re: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

Reply #4
Just to mention but the zramen script sets the size to a fraction of the ram (1/5), recommended size is a half or less, not double.
Thats wrong. Look:
Quote
There is little point creating a zram of greater than twice the size of memory since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the size of the disk when not in use so a huge zram is wasteful.
https://www.kernel.org/doc/Documentation/admin-guide/blockdev/zram.rst

Re: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

Reply #5
Thats wrong. Look:
Quote
There is little point creating a zram of greater than twice the size of memory since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the size of the disk when not in use so a huge zram is wasteful.
https://www.kernel.org/doc/Documentation/admin-guide/blockdev/zram.rst
You are comprehending that different to me. To me it says don't go over a size twice the size of ram but doesn't actually recommend a zram twice the size of ram.
I hate to doubt the kernel documentation but a 2:1 compression ratio is optimistic and hard to guarantee.

From the Arch wiki
Quote
A simple size to start with is half of the total system memory.
If I was to use zram I would not go over the size of physical ram as there's every chance there will be occasions when  /tmp contains largely already compressed data

My preferred setup. Lot's of real ram. No swap, no zswap, no zram, Simple.

But things starting z... do sound cool so maybe I'm missing out?

Re: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

Reply #6
In RAM are only decodet things, witch usualy can be compressed very good. So 2:1 for lz4 and 3:1 for zstd ist realistic. - I tested a lot.

I have 32G RAM and need zRAM sometimes to compress with 7zip and 4G dictionary size: it needs up to 42G RAM, so without zRAM it doesn't work.

Because it costs nearly nothing, its better to have it and not need it, than vice versa.

Re: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

Reply #7
@Caramon2 My excuses if you know this already, i get what you're using it for, but keeping in mind that zram is like a ram disk it stores what's swapped next to what isn't (hence the recommendation to set swappiness very high), so it doesn't directly compress memory like zswap does (too bad the latter isn't too well documented), if you target 2x memory compressibility potential you set the zram size closer to like 1-1.5x (150% like you said), conversly when 2x zram size is documented it assumes the best possible ~3-4x ratio but it doesn't depend on just the algorithm.

Re: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

Reply #8
I'm using zRAM-Disks too::

"mkzram" (without ".sh"):
Code: [Select]
#!/bin/bash
if [ $# == 0 ];then echo "mkzram [Size in G] [zstd] (otherwise lz4)";exit;fi
al=lz4
if [ $2 == "zstd" ] 2>/dev/null;then al=zstd;fi
if [ ! -e /dev/zram* ] 2>/dev/null
then sudo modprobe zram;id=0
else id=$(sudo cat /sys/class/zram-control/hot_add)
fi
echo $al|sudo tee /sys/block/zram$id/comp_algorithm >/dev/null
echo $1"G"|sudo tee /sys/block/zram$id/disksize >/dev/null
sudo mkfs.xfs -q /dev/zram$id && mkdir /tmp/zram$id
sudo mount -o discard /dev/zram$id /tmp/zram$id/ && sudo chmod 777 /tmp/zram$id/
zramctl -o name,algorithm,disksize,data,compr,mountpoint

"rmzram" (without ".sh"):
Code: [Select]
#!/bin/bash
if [ $# == 0 ];then echo "rmzram [ID]:";zramctl -o name,algorithm,disksize,data,compr,mountpoint;exit;fi
sudo umount -l /tmp/zram$1/ && rm -rf /tmp/zram$1
echo $1|sudo tee /sys/class/zram-control/hot_remove > /dev/null
if [ ! -e /dev/zram* ] 2>/dev/null;then sudo modprobe -r zram;fi
zramctl -o name,algorithm,disksize,data,compr,mountpoint

/tmp/ is in RAM, /tmph/ for huge Files (i. e. DVB-S Videocut):
Code: [Select]
memory                                    /tmp  tmpfs nosuid,size=90%      0 0
memory                                    /tmph tmpfs huge=always,size=90% 0 0
(from my /etc/fstab)

As said: I tested a lot. :)

Re: [SOLVED] Zramen configuration for zRAM size doesn't exceed the actual RAM amount

Reply #9
For setting zRAM twice the RAM amount size and set lz4 compression:
My Version (look #2), don't need zramctl and uses errorchecking (the "&&").

but keeping in mind that zram is like a ram disk it stores what's swapped next to what isn't, so it doesn't directly compress memory like zswap does, if you target 2x memory compressibility potential you set the zram size closer to like 1-1.5x (150% like you said)
I tryed zswap and it was bad, because it permanently reserve RAM, whitch you ca. use anymore (here in german (my english is to bad, to translate the nesesary: https://www.computerbase.de/forum/threads/zswap-vs-zram-vs-zram-disk.2107871/ )

With zRAM my calculation is simple:

With 100% and lz4 usualy max. 50% memory is used, when zRAM-Swap is full.

With 150% and zstd again max. 50% memory is used, when zRAM-Swap is full, because of the higher (but slower) compression.

For my 7zip 4G dict-Test and 32G RAM lz4 compression was enough and a lot faster then with zstd. That zstd kept more RAM free for 7zip to work, was not the expected advantage.