$ free -m
               total        used        free      shared  buff/cache   available
Mem:             477          30         411           1          34         404
Swap:              0           0           0
$ sudo /boot/dietpi/func/dietpi-set_swapfile 476 zram
 DietPi-Set_swapfile
─────────────────────────────────────────────────────
 Mode: Applying 428 zram
[ INFO ] DietPi-Set_swapfile | Disabling and deleting all existing swap files
[  OK  ] DietPi-Set_swapfile | swapoff -a
[  OK  ] DietPi-Set_swapfile | Generating new swap space
[ INFO ] DietPi-Set_swapfile | Size = 476 MiB
[ INFO ] DietPi-Set_swapfile | Path = /dev/zram0
[  OK  ] DietPi-Set_swapfile | eval echo 1 > /sys/block/zram0/reset
[  OK  ] DietPi-Set_swapfile | eval echo '476M' > /sys/block/zram0/disksize
[  OK  ] DietPi-Set_swapfile | chmod 0600 /dev/zram0
[  OK  ] DietPi-Set_swapfile | mkswap /dev/zram0
[  OK  ] DietPi-Set_swapfile | swapon /dev/zram0
[  OK  ] DietPi-Set_swapfile | eval echo 'zram' > /etc/modules-load.d/dietpi-zram-swap.conf
[  OK  ] DietPi-Set_swapfile | eval echo 'SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="476M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon /dev/zram0"' > /etc/udev/rules.d/98-dietpi-zram-swap.rules
[  OK  ] DietPi-Set_swapfile | eval echo 'swappiness=50' > /etc/sysctl.d/98-dietpi-zram-swap.conf
[  OK  ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_SIZE=476
[  OK  ] DietPi-Set_swapfile | Desired setting in /boot/dietpi.txt was already set: AUTO_SETUP_SWAPFILE_LOCATION=zram
[ INFO ] DietPi-Set_swapfile | Setting /tmp tmpfs size: 476 MiB
[  OK  ] DietPi-Set_swapfile | mount -o remount /tmp
$ sudo fallocate -l 2048M /var/swap $ sudo chmod 0600 /var/swap $ sudo mkswap /var/swap
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes) no label, UUID=1a4e054d-d8b8-4b3f-8ca3-5143af119936
$ sudo swapon -v /var/swap
swapon: /var/swap: found signature [pagesize=4096, signature=swap] swapon: /var/swap: pagesize=4096, swapsize=2147483648, devsize=2147483648 swapon /var/swap
$ sudo swapon -s
Filename Type Size Used Priority /dev/zram0 partition 485372 0 -2 /var/swap file 2097148 0 -3
$ free -m
               total        used        free      shared  buff/cache   available
Mem:             477          29         405           1          42         402
Swap:           2521           0        2521
$ echo '/var/swap none swap sw 0 0' | sudo tee -a /etc/fstab
/var/swap none swap sw 0 0
$ sudo /boot/dietpi/func/dietpi-set_swapfile 1 /var/swap
DietPi-Set_swapfile ───────────────────────────────────────────────────── Mode: Applying 1 /var/swap [ INFO ] DietPi-Set_swapfile | Disabling and deleting all existing swap files [ OK ] DietPi-Set_swapfile | swapoff -a removed '/etc/modules-load.d/dietpi-zram-swap.conf' removed '/etc/udev/rules.d/98-dietpi-zram-swap.rules' [ OK ] DietPi-Set_swapfile | Free space check: path=/var/ | available=104886 MiB | required=1619 MiB [ OK ] DietPi-Set_swapfile | Generating new swap space [ INFO ] DietPi-Set_swapfile | Size = 1619 MiB [ INFO ] DietPi-Set_swapfile | Path = /var/swap [ OK ] DietPi-Set_swapfile | fallocate -l 1619M /var/swap [ OK ] DietPi-Set_swapfile | mkswap /var/swap [ OK ] DietPi-Set_swapfile | swapon /var/swap [ OK ] DietPi-Set_swapfile | chmod 0600 /var/swap [ OK ] DietPi-Set_swapfile | eval echo '/var/swap none swap sw' >> /etc/fstab [ OK ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_SIZE=1619 [ OK ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_LOCATION=/var/swap [ INFO ] DietPi-Set_swapfile | Setting /tmp tmpfs size: 1024 MiB [ OK ] DietPi-Set_swapfile | mount -o remount /tmp
$ sudo /boot/dietpi/func/dietpi-set_swapfile 3072 /var/swap
DietPi-Set_swapfile ───────────────────────────────────────────────────── Mode: Applying 3072 /var/swap [ INFO ] DietPi-Set_swapfile | Disabling and deleting all existing swap files [ OK ] DietPi-Set_swapfile | swapoff -a removed '/var/swap' [ OK ] DietPi-Set_swapfile | Free space check: path=/var/ | available=104886 MiB | required=3072 MiB [ OK ] DietPi-Set_swapfile | Generating new swap space [ INFO ] DietPi-Set_swapfile | Size = 3072 MiB [ INFO ] DietPi-Set_swapfile | Path = /var/swap [ OK ] DietPi-Set_swapfile | fallocate -l 3072M /var/swap [ OK ] DietPi-Set_swapfile | mkswap /var/swap [ OK ] DietPi-Set_swapfile | swapon /var/swap [ OK ] DietPi-Set_swapfile | chmod 0600 /var/swap [ OK ] DietPi-Set_swapfile | eval echo '/var/swap none swap sw' >> /etc/fstab [ OK ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_SIZE=3072 [ OK ] DietPi-Set_swapfile | Desired setting in /boot/dietpi.txt was already set: AUTO_SETUP_SWAPFILE_LOCATION=/var/swap [ INFO ] DietPi-Set_swapfile | Setting /tmp tmpfs size: 1750 MiB [ OK ] DietPi-Set_swapfile | mount -o remount /tmp
$ sudo /boot/dietpi/func/dietpi-set_swapfile 1 zram
 DietPi-Set_swapfile
─────────────────────────────────────────────────────
 Mode: Applying 1 zram
[ INFO ] DietPi-Set_swapfile | Disabling and deleting all existing swap files
[  OK  ] DietPi-Set_swapfile | swapoff -a
removed '/var/swap'
[  OK  ] DietPi-Set_swapfile | Generating new swap space
[ INFO ] DietPi-Set_swapfile | Size = 214 MiB
[ INFO ] DietPi-Set_swapfile | Path = /dev/zram0
[  OK  ] DietPi-Set_swapfile | eval echo 1 > /sys/block/zram0/reset
[  OK  ] DietPi-Set_swapfile | eval echo '214M' > /sys/block/zram0/disksize
[  OK  ] DietPi-Set_swapfile | chmod 0600 /dev/zram0
[  OK  ] DietPi-Set_swapfile | mkswap /dev/zram0
[  OK  ] DietPi-Set_swapfile | swapon /dev/zram0
[  OK  ] DietPi-Set_swapfile | eval echo 'zram' > /etc/modules-load.d/dietpi-zram-swap.conf
[  OK  ] DietPi-Set_swapfile | eval echo 'SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="214M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon /dev/zram0"' > /etc/udev/rules.d/98-dietpi-zram-swap.rules
[  OK  ] DietPi-Set_swapfile | eval echo 'swappiness=50' > /etc/sysctl.d/98-dietpi-zram-swap.conf
[  OK  ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_SIZE=214
[  OK  ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_LOCATION=zram
[ INFO ] DietPi-Set_swapfile | Setting /tmp tmpfs size: 321 MiB
[  OK  ] DietPi-Set_swapfile | mount -o remount /tmp
$ sudo /boot/dietpi/func/dietpi-set_swapfile 428 zram
 DietPi-Set_swapfile
─────────────────────────────────────────────────────
 Mode: Applying 428 zram
[ INFO ] DietPi-Set_swapfile | Disabling and deleting all existing swap files
[  OK  ] DietPi-Set_swapfile | swapoff -a
[  OK  ] DietPi-Set_swapfile | Generating new swap space
[ INFO ] DietPi-Set_swapfile | Size = 428 MiB
[ INFO ] DietPi-Set_swapfile | Path = /dev/zram0
[  OK  ] DietPi-Set_swapfile | eval echo 1 > /sys/block/zram0/reset
[  OK  ] DietPi-Set_swapfile | eval echo '428M' > /sys/block/zram0/disksize
[  OK  ] DietPi-Set_swapfile | chmod 0600 /dev/zram0
[  OK  ] DietPi-Set_swapfile | mkswap /dev/zram0
[  OK  ] DietPi-Set_swapfile | swapon /dev/zram0
[  OK  ] DietPi-Set_swapfile | eval echo 'zram' > /etc/modules-load.d/dietpi-zram-swap.conf
[  OK  ] DietPi-Set_swapfile | eval echo 'SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="428M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon /dev/zram0"' > /etc/udev/rules.d/98-dietpi-zram-swap.rules
[  OK  ] DietPi-Set_swapfile | eval echo 'swappiness=50' > /etc/sysctl.d/98-dietpi-zram-swap.conf
[  OK  ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_SIZE=428
[  OK  ] DietPi-Set_swapfile | Desired setting in /boot/dietpi.txt was already set: AUTO_SETUP_SWAPFILE_LOCATION=zram
[ INFO ] DietPi-Set_swapfile | Setting /tmp tmpfs size: 428 MiB
[  OK  ] DietPi-Set_swapfile | mount -o remount /tmp
$ sudo /boot/dietpi/func/dietpi-set_swapfile 429 zram
DietPi-Set_swapfile ───────────────────────────────────────────────────── Mode: Applying 429 zram [ INFO ] DietPi-Set_swapfile | Disabling and deleting all existing swap files [ OK ] DietPi-Set_swapfile | swapoff -a removed '/etc/modules-load.d/dietpi-zram-swap.conf' removed '/etc/udev/rules.d/98-dietpi-zram-swap.rules' [FAILED] DietPi-Set_swapfile | Insufficient RAM size for desired zram-swap size [ INFO ] DietPi-Set_swapfile | Leaving swap space disabled [ OK ] DietPi-Set_swapfile | Setting in /boot/dietpi.txt adjusted: AUTO_SETUP_SWAPFILE_SIZE=0 [ OK ] DietPi-Set_swapfile | Desired setting in /boot/dietpi.txt was already set: AUTO_SETUP_SWAPFILE_LOCATION=zram [ INFO ] DietPi-Set_swapfile | Setting /tmp tmpfs size: 214 MiB [FAILED] DietPi-Set_swapfile | mount -o remount /tmp
# Free spacey, checkey weckey: zram < RAM size
elif [[ $SWAP_FS == 'zram' ]] && (( $(free -m | mawk '/^Mem:/{print $2;exit}') <= $SWAP_SIZE )); then
    Error_Reset 'Insufficient RAM size for desired zram-swap size'
$ free -m
               total        used        free      shared  buff/cache   available
Mem:             429         109          20         233         299          37
Swap:              0           0           0
$ free -m | mawk '/^Mem:/{print $2;exit}'
429
$ sudo fallocate -l 3072M /var/swap $ sudo chmod 0600 /var/swap $ sudo mkswap /var/swap
Setting up swapspace version 1, size = 3 GiB (3221221376 bytes) no label, UUID=9239781e-559a-47a4-b17c-f9f359004181
$ sudo swapon /var/swap $ sudo swapon -s
Filename Type Size Used Priority /dev/zram0 partition 438268 56152 -2 /var/swap file 3145724 0 -3
$ free -m
               total        used        free      shared  buff/cache   available
Mem:             429         141          43         192         244          46
Swap:           3499          55        3444
$ echo '/var/swap none swap sw' | sudo tee -a /etc/fstab
/var/swap none swap sw
$ sudo reboot $ sudo swapon -s
Filename Type Size Used Priority /var/swap file 3145724 256 -2 /dev/zram0 partition 438268 0 -3
$ sudo nano /etc/udev/rules.d/98-dietpi-zram-swap.rules
SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="428M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon  /dev/zram0"
**swapon** に priority **100** を指定する🤤 (大きい priority が優先される🤔ここでは 100 の zram0 から優先して使われる😻)\\
SUBSYSTEM=="block", KERNEL=="zram0", ACTION=="add", ATTR{disksize}="428M", RUN+="chmod 0600 /dev/zram0", RUN+="/sbin/mkswap /dev/zram0", RUN+="/sbin/swapon -p 100 /dev/zram0"
$ sudo reboot $ sudo swapon -s Filename Type Size Used Priority /var/swap file 3145724 0 -2 /dev/zram0 partition 438268 256 100
$ cat /boot/dietpi/func/dietpi-set_swapfile
#!/bin/bash
{
        #////////////////////////////////////
        # DietPi Function: swap file
        #
        #////////////////////////////////////
        # Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com
        #
        #////////////////////////////////////
        #
        # Info:
        # - Location: /boot/dietpi/func/dietpi-set_swapfile
        # - Allows set the swap file size and path or disable it, based in input arguments, dietpi.txt entry, existing swap file or default, in that priority order.
        #
        # Usage:
        # -      = this will apply the settings stored in dietpi.txt, refresh the current swap file or apply defaults as fallback
        # - $1          = swap file size [MiB], use "0" to disable or "1" for auto-choice assuring min 2048 MiB total memory, respectively 50% of RAM size when used with "zram"
        # - $2          = swap file path, or use "zram" to create a zram-swap on /dev/zram0 instead
        #////////////////////////////////////
        # Import DietPi-Globals --------------------------------------------------------------
        . /boot/dietpi/func/dietpi-globals
        readonly G_PROGRAM_NAME='DietPi-Set_swapfile'
        G_CHECK_ROOT_USER
        G_INIT
        # Import DietPi-Globals --------------------------------------------------------------
        EXIT_CODE=0
        # Check and apply valid input, else dietpi.txt entry, else current swap file, else revert to defaults
        # - Size
        if disable_error=1 G_CHECK_VALIDINT "$1"; then
                SWAP_SIZE=$1
        elif ! SWAP_SIZE=$(sed -n '/^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt) || ! disable_error=1 G_CHECK_VALIDINT "$SWAP_SIZE"; then
                SWAP_SIZE=$(mawk '$2=="file" {printf "%.0f",$3/1024;exit}' /proc/swaps) && disable_error=1 G_CHECK_VALIDINT "$SWAP_SIZE" || SWAP_SIZE=1
        fi
        # - Path: Store dietpi.txt entry (excluding zram-swap) and active swap files for disabling and removal before creating a new swap space
        SWAP_PATH=$(sed -n '/^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
        read -ra SWAP_FILES_ACTIVE < <(mawk '$2=="file" {print $1}' /proc/swaps)
        [[ $SWAP_PATH == '/'* && $SWAP_PATH != '/dev/zram0' ]] && SWAP_FILES_ACTIVE+=("$SWAP_PATH")
        if [[ $2 == '/'* || $2 == 'zram' || $2 == 'zram0' ]]; then
                SWAP_PATH=$2
        elif [[ $SWAP_PATH != '/'* && $SWAP_PATH != 'zram' && $SWAP_PATH != 'zram0' ]]; then
                SWAP_PATH=$(mawk '$2=="file" {print $1;exit}' /proc/swaps) && [[ $SWAP_PATH == '/'* || $SWAP_PATH == 'zram' || $SWAP_PATH == 'zram0' ]] || SWAP_PATH='/var/swap'
        fi
        Update_DietPi_Conf(){
                G_CONFIG_INJECT 'AUTO_SETUP_SWAPFILE_SIZE=' "AUTO_SETUP_SWAPFILE_SIZE=$SWAP_SIZE" /boot/dietpi.txt
                [[ $SWAP_FS == 'zram' ]] && SWAP_PATH='zram' # Revert zram path to input value
                G_CONFIG_INJECT 'AUTO_SETUP_SWAPFILE_LOCATION=' "AUTO_SETUP_SWAPFILE_LOCATION=$SWAP_PATH" /boot/dietpi.txt
        }
        Update_Tmp(){
                # Skip if /tmp is not dedicated mount
                grep -q '[[:blank:]]/tmp[[:blank:]]' /etc/fstab || return 0
                # Set /tmp to 50% of RAM+SWAP: https://github.com/MichaIng/DietPi/issues/1027#issuecomment-369373082
                local tmp_size=$(( $(free -tm | mawk '/^Total:/{print $2;exit}') / 2 ))
                G_DIETPI-NOTIFY 2 "Setting /tmp tmpfs size: $tmp_size MiB"
                # Apply to existing fstab entry
                sed -i "/[[:blank:]]\/tmp[[:blank:]]/ctmpfs \/tmp tmpfs size=${tmp_size}M,noatime,lazytime,nodev,nosuid,mode=1777" /etc/fstab
                systemctl daemon-reload
                # Apply now to existing mount via "remount" to preserve current content and avoid doubled mount
                [[ $(findmnt -Ufnro FSTYPE -M /tmp) == 'tmpfs' ]] && G_EXEC mount -o remount /tmp
        }
        Swap_Disable(){
                G_DIETPI-NOTIFY 2 'Disabling and deleting all existing swap files'
                (( $G_HW_MODEL == 75 )) || grep -zaq '^container=' /proc/1/environ || G_EXEC swapoff -a
                rm -fv "${SWAP_FILES_ACTIVE[@]}"
                sed -i '/[[:blank:]]swap[[:blank:]]/d' /etc/fstab
                # zram-swap
                [[ -f '/etc/modules-load.d/dietpi-zram-swap.conf' ]] && rm -v /etc/modules-load.d/dietpi-zram-swap.conf
                [[ -f '/etc/udev/rules.d/98-dietpi-zram-swap.rules' ]] && rm -v /etc/udev/rules.d/98-dietpi-zram-swap.rules
        }
        # Create new swappey whappey
        Swap_Enable(){
                G_DIETPI-NOTIFY 0 'Generating new swap space'
                G_DIETPI-NOTIFY 2 "Size = $SWAP_SIZE MiB"
                G_DIETPI-NOTIFY 2 "Path = $SWAP_PATH"
                # zram
                if [[ $SWAP_FS == 'zram' ]]; then
                        [[ -b $SWAP_PATH ]] || G_EXEC modprobe zram
                        G_EXEC eval 'echo 1 > /sys/block/zram0/reset'
                        G_EXEC eval "echo '${SWAP_SIZE}M' > /sys/block/zram0/disksize"
                        G_EXEC chmod 0600 "$SWAP_PATH"
                        G_EXEC mkswap "$SWAP_PATH"
                        G_EXEC swapon "$SWAP_PATH"
                        # Make persistent, proceed with failure in case of R/O rootfs
                        G_EXEC_NOHALT=1 G_EXEC eval "echo 'zram' > /etc/modules-load.d/dietpi-zram-swap.conf" || return 1
                        G_EXEC_NOHALT=1 G_EXEC eval "echo 'SUBSYSTEM==\"block\", KERNEL==\"zram0\", ACTION==\"add\", ATTR{disksize}=\"${SWAP_SIZE}M\", RUN+=\"chmod 0600 /dev/zram0\", RUN+=\"/sbin/mkswap /dev/zram0\", RUN+=\"/sbin/swapon /dev/zram0\"' > /etc/udev/rules.d/98-dietpi-zram-swap.rules" || return 1
                        G_EXEC_NOHALT=1 G_EXEC eval "echo 'swappiness=50' > /etc/sysctl.d/98-dietpi-zram-swap.conf" || return 1
                        return 0
                # Swap file pre-allocation: Try faster and less write-intense fallocate first and dd as fallback
                elif ! G_EXEC_NOHALT=1 G_EXEC fallocate -l "${SWAP_SIZE}M" "$SWAP_PATH" || ! G_EXEC_NOHALT=1 G_EXEC mkswap "$SWAP_PATH" || ! G_EXEC_NOHALT=1 G_EXEC swapon "$SWAP_PATH"; then
                        G_DIETPI-NOTIFY 2 'Swap file generation via "fallocate" failed, falling back to "dd"...'
                        G_EXEC swapoff -a
                        G_EXEC dd if=/dev/zero of="$SWAP_PATH" bs=1M "count=$SWAP_SIZE"
                        G_EXEC mkswap "$SWAP_PATH"
                        G_EXEC swapon "$SWAP_PATH"
                fi
                # Harden permissions, allow to fail on filesystems without UNIX permission support
                G_EXEC_NOHALT=1 G_EXEC chmod 0600 "$SWAP_PATH"
                # Make persistent, proceed with failure in case of R/O rootfs
                G_EXEC_NOHALT=1 G_EXEC eval "echo '$SWAP_PATH none swap sw' >> /etc/fstab" || return 1
        }
        Error_Reset(){
                G_DIETPI-NOTIFY 1 "$*"
                G_DIETPI-NOTIFY 2 'Leaving swap space disabled'
                SWAP_SIZE=0 EXIT_CODE=1
        }
        #/////////////////////////////////////////////////////////////////////////////////////
        # Main Loop
        #/////////////////////////////////////////////////////////////////////////////////////
        G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" "Applying $SWAP_SIZE $SWAP_PATH"
        # Always reset existing swap files
        Swap_Disable
        # zram-swap
        if [[ $SWAP_PATH == 'zram' || $SWAP_PATH == 'zram0' || $SWAP_PATH == '/dev/zram0' ]]; then
                (( $SWAP_SIZE == 1 )) && SWAP_SIZE=$(( $(free -m | mawk '/^Mem:/{print $2;exit}') / 2 )) # Auto size
                SWAP_PATH='/dev/zram0' SWAP_FS='zram'
        # swap file
        else
                # Auto size: Skip if size would be less than 100 MiB, since else on all 2 GiB SBCs there is a non-reasonable ~50 MiB swap file created
                if (( $SWAP_SIZE == 1 )); then
                        SWAP_SIZE=$(( 2048 - $(free -m | mawk '/^Mem:/{print $2;exit}') ))
                        if (( $SWAP_SIZE > 1 && $SWAP_SIZE < 100 )); then
                                G_DIETPI-NOTIFY 0 "Skipping the auto-creation of a tiny $SWAP_SIZE MiB swap file"
                                G_DIETPI-NOTIFY 0 'Set < 100 MiB values manually to create such small swap files'
                                SWAP_SIZE=0
                        fi
                fi
                SWAP_DIR="${SWAP_PATH%/*}/" SWAP_FS=$(findmnt -Ufnro FSTYPE -T "$SWAP_DIR")
        fi
        # Disable
        if (( $SWAP_SIZE < 1 )); then
                SWAP_SIZE=0
        # Unsupported in container
        elif (( $G_HW_MODEL == 75 )) || grep -zaq '^container=' /proc/1/environ; then
                Error_Reset 'Swap space cannot be controlled form within a container.'
        # Unsupported on Btrfs
        elif [[ $SWAP_FS == 'btrfs' ]]; then
                Error_Reset 'Swap files are not supported on Btrfs file system.'
        # Free spacey, checkey weckey: zram < RAM size
        elif [[ $SWAP_FS == 'zram' ]] && (( $(free -m | mawk '/^Mem:/{print $2;exit}') <= $SWAP_SIZE )); then
                Error_Reset 'Insufficient RAM size for desired zram-swap size'
        elif [[ $SWAP_FS != 'zram' ]] && ! G_CHECK_FREESPACE "$SWAP_DIR" "$SWAP_SIZE"; then
                Error_Reset 'Insufficient free space for desired swap files size'
        else
                Swap_Enable || EXIT_CODE=1
        fi
        Update_DietPi_Conf
        Update_Tmp
        #-----------------------------------------------------------------------------------
        exit "$EXIT_CODE"
        #-----------------------------------------------------------------------------------
}
 
$ sudo apt install git
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
  git
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,724 kB of archives.
After this operation, 31.1 MB of additional disk space will be used.
Get:1 http://ftp.udx.icscoe.jp/Linux/raspbian/raspbian bullseye/main armhf git armhf 1:2.30.2-1 [4,724 kB]
Fetched 4,724 kB in 5s (999 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package git.
(Reading database ... 69783 files and directories currently installed.)
Preparing to unpack .../git_1%3a2.30.2-1_armhf.deb ...
Unpacking git (1:2.30.2-1) ...
Setting up git (1:2.30.2-1) ...
$ git clone --depth 1 https://github.com/StuartIanNaylor/zram-swap-config
Cloning into 'zram-swap-config'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 9 (delta 0), reused 2 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), 17.69 KiB | 646.00 KiB/s, done.
$ cd zram-swap-config
$ sudo ./install.sh
Created symlink /etc/systemd/system/sysinit.target.wants/zram-swap-config.service → /etc/systemd/system/zram-swap-config.service.
#####     Reboot to activate zram-swap-config     #####
##### edit /etc/zram-swap-config.conf for options #####
$ sudo modprobe zram
$ cat /sys/block/zram0/comp_algorithm
lzo [lzo-rle] lz4 zstd
$ cat /etc/zram-swap-config.conf
# Configuration file for zram-swap-config (https://github.com/StuartIanNaylor/zram-swap-config) under GNU General Public License v3.0 license.
# This configuration file is read by the zram-swap-config service
# MEM_FACTOR = Percentage of available ram to allocate to all zram swap devices which is divided equally by swap_devices number
MEM_FACTOR=40
# DRIVE_FACTOR = Virtual uncompressed zram drive size = estimate approx alg compression ratio an results and is the % of the Memfactor
DRIVE_FACTOR=200
# COMP_ALG lz4 is faster than lzo but some distro's show compile and operation difference and in use lzo depending on binary may be faster
COMP_ALG=lzo-rle
# SWAP_DEVICES = number of indivial drives sharing memeory provided by MEM_FACTOR each device support multiple streams 1 large drive is generally better
SWAP_DEVICES=1
# SWAP_PRI = swap_priority for each drive 75 is a hig order preference and should be well above other swap drives
SWAP_PRI=75
# PAGE_CLUSTER default page cluster is 3 which caches fetches in batches of 8 and helps with HDD paging, with zram mem 0 forces single page fetches
# This can help reduce latency and increase performance
PAGE_CLUSTER=0
# SWAPPINESS default swappiness is 60 but with increased performance of zram swap 80 garners overall performance gain without excessive load
# Because zram uses compression load is created and even if minimal at intense load periods such as boot any extra load is unwanted
# Unfortunately there is no dynamic load balancing of swappiness as with zram in general operation SWAPINESS=100 will garner performance benefit
# If the overall load is reasonable at high load it will cause load to accumulate.
SWAPPINESS=90
# If you check my repo there will also be a simple dynamic load branch based SWAPPINESS governor that will get of the hurdle of a static compromise on swappiness
MEM_FACTOR=25
DRIVE_FACTOR=300
COMP_ALG=lz4
SWAP_DEVICES=1
SWAP_PRI=75
PAGE_CLUSTER=0
SWAPPINESS=80
MEM_FACTOR=10
DRIVE_FACTOR=300
COMP_ALG=lz4
SWAP_DEVICES=1
SWAP_PRI=75
PAGE_CLUSTER=0
SWAPPINESS=80
MEM_FACTOR=15
DRIVE_FACTOR=300
COMP_ALG=lz4
SWAP_DEVICES=1
SWAP_PRI=75
PAGE_CLUSTER=0
SWAPPINESS=80
$ sudo systemctl start zram-swap-config
$ sudo systemctl status zram-swap-config
● zram-swap-config.service - zram-swap-config
     Loaded: loaded (/etc/systemd/system/zram-swap-config.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2022-04-18 06:04:20 JST; 14s ago
    Process: 14634 ExecStart=/usr/local/bin/zram-swap-config start (code=exited, status=0/SUCCESS)
   Main PID: 14634 (code=exited, status=0/SUCCESS)
        CPU: 160ms
Apr 18 06:04:19 dietpi-001 zram-swap-config[14636]: modprobe: ERROR: could not insert 'zram': Module already in kernel
Apr 18 06:04:19 dietpi-001 zram-swap-config[14634]: zram1 1
Apr 18 06:04:20 dietpi-001 zram-swap-config[14645]: Setting up swapspace version 1, size = 129 MiB (135225344 bytes)
Apr 18 06:04:20 dietpi-001 zram-swap-config[14645]: no label, UUID=5c52fd2d-6ae3-4e3f-b3fd-484bd1bb8042
Apr 18 06:04:20 dietpi-001 zram-swap-config[14646]: swapon: /dev/zram1: found signature [pagesize=4096, signature=swap]
Apr 18 06:04:20 dietpi-001 zram-swap-config[14646]: swapon: /dev/zram1: pagesize=4096, swapsize=135229440, devsize=1352>
Apr 18 06:04:20 dietpi-001 zram-swap-config[14646]: swapon /dev/zram1
Apr 18 06:04:20 dietpi-001 zram-swap-config[14647]: vm.page-cluster = 0
Apr 18 06:04:20 dietpi-001 zram-swap-config[14648]: vm.swappiness = 80
Apr 18 06:04:20 dietpi-001 systemd[1]: Finished zram-swap-config.
$ sudo zramctl
NAME       ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram1 lz4           129M   4K   63B    4K       1 [SWAP]
$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 116.4G  0 disk
├─mmcblk0p1 179:1    0   128M  0 part /boot
└─mmcblk0p2 179:2    0 116.2G  0 part /
zram1       254:1    0   129M  0 disk [SWAP]
$ sudo swapon --show
NAME       TYPE      SIZE USED PRIO
/var/swap  file      1.6G 1.3M   -2
/dev/zram1 partition 129M   0B   75