Help / correct init-zram-swapping format

i need some help

when i set up my zram using

sudo nano /usr/bin/init-zram-swapping

i did it this way

the 2024 link fosspost

has it this way

an the 2023 link maketecheasier post

has it this way

my current config is the terminal view next to each posts listed config

the swapon -p 1000 /dev/zram0 line in my terminal view i did that as thats how it was in pop-os , im not sure what effect it has in ubuntu

but i want to know how it should be for ubuntu 24.04lts

should the init-zram-swapping

be this way with the zstd algorithm

#!/bin/sh

modprobe zram

Calculate memory to use for zram (1/2 of ram)

totalmem=LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/ *.*//'
mem=$((totalmem * 768))
echo zstd > /sys/block/zram0/comp_algorithm

initialize the devices

echo $mem > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon -p 1000 /dev/zram0

or this way

#!/bin/sh

modprobe zram

Calculate memory to use for zram (1/2 of ram)

totalmem=LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/ *.*//'
mem=$((totalmem * 768))
echo zstd > /sys/block/zram0/comp_algorithm

initialize the devices

echo $mem > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon -p 75 /dev/zram0

or this way

#!/bin/sh

modprobe zram

Calculate memory to use for zram (1/2 of ram)

totalmem=LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/ *.*//'
mem=$((totalmem * 768))
echo zstd > /sys/block/zram0/comp_algorithm

initialize the devices

echo $mem > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon -p 5 /dev/zram0

an should the

echo zstd > /sys/block/zram0/comp_algorithm line be either above or below the

initialize the devices

echo $mem > /sys/block/zram0/disksize line

an is it possible to add a force compression value like this compress-force=zstd:5 or somthing similar to that of the one used on my ssd drives btrfs filesystem

Ubuntu has a package zram-tools, configuration, say that 50% or physical RAM, in /etc/default/zramswap with a guide how to set it up, there’s a service zramswap.service that’s automatically enabled when you install zram-tools. I run it on all my Debian and Ubuntu machines.

K3n.

Also GitHub - systemd/zram-generator: Systemd unit generator for zram devices is in the ubuntu 24.04 repos.