Choose LZ4 with zram where possible

This commit is contained in:
ThomasKaiser 2017-11-04 09:19:52 +01:00
parent c23d793ec4
commit e1ce4d7a66

View File

@ -363,6 +363,9 @@ add_usb_storage_quirks() {
} # add_usb_storage_quirks
activate_zram() {
# Do not interfere with already present config-zram package
dpkg -l | grep -q 'zram-config' && return
# Load zram module with n instances (one per CPU core, 4 are the maximum)
cpu_cores=$(grep -c '^processor' /proc/cpuinfo | sed 's/^0$/1/')
[[ ${cpu_cores} -gt 4 ]] && zram_devices=4 || zram_devices=${cpu_cores}
@ -372,11 +375,12 @@ activate_zram() {
# Use half of the real memory by default --> 1/${ram_divisor}
ram_divisor=2
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})
memory_total=$(awk '{printf("%d",$2*1024)}' <<<${mem_info})
mem_per_zram_device=$(( ${memory_total} / ${zram_devices} / ${ram_divisor} ))
for (( i=0; i<zram_devices; i++ )); do
echo -n ${mem_per_zram_device} > /sys/block/zram${i}/disksize
[[ -f /sys/block/zram${i}/comp_algorithm ]] && echo lz4 >/sys/block/zram${i}/comp_algorithm 2>/dev/null
mkswap /dev/zram${i}
swapon -p 5 /dev/zram${i}
done