This is what I did and worked for me. here is the output of lsblk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 7.3T 0 disk
├─sda1 8:1 0 16M 0 part
└─sda2 8:2 0 7.3T 0 part /run/media/ef/Storage
zram0 252:0 0 8G 0 disk [SWAP]
nvme0n1 259:0 0 1.8T 0 disk
├─nvme0n1p1 259:1 0 16M 0 part
├─nvme0n1p2 259:2 0 834.7G 0 part
├─nvme0n1p3 259:3 0 614M 0 part
├─nvme0n1p4 259:4 0 100M 0 part /boot/efi
├─nvme0n1p5 259:5 0 1G 0 part /boot
└─nvme0n1p6 259:6 0 1T 0 part /home
and here is output of $ swapon -s
Filename Type Size Used Priority
/dev/zram0 partition 8388604 1935420 100
Here are the steps I followed:
$ sudo touch /swapfile
$ sudo chattr +C /swapfile
$ sudo lsattr /swapfile
$ sudo fallocate -l 200G /swapfile
$ sudo lsattr /swapfile
$ sudo chmod 600 /swapfile
$ sudo lsattr /swapfile # make sure you see the letter C in the results: ---------------C------ /swapfile
$ sudo mkswap /swapfile # output example: Setting up swapspace version 1, size = 200 GiB (214748360704 bytes)
$ sudo mkswap /swapfile # output example: Setting up swapspace version 1, size = 200 GiB (214748360704 bytes)
no label, UUID=98a6c4a0-ec8d-4afb-90af-6162e83d30b3
$ sudo swapon /swapfile
$ vim /etc/fstab
here I added one line at the end of /etc/fstab:
/swapfile swap swap defaults 0 0
That's it. Now you can see it shows up:
$ sudo swapon -s
NAME TYPE SIZE USED PRIO
/dev/zram0 partition 8G 1.8G 100
/swapfile file 200G 0B -2
I tested it and it works for reading huge files.
resources that helped: