Requirements: Termux, Root (preferably Magisk).
Open termux and give it root permissions
Type su to escalate the permissions
Now enter the command dd if=/dev/zero of=swapfile bs=1024 count=6144k replacing 6144k with as much swap as you need, in this case 6GB
Once its done, enter mkswap swapfile to create the sawp file and swapon swapfile to enable the swap file
Thank you!
To enable this across reboots I had to create a script inside Magisk boot script service.d path. But with a delay of 2 minutes, otherwise the script would run before zRAM allocation and the performance was terrible. It needs to run after it, because zRAM is faster storage and needs to be used before the swap file in the SSD.
This has effectively solved all lagging issues on my phone 😁