vaeth / zram-init

A wrapper script for the zram linux kernel module with zsh and openrc support
http://www.mathematik.uni-wuerzburg.de/~vaeth/download/index.html#zram-init
79 stars 26 forks source link

use a sane default memory size for zram devices #16

Closed sedlund closed 5 years ago

sedlund commented 5 years ago

Ubuntu/Debian etc use a sane default not predetermined number for enabling zram

# Calculate memory to use for zram (1/2 of ram)
totalmem=`LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/  *.*//'`
mem=$(((totalmem / 2 / ${NRDEVICES}) * 1024))
vaeth commented 5 years ago

I am not sure whether RAM/2 is “sane”. It really depends on the requirements. But you are right, that it would be a good idea to use such a thing in the example config.

(Though with better code: Why combine grep+sed if sed alone can do the same? Or use awk to get even simpler code and do also the numerics...)

Unfortunately, these possibilities exist only with openrc. With systemd and its sh-is-bad insanity it is probably not so easy.

sedlund commented 5 years ago

I use this for coreos

        [Unit]
        Before=docker.service
        ConditionPathExists=!/dev/zram0
        [Install]
        RequiredBy=docker.service
        [Service]
        Type=oneshot
        ExecStartPre=/usr/bin/sh -c "/usr/bin/systemctl set-environment SIZE=$(( $( free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/  *.*//') * 3 / 2 ))000"
        ExecStart=/usr/sbin/modprobe zram
        ExecStart=/usr/sbin/zramctl -f -s $SIZE
        ExecStart=/usr/sbin/mkswap /dev/zram0

Consensus of Debian and Ubuntu seems to be half RAM for a sane default.

vaeth commented 5 years ago

Pushed

sedlund commented 5 years ago

Awesome I will give it a try. Thanks