Last active
August 2, 2023 16:11
-
-
Save Manouchehri/cbc57183ee9f6732a151f7ebe7349067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo dd if=/dev/zero of=/swapfile0 bs=1M count=4096 status=progress # not right for btrfs? Should disable compression too? | |
sudo chmod 600 /swapfile0 | |
# old kernels need more swapfiles | |
sudo lvcreate -l +100%FREE ubuntu-vg -n zram0 | |
# edit the other two files in this gist first | |
sudo /usr/bin/init-zram-swapping | |
sudo sysctl -p | |
# You only need one zram device for kernels newer than 3.15 | |
sudo lvcreate -L 500M ubuntu-vg -n zram1 | |
sudo lvcreate -L 500M ubuntu-vg -n zram2 | |
sudo lvcreate -L 500M ubuntu-vg -n zram3 | |
sudo lvcreate -L 500M ubuntu-vg -n zram4 | |
sudo lvcreate -L 500M ubuntu-vg -n zram5 | |
sudo lvcreate -L 500M ubuntu-vg -n zram6 | |
sudo lvcreate -L 500M ubuntu-vg -n zram7 | |
sudo lvcreate -L 500M ubuntu-vg -n zram8 | |
sudo lvcreate -L 500M ubuntu-vg -n zram9 | |
sudo lvcreate -L 500M ubuntu-vg -n zram10 | |
sudo lvcreate -L 500M ubuntu-vg -n zram11 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# load dependency modules | |
# NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/1/') | |
# We don't need multiple devices anymore | |
NRDEVICES=1 | |
if modinfo zram | grep -q ' zram_num_devices:' 2>/dev/null; then | |
MODPROBE_ARGS="zram_num_devices=${NRDEVICES}" | |
elif modinfo zram | grep -q ' num_devices:' 2>/dev/null; then | |
MODPROBE_ARGS="num_devices=${NRDEVICES}" | |
else | |
exit 1 | |
fi | |
modprobe zram $MODPROBE_ARGS | |
# 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 / 2 / ${NRDEVICES}) * 1024)) | |
# To override the auto size | |
mem="4G" | |
# initialize the devices | |
for i in $(seq ${NRDEVICES}); do | |
DEVNUMBER=$((i - 1)) | |
swapdev="$(losetup --find "$(readlink -f /swapfile${DEVNUMBER})" --show)" | |
echo $swapdev > /sys/block/zram${DEVNUMBER}/backing_dev | |
echo lz4 > /sys/block/zram${DEVNUMBER}/comp_algorithm | |
echo $mem > /sys/block/zram${DEVNUMBER}/disksize | |
echo all > /sys/block/zram${DEVNUMBER}/idle | |
echo idle > /sys/block/zram${DEVNUMBER}/writeback | |
mkswap /dev/zram${DEVNUMBER} | |
swapon -p 5 /dev/zram${DEVNUMBER} | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vm.swappiness = 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Proof of how amazing this is: