From c24ceea4b1315f79ae26618191d2c193ee9fab01 Mon Sep 17 00:00:00 2001 From: Thomas Kaiser Date: Thu, 6 Sep 2018 21:56:51 +0200 Subject: [PATCH] Allow also RAMLOG_ALGORITHM to be defined with zram --- .../usr/lib/armbian/armbian-zram-config | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/bsp/common/usr/lib/armbian/armbian-zram-config b/packages/bsp/common/usr/lib/armbian/armbian-zram-config index 7463f35999..eb77aa4c0a 100755 --- a/packages/bsp/common/usr/lib/armbian/armbian-zram-config +++ b/packages/bsp/common/usr/lib/armbian/armbian-zram-config @@ -8,7 +8,8 @@ # Functions: # -# activate_zram +# activate_zram_swap +# activate_ramlog_partition # Read in basic OS image information @@ -16,13 +17,13 @@ # and script configuration . /usr/lib/armbian/armbian-common -# ZRAM_PERCENTAGE, ZRAM_MAX_DEVICES and SWAP_ALGORITHM can be defined there: +# ZRAM_PERCENTAGE, ZRAM_MAX_DEVICES, SWAP_ALGORITHM and RAMLOG_ALGORITHM can be defined: [ -f /etc/default/armbian-zram-config ] && . /etc/default/armbian-zram-config activate_zram_swap() { - # Do not interfere with already present config-zram package dpkg -l | grep -q 'zram-config' && exit 0 + [[ "$ENABLED" != "true" ]] && exit 0 # Load zram module with n instances (one per CPU core, $ZRAM_MAX_DEVICES are the max) @@ -45,7 +46,7 @@ activate_zram_swap() { mkswap /dev/zram${i} swapon -p 5 /dev/zram${i} done - echo -e "### Activated ${zram_devices} zram swap devices with $(( ${mem_per_zram_device} / 1048576 )) MB each\n" >>${Log} + echo -e "\n### Activated ${zram_devices} zram swap devices with $(( ${mem_per_zram_device} / 1048576 )) MB each\n" >>${Log} } # activate_zram_swap activate_ramlog_partition() { @@ -58,10 +59,16 @@ activate_ramlog_partition() { ramlogsize=$(awk -F"=" '/^SIZE/ {print $2}' /etc/default/armbian-ramlog) disksize=$(sed -e 's/M$/*1048576/' -e 's/K$/*1024/' <<<${ramlogsize:=50M} | bc) - # Try to choose most efficient compression scheme available -- https://patchwork.kernel.org/patch/9918897/ - for algo in lz4 quicklz zlib brotli zstd ; do - echo ${algo} >/sys/block/zram0/comp_algorithm 2>/dev/null - done + # choose RAMLOG_ALGORITHM if defined in /etc/default/armbian-zram-config + # otherwise try to choose most efficient compression scheme available. + # See https://patchwork.kernel.org/patch/9918897/ + if [ -n ${RAMLOG_ALGORITHM} ]; then + echo ${RAMLOG_ALGORITHM} >/sys/block/zram0/comp_algorithm 2>/dev/null + else + for algo in lz4 lz4hc quicklz zlib brotli zstd ; do + echo ${algo} >/sys/block/zram0/comp_algorithm 2>/dev/null + done + fi echo -n ${disksize} > /sys/block/zram0/disksize # if it fails, select $swap_algo. Workaround for some older kernels @@ -72,7 +79,7 @@ activate_ramlog_partition() { mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/zram0 algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' >${Log} + echo -e "### Activated Armbian ramlog partition with ${algo} compression" >>${Log} } # activate_ramlog_partition case $1 in