So after spending a little more time researching, here’s what I came up with for swap partition vs. swap file.
Swap performance relies on the swapped data being contiguous on the disk. Swap partitions are inherently contiguous because they are entirely dedicated to swap whereas a swap file may not be contiguous as it is just a file on a general-use partition that shares space with all the other files contained there. This is particularly true for filesystems that have been in use for a while where at least some fragmentation is likely. Disk space is also a factor. If there isn’t a contiguous block of space large enough to accommodate the size of the swap file then it could be split into pieces which will absolutely decrease performance of the swap process. This should not be an issue when creating a swap file on a fresh partition with adequate free space available. In cases where the swap file is contiguous there should be no discernible difference in performance between a swap partition and a swap file.
The other reason I came across was the idea of planning ahead and separating concerns. If you know you need or want to use swap and know how much you want to allocate then dedicating a partition for that purpose makes sense. This is particularly true if you are doing so with the assumption that you will be relying on swap on a regular basis and not as a safety net as I assume most people do. It can be particularly important for mission critical systems like servers. Lastly, the idea that a swap partition can be located anywhere such as a different, faster disk could play a role, although there’s no reason a swap file also couldn’t be located on any mounted disk.
Hibernation was also something I came across. I mentioned it in the video and I genuinely do believe that most people don’t use hibernation at this point but I may be incorrect. You can use hibernation with both swap partitions and files but using a swap file requires additional steps to configure and will vary depending on your approach and distribution.
My final thoughts on this come down to how you approach swap. As I’ve mentioned, I really only see it as a safety net for the extremely rare occasions where I do something dumb and go OOM or the unlikely event some process goes off the rails and eats all my RAM. I will never rely on swap as a primary means of managing memory in a purposeful way where I know I will use all the physical memory and overflow into swap space. It’s a pretty terrible experience in case you’ve never dealt with it. You probably have as a Windows user back in the day where it was very common to have a low spec system without sufficient RAM to run the OS and many applications at once. This combined with the slow disks available at the time was almost unbearable. Remember memory managers? They would push things out of physical memory to free up space, usually didn’t work very well and generally caused more problems than they attempted to solve.
I guess the bottom line is, to me at least, if you are running out of memory on a regular basis…get more. Swap is a band-aid and will not solve that problem. It will stop your system from crashing and hence is still useful so definitely make sure you have thought about it but don’t see it as a way to solve the fundamental issue of too little memory.