Make SWAP_ALGORITHM also configurable with zram swap
This commit is contained in:
parent
4804c91114
commit
e0d8b11ade
@ -2,6 +2,14 @@
|
||||
#
|
||||
# enable the armbian-zram-config service?
|
||||
ENABLED=true
|
||||
#
|
||||
# size of the partition for ramlog in megabytes
|
||||
SIZE=50
|
||||
|
||||
# percentage of zram usage compared to physically available DRAM.
|
||||
# Huge overcommitment (300) is possible and sometimes desirable. See
|
||||
# https://forum.armbian.com/topic/5565-zram-vs-swap/?do=findComment&comment=61082
|
||||
# ZRAM_PERCENTAGE=50
|
||||
|
||||
# create how many zram devices max for swap
|
||||
# ZRAM_MAX_DEVICES=4
|
||||
|
||||
# Which algorithm to choose for zram based swapping
|
||||
# SWAP_ALGORITHM=lz4
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
# and script configuration
|
||||
. /usr/lib/armbian/armbian-common
|
||||
|
||||
# ZRAM_PERCENTAGE and ZRAM_MAX_DEVICES can be defined in /etc/default/armbian-zram-config
|
||||
# ZRAM_PERCENTAGE, ZRAM_MAX_DEVICES and SWAP_ALGORITHM can be defined there:
|
||||
[ -f /etc/default/armbian-zram-config ] && . /etc/default/armbian-zram-config
|
||||
|
||||
activate_zram() {
|
||||
@ -38,8 +38,9 @@ activate_zram() {
|
||||
memory_total=$(awk '{printf("%d",$2*1024)}' <<<${mem_info})
|
||||
mem_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${zram_percent} / 100 ))
|
||||
|
||||
swap_algo=${SWAP_ALGORITHM:=lz4}
|
||||
for (( i=1; i<=zram_devices; i++ )); do
|
||||
[[ -f /sys/block/zram${i}/comp_algorithm ]] && echo lz4 >/sys/block/zram${i}/comp_algorithm 2>/dev/null
|
||||
[[ -f /sys/block/zram${i}/comp_algorithm ]] && echo ${swap_algo} >/sys/block/zram${i}/comp_algorithm 2>/dev/null
|
||||
echo -n ${mem_per_zram_device} > /sys/block/zram${i}/disksize
|
||||
mkswap /dev/zram${i}
|
||||
swapon -p 5 /dev/zram${i}
|
||||
@ -53,9 +54,9 @@ activate_zram() {
|
||||
done
|
||||
echo -n $(($SIZE*1024*1024)) > /sys/block/zram0/disksize
|
||||
|
||||
# if it fails, select lz4. Workaround for some older kernels
|
||||
# if it fails, select $swap_algo. Workaround for some older kernels
|
||||
if [[ $? == 1 ]]; then
|
||||
echo lz4 > /sys/block/zram0/comp_algorithm 2>/dev/null
|
||||
echo ${swap_algo} > /sys/block/zram0/comp_algorithm 2>/dev/null
|
||||
echo -n $(($SIZE*1024*1024)) > /sys/block/zram0/disksize
|
||||
fi
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user