Closed zpuskas closed 3 years ago
Thank you for the report. However, for consistency with the size (discsize) option, I decided to not use units but instead to fix the bug and make it work with megabytes as it was documented. I am aware that this might break existing configs without a warning, but I prefer to have interface consistency. This is fixed in zram-10.10.
Problem
Help text in example configuration
/etc/conf.d/zram-init
says:# mlim0, mlim1, ... are the variables for the maximal uncompressed memory (MB)
Using this option as per the help text results in service startup failure, as the filesystem creation fails on the ZRAM device. Any value written to this parameter will be interpreted in bytes, with a 8kB memory limit (minimum amount apparently) for any value less than 8192 (e.g. 6144 is supposed to be 6GB, but it's understood as 6kB, which is rounded up to the minimum of 8kB), and the actual kB amount above that.
File system creation fails, because we immediately fill up the tiny memory limit, regardless of the disk size specified for the ZRAM device.
Example failure when starting the zram-init service with ext2 filesystem:
Example failure when starting the zram-init service with btrfs filesystem:
Tried filesystem creation manually for more verbose error messages:
Rootcause
This setting expects only numbers as per zram-init.in:L262, and will not take sizes with unit suffixes, e.g.
1024M
, or4G
. The number set for memory limit is actually in bytes not in megabytes because the raw number is passed toSysCtl
function zram-init.in:L388, which simply writes it into the/sys
file system on zram-init.in:L68.Proposed solution
Since this option is most likely used as a safety feature (e.g. preventing ZRAM to consume all memory for larger filesystems), the solution should be backward compatible with existing configurations, where people set the value in bytes.
I propose to allow passing in numbers with unit suffixes in
mlim
option, e.g. 512M or 4G, since the ZRAM/sys
filesystem supports it. E.g.:echo 4G > /sys/block/zram0/mem_limit