Add and configure 20% of memory as zram swap with a low agressive swappiness

This commit is contained in:
j1nx 2021-03-01 21:58:30 +01:00
parent e54ba60296
commit 70fa66f615
7 changed files with 102 additions and 0 deletions

View File

@ -1,3 +1,6 @@
CONFIG_SND_SOC_WM8960=m
# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
CONFIG_ZRAM=y
CONFIG_ZSMALLOC=y

View File

@ -465,6 +465,7 @@ BR2_PACKAGE_UTIL_LINUX_BINARIES=y
BR2_PACKAGE_UTIL_LINUX_HWCLOCK=y
BR2_PACKAGE_UTIL_LINUX_KILL=y
BR2_PACKAGE_UTIL_LINUX_MORE=y
BR2_PACKAGE_UTIL_LINUX_ZRAMCTL=y
BR2_PACKAGE_NANO=y
BR2_PACKAGE_VIM=y
# BR2_PACKAGE_VIM_RUNTIME is not set

View File

@ -0,0 +1 @@
vm.swappiness = 20

View File

@ -0,0 +1,10 @@
[Unit]
Description=OVOS ZRAM swap
Requires=zram-swap.service
After=zram-swap.service
[Swap]
What=/dev/zram0
[Install]
WantedBy=swap.target

View File

@ -0,0 +1,6 @@
[Unit]
Description=OVOS zram targets
Documentation=man:systemd.target(5)
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,15 @@
[Unit]
Description=OVOS ZRAM swap
DefaultDependencies=no
Before=dev-zram0.swap
RefuseManualStart=true
RefuseManualStop=true
[Service]
Type=oneshot
ExecStart=/usr/libexec/ovos-zram -t swap
RemainAfterExit=true
StandardOutput=null
[Install]
WantedBy=ovos-zram.target

View File

@ -0,0 +1,66 @@
#!/bin/sh
# Credits go to: https://github.com/home-assistant/operating-system/
set -e
#### Options ####
TYPE=""
MOUNT=""
DEVICE=""
SIZE=0
#### Parse arguments ####
while [ "$1" != "" ]; do
key=$1
case $key in
-t|--type)
TYPE=$2
shift
;;
-s|--size)
SIZE=$2
shift
;;
-m|--mount)
MOUNT=$2
shift
;;
*)
echo "[Error] $0 : Argument '$1' unknown"
exit 1
;;
esac
shift
done
# Valide Type
if [ "$TYPE" != "swap" ]; then
echo "[Error] Type unknown!"
exit 1
fi
# Lookup device
if [ "$TYPE" = "swap" ]; then
DEVICE="/dev/zram0"
#elif [ "$MOUNT" = "var" ]; then
# DEVICE="/dev/zram1"
#elif [ "$MOUNT" = "tmp" ]; then
# DEVICE="/dev/zram2"
else
echo "[Error] No device for lookup!"
exit 1
fi
# Calc 20% of memory for ZRAM swap partition
if [ "$TYPE" = "swap" ] && [ "$SIZE" -eq "0" ]; then
SIZE="$(awk '/MemTotal/{ print $2 * 0.20 }' /proc/meminfo)K"
fi
# Init device
zramctl "$DEVICE" -s "$SIZE" -a lz4
# Swap
if [ "$TYPE" = "swap" ]; then
mkswap -L "ovos-zramswap" "$DEVICE"
fi