2

I know what this command does. It sets up swap area on a device or in a file.
The device being a partition, and file being a simple file.

But I want to know what it does internally on the disk.

Correct me here if I am wrong, Swap is slower than RAM, but faster than simple Disk for operations.

This is my question.

What changes does mkswap makes on disk? I mean, the swap area is still on disk (be it a partition or a file), right?, then how come it works faster than rest of the disk? It must be doing some changes on the disk? What are these changes?

EDIT - It is in reference to this video, https://www.youtube.com/watch?v=uxiis-K6v7w

here it is being told that data accessed frequently is moved to the outer area of the disk. So, I guess mkswap might move the swap partition/file to some outer area of the disk.

luv.preet
  • 5,997

2 Answers2

6

Swap is not faster than of your disk, think about it in form of manufacture, how can your car becomes faster without any tuning of its physical parts?

mkswap is somehow like other mkfs utilities, it prepares your file or partition to be used as a swapping space in a special form which it can't be thought of any other kind of file systems. it prepares a portion of your disk which might be upon a file system itself (a swap file) to save the memory pages directly into it. That might be the reason of feeling it being a little bit more faster.

Also it's nice to read: Does swap space have a filesystem?

Ravexina
  • 57,256
0

mkswap does not make your disk faster. When your swap space resides on a disk it is bound to the physical constraints of that disk. There is no magic that would speed up a physical disk.

Compared to a standard filesystem like ext4 or xfs it might be faster as the management overhead and disk placement is much simpler.

Thomas
  • 6,433