Ok, basic details:
Some time ago, there was a linux optimization patch set called "CompCache", which used zlib compression to compress the data in a swap file, to make it smaller. The goal, was to reduce the size of the data that needed to be loaded from disk, so that fewer disk iops would be done when fetching from swap.
Sometime later, the idea of using this on an "Allocated as needed" ramdisk appeared, and this slowly morphed into zram.
zram is a kernel module, that produces one or more block devices of user definable sizes. It is able to use any compressor library that the system knows about, but it usually uses LZO compression by default, because it is fast at both compression and decompression.
It only allocates memory as it needs it. So, if you tell it to make a block device that is 1.5x the size of system RAM, it initially only starts using a few kilobytes of that RAM, until it gets things written into it.
Since it presents as a block device, you can do anything with it that you can with a block device. Put a filesystem on it, put a swap space on it, whatever. It acts just like a disk drive.
The nitty gritty details:
Spoiler
zram is controlled by a /sys/block/zramX (where X is the number of the device, starting at 0) config block. It has numerous tunable options, including disk size, compressor to use, a facility to reset the device, etc. These options can only be tuned by the root user.
Basically, (as root) you just punch some values into its config "files" in that config block, and the driver responds. eg,
echo 2147483648 > /sys/block/zram0/disksize
will set the size of the reported block device to 2gb. (disksize is in the form of bytes. That number is EXACTLY 2gb, in bytes.)
echo zstd > /sys/block/zram0/comp-algorithm
will set the compression algorithm to ZSTD instead of the default, LZO. (It was created by Oracle, I think? It is a very aggressive compressor. Usually gets better compression than LZ4, and LZO, but is slower, and consumes more CPU time. Not really recommended for phones, but for things on wall power with a real cpu, it's usually fine.)
on android, there is a custom init script process that sets everything up, including configuring swap devices and loading the zram module. You need to be root, and you need to remount the root filesystem as writable (temporarily) to make persistent changes to these config files. However, you CAN do this, if you are rooted. So, persistently tuning the amount of zram supplied compressed ram swap on an aging phone to squeeze just a little more useful life out, is perfectly doable.