Having such a huge swap nowadays is often a bad idea. By the time the OS swapped out just a few GBGBs of memory to swap, your system had already crawled to death (like what you saw)
It's better to use zram with a small backup swap partition. Many OSes like ChromeOS, Android and various Linux distros (Lubuntu, Fedora) have enabled zram by default for years, especially for systems with less RAM. It'sIn fact Windows 10 and macOS also use similar pagefile compression techniques by default
That's because it's much faster than swap on HDD and you can clearly feel the system responsiveness in this caseonce it's enabled. Less so on an SSD, but according to the benchmark results here it still seems faster even with the default lzo algorithm. You can change to lz4 for even better performance with a little bit less compression ratio. It's decoding speed is nearly 5 times faster than lzo based on official benchmark
In fact Windows 10 and macOS also use similar. Or switch to the modern pagefile compression techniques by defaultzstd to trade a bit of speed for better compression
There's also zswap although I've never used it. Probably worth a try and compare which one is better for your usecases
After that another suggestion is to reduce the priority of those IO-bound processes and possibly leave a terminal running on higher priority so that you can run commands on it right away even when the system is on a high load
Further reading
- Arch Linux - Improving performance - Zram or zswap
- Enable ZSwap to increase performance
- Enable zRAM for improved memory handling and less swapping
- Running out of RAM in Ubuntu? Enable ZRAM
- Difference between ZRAM and ZSWAP
- zram vs zswap vs zcache Ultimate guide: when to use which one
- Linux, SSD and swap
- https://wiki.debian.org/ZRam
- https://www.kernel.org/doc/Documentation/blockdev/zram.txt
- https://wiki.gentoo.org/wiki/Zram