How to change zram size?

According to http://manpages.ubuntu.com/manpages/xenial/man8/zramctl.8.html, you can remove and recreate a zram swap like this:

# swapoff /dev/zram0
# zramctl --reset /dev/zram0
# zramctl --find --size 1024M
/dev/zram0
# mkswap /dev/zram0
# swapon /dev/zram0

To permanently change the size, you have to adapt the init script, where the swap files are created. Be aware, that this file may be overridden by future system updates.

To increase the size of the swapfile in Ubunutu 16.04 from 50% to 200% of your total memory size, change this line in /usr/bin/init-zram-swapping

mem=$(((totalmem / 2 / ${NRDEVICES}) * 1024))

to

mem=$(((totalmem * 2 / ${NRDEVICES}) * 1024))

I'm a Fedora 33 user, but I came across this answer when looking for how to configure my zram. This is my /usr/lib/systemd/zram-generator.conf:

# This config file enables a /dev/zram0 device with the default settings:
# — size — half of available RAM or 4GB, whichever is less
# — compression — most likely lzo-rle
#
# To disable, uninstall zram-generator-defaults or create empty
# /etc/systemd/zram-generator.conf file.
[zram0]
zram-fraction = 2
max-zram-size=none

This is persistent across reboots and seems to be the recommended way of controlling zram.

See https://fedoraproject.org/wiki/Changes/SwapOnZRAM, espeically man 5 zram-generator.conf