>>103113315
Zram works well if you have plenty of RAM:
/etc/conf.d/zram-init:
# swap - 500M (or a fourth of available memory if uncommenting)
type0=swap
flag0= # The default "16383" is fine for us
#size0=512
size0=`LC_ALL=C free -m | awk '/^Mem:/{print int($2/4)}'`
mlim0= # no hard memory limit
back0= # no backup device
icmp0= # no incompressible page writing to backup device
idle0= # no idle page writing to backup device
wlim0= # no writeback_limit for idle page writing for backup device
notr0= # keep the default on linux-3.15 or newer
maxs0=1 # maximum number of parallel processes for this device
algo0=zstd # zstd (since linux-4.18), lz4 (since linux-3.15), or lzo.
# Size: zstd (best) > lzo > lz4. Speed: lz4 (best) > zstd > lzo
labl0=zram_swap # the label name
uuid0= # Do not force UUID
args0= # we could e.g. have set args0="-L 'zram_swap'" instead of using labl0
type1=/var/tmp/portage
flag1=btrfs
size1=46080
algo1=zstd
labl1=var_tmp_portage_dir
That gives me 25% of my RAM for Swap and a BTRFS volume 46 GB for Portage
$ sudo zramctl --output-all;sudo swapon --show;free -h
NAME DISKSIZE DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MEM-LIMIT MEM-USED MIGRATED MOUNTPOINT
/dev/zram0 15.7G 14.1G 6G zstd 32 411865 6G 0B 8.1G 6.2M [SWAP]
/dev/zram1 45G 4.3G 1.9G zstd 32 13402 2G 0B 26.7G 19M
NAME TYPE SIZE USED PRIO
/dev/zram0 partition 15.7G 14.1G 16383
/dev/root/swap/swap2.img file 27G 4G -2
total used free shared buff/cache available
Mem: 62Gi 28Gi 11Gi 93Mi 23Gi 34Gi
Swap: 42Gi 18Gi 24Gi