I'm building my zRAM-Swap in /etc/rc.local (Xfce-Runit):
#!/bin/sh
modprobe zram && echo lz4 > /sys/block/zram0/comp_algorithm && echo $(($(grep 'MemTotal:' /proc/meminfo|awk '{print $2}')*1/1))K > /sys/block/zram0/disksize && mkswap -qU clear /dev/zram0 && swapon -p100 /dev/zram0
exit 0
For zRAM-Disk I wrote two Scripts and put them in the path:
"mkzram":
#!/bin/bash
if [ $# == 0 ];then echo "mkzram [Size in G] [zstd] (standard: lz4)";exit;fi
al=lz4
if [ $2 == "zstd" ] 2>/dev/null;then al=zstd;fi
if [ ! -e /dev/zram* ] 2>/dev/null
then sudo modprobe zram;id=0
else id=$(sudo cat /sys/class/zram-control/hot_add)
fi
echo $al|sudo tee /sys/block/zram$id/comp_algorithm >/dev/null
echo $1"G"|sudo tee /sys/block/zram$id/disksize >/dev/null
sudo mkfs.xfs -Kqmcrc=0 /dev/zram$id >/dev/null && mkdir /tmp/zram$id
sudo mount -o discard /dev/zram$id /tmp/zram$id/ && sudo chmod 777 /tmp/zram$id/
zramctl -o name,algorithm,disksize,data,compr,mountpoint
"rmzram":
#!/bin/bash
if [ $# == 0 ];then echo -e "rmzram [ID]:\n";zramctl -o name,algorithm,disksize,data,compr,mountpoint;exit;fi
sudo umount -l /tmp/zram$1/ && rm -rf /tmp/zram$1
echo $1|sudo tee /sys/class/zram-control/hot_remove > /dev/null
if [ ! -e /dev/zram* ] 2>/dev/null;then sudo modprobe -r zram;fi
zramctl -o name,algorithm,disksize,data,compr,mountpoint
Example:
$ mkzram 12
[sudo] Passwort für user:
NAME ALGORITHM DISKSIZE DATA COMPR MOUNTPOINT
/dev/zram0 lz4 31,3G 4K 44B [SWAP]
/dev/zram1 lz4 12G 2,3M 53,4K /tmp/zram1
$ mkzram 8 zstd
NAME ALGORITHM DISKSIZE DATA COMPR MOUNTPOINT
/dev/zram0 lz4 31,3G 4K 44B [SWAP]
/dev/zram1 lz4 12G 2,3M 53,4K /tmp/zram1
/dev/zram2 zstd 8G 2,3M 45,2K /tmp/zram2
$ rmzram
rmzram [ID]:
NAME ALGORITHM DISKSIZE DATA COMPR MOUNTPOINT
/dev/zram0 lz4 31,3G 4K 44B [SWAP]
/dev/zram1 lz4 12G 2,3M 53,4K /tmp/zram1
/dev/zram2 zstd 8G 2,3M 45,2K /tmp/zram2
$ rmzram 1
NAME ALGORITHM DISKSIZE DATA COMPR MOUNTPOINT
/dev/zram0 lz4 31,3G 4K 44B [SWAP]
/dev/zram2 zstd 8G 2,3M 45,2K /tmp/zram2
$ rmzram 2
NAME ALGORITHM DISKSIZE DATA COMPR MOUNTPOINT
/dev/zram0 lz4 31,3G 4K 44B [SWAP]