mirror of
https://github.com/home-assistant/operating-system.git
synced 2025-07-27 23:16:31 +00:00
Use zswap instead of swap in zram (#2420)
* Use zswap instead of swap in zram This requires a swap file which will get generated automatically on startup. * Fix file size and free disk space comparison * Set zswap factor to 33% * Set vm.swappiness to 1 Decrease swapping to a minimum. This is also recommended for database work loads by the MariaDB documentation. In practice it causes the least amount of writes to disk when under memory pressure, while still making swap available when needed.
This commit is contained in:
parent
5c6330f70f
commit
75dcb932f8
@ -8,6 +8,9 @@ CONFIG_IKCONFIG_PROC=y
|
||||
CONFIG_MODULE_COMPRESS_NONE=y
|
||||
|
||||
CONFIG_ZRAM=y
|
||||
CONFIG_ZSWAP=y
|
||||
CONFIG_ZSWAP_DEFAULT_ON=y
|
||||
CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4=y
|
||||
CONFIG_ZSMALLOC=y
|
||||
|
||||
CONFIG_LRU_GEN=y
|
||||
|
@ -0,0 +1,2 @@
|
||||
# Decrease swapping to a minimum
|
||||
vm.swappiness=1
|
@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=HassOS ZRAM swap
|
||||
Requires=zram-swap.service
|
||||
After=zram-swap.service
|
||||
|
||||
[Swap]
|
||||
What=/dev/zram0
|
||||
|
||||
[Install]
|
||||
WantedBy=swap.target
|
@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=HAOS swap
|
||||
DefaultDependencies=no
|
||||
Requires=mnt-data.mount
|
||||
After=mnt-data.mount systemd-growfs@mnt-data.service
|
||||
Before=mnt-data-swapfile.swap
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/libexec/haos-swapfile
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=HAOS swap file
|
||||
|
||||
[Swap]
|
||||
What=/mnt/data/swapfile
|
||||
|
||||
[Install]
|
||||
WantedBy=swap.target
|
@ -1,15 +0,0 @@
|
||||
[Unit]
|
||||
Description=HassOS ZRAM swap
|
||||
DefaultDependencies=no
|
||||
Before=dev-zram0.swap
|
||||
RefuseManualStart=true
|
||||
RefuseManualStop=true
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/libexec/hassos-zram -t swap
|
||||
RemainAfterExit=true
|
||||
StandardOutput=null
|
||||
|
||||
[Install]
|
||||
WantedBy=hassos-zram.target
|
21
buildroot-external/rootfs-overlay/usr/libexec/haos-swapfile
Executable file
21
buildroot-external/rootfs-overlay/usr/libexec/haos-swapfile
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
swapfile="/mnt/data/swapfile"
|
||||
swapsize="$(awk '/MemTotal/{ print $2 * 0.33 }' /proc/meminfo)"
|
||||
|
||||
|
||||
if [ ! -s "${swapfile}" ] || [ "$(stat "${swapfile}" -c '%s')" -lt $((swapsize * 1024)) ]; then
|
||||
# Check free space (in 4k blocks)
|
||||
if [ "$(stat -f /mnt/data -c '%f')" -lt $((swapsize / 4)) ]; then
|
||||
echo "[WARNING] Not enough space to allocate swapfile"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dd if=/dev/zero of="${swapfile}" bs=1k count="${swapsize}"
|
||||
fi
|
||||
|
||||
if ! swaplabel "${swapfile}" > /dev/null 2>&1; then
|
||||
/usr/lib/systemd/systemd-makefs swap "${swapfile}"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user