Allow also RAMLOG_ALGORITHM to be defined with zram

This commit is contained in:
Thomas Kaiser 2018-09-06 21:56:51 +02:00 committed by GitHub
parent 3d0a5a38ca
commit c24ceea4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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' </sys/block/zram0/comp_algorithm)
echo -e "### Activated Armbian ramlog partition with ${algo} compression\n" >>${Log}
echo -e "### Activated Armbian ramlog partition with ${algo} compression" >>${Log}
} # activate_ramlog_partition
case $1 in