aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-extended/zram/zram/zram-swap-init
blob: ccc3aafe3a6f5a4148d27c602f04a2e8c4f55e6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
set -e

device=$1
if [ "$device" = "" ]; then
    echo "Usage: zram-swap-init <device>"
    exit 1
fi

# Allocate zram to be size of actual system memory
# Note: zram is only allocated when used. When swapped pages compress with a
# a 2:1 ratio zram will require 50% of system memory (while allowing to use
# 150% memory).
ZRAM_SIZE_PERCENT=100
ZRAM_ALGORITHM=lz4

[ -f /etc/default/zram ] && . /etc/default/zram || true

memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
memzram=$(($memtotal*${ZRAM_SIZE_PERCENT}/100))

# Try loading zram module
modprobe -q zram || true

zramctl -a ${ZRAM_ALGORITHM} -s ${memzram}KB $device
mkswap -L "zram-swap" $device