I am a new linux user switched from windows 10. I have installed ubuntu 20.04.1 lts. I have swap file available in my system. Is it better to use swap partition instead of swap file? Thanks in advance!
1 Answers
In a nutshell: don't worry too much about this, and start by choosing a swap file (as they are easy to move/modify, whereas you have only a limited amount of partitions)
However, if you really need details on some of the multiple impact that choise has (some good, some bad):
If you are using a rotating hard drive (and not an ssd), one big difference is in the way the swap is spread on the disk's surface, and the time it takes to access it :
And a rotating disc takes a very "long" time changing the location it is reading from and waiting for the right portion to arrive underneath the drive's reading head.
On the other hand an ssd is almost not impacted at all by the way the data it needs to read is spread : it goes to the relevant section immediately (... but still benefits if the data is nicely packed together in sizeable continuous chunks)
So the impact is mostly seen for rotating hard drives (and very less impactful for SSDs):
A swap file may be "anywhere" within the disk partition it belongs to. This means it could even be scattered across several bits.
In addition to that, the swap file itself may be fragmented and have parts all over the partition.
The rotating drive will take each time a very "long" time changing the location it is reading from, and waiting for the right portion to arrive underneath its reading head.
On the other hand : if you choose a dedicated partition it will always be in a "known" part of your drive, forcing the head to head to a specific portion of the disc when reading from/writing to swap data, and there should be a limited range of movements as that partition is "packed together" on a small portion of the overall disk. (But please note that the disk may still have to wait until the right section is underneath it's reading head).

- 6,285
-
Thank you very much. – Muhammad Asraf Ahmed Imon Sep 19 '20 at 07:00