Introduce MEM_LIMIT_PERCENTAGE variable for zram
(defaulting to 50% so zram will not use more than this treshold anyway
This commit is contained in:
parent
c1530db482
commit
9688c96a04
@ -3,11 +3,18 @@
|
||||
# enable the armbian-zram-config service?
|
||||
ENABLED=true
|
||||
|
||||
# percentage of zram usage compared to physically available DRAM.
|
||||
# percentage of zram used as swap 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
|
||||
# and don't forget to adjust $MEM_LIMIT_PERCENTAGE below too.
|
||||
# ZRAM_PERCENTAGE=50
|
||||
|
||||
# percentage of DRAM available to zram. If this amount is exceeded the zram
|
||||
# devices used for swap simply behave as if the device is full. You need to
|
||||
# adjust/increase this value only if you want to work with massive memory
|
||||
# overcommitment (ZRAM_PERCENTAGE exceeding 150 for example)
|
||||
# MEM_LIMIT_PERCENTAGE=50
|
||||
|
||||
# create how many zram devices max for swap
|
||||
# ZRAM_MAX_DEVICES=4
|
||||
|
||||
|
||||
@ -35,16 +35,21 @@ activate_zram_swap() {
|
||||
module_args="$(modinfo zram | awk -F" " '/num_devices/ {print $2}' | cut -f1 -d:)"
|
||||
[[ -n ${module_args} ]] && modprobe zram ${module_args}=$(( ${zram_devices} + 2 )) || return
|
||||
|
||||
# Use 50% of real memory by default
|
||||
# Expose 50% of real memory as swap space by default
|
||||
zram_percent=${ZRAM_PERCENTAGE:=50}
|
||||
mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem")
|
||||
memory_total=$(awk '{printf("%d",$2*1024)}' <<<${mem_info})
|
||||
mem_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${zram_percent} / 100 ))
|
||||
|
||||
# Limit memory available to zram to 50% by default
|
||||
mem_limit_percent=${MEM_LIMIT_PERCENTAGE:=50}
|
||||
mem_limit_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${mem_limit_percent} / 100 ))
|
||||
|
||||
swap_algo=${SWAP_ALGORITHM:=lzo}
|
||||
for (( i=1; i<=zram_devices; i++ )); do
|
||||
[[ -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
|
||||
echo -n ${mem_limit_per_zram_device} > /sys/block/zram${i}/mem_limit
|
||||
mkswap /dev/zram${i}
|
||||
swapon -p 5 /dev/zram${i}
|
||||
done
|
||||
|
||||
Loading…
Reference in New Issue
Block a user