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,787
  • 1
    I strongly disagree that this is a duplicate. I know what Swap Space is, but that doesn't tell me what mkswap does to a logical file or physical partition except maybe, as the question states, moves it's logical allocation to a contiguous place on the physical disk. @Ravexina links to a question whose accepted answer also properly answers this question: https://askubuntu.com/questions/846163/does-swap-space-have-a-filesystem ... even though the question isn't about mkswap it does a great job of explaining what mkswap actually does. The answer here link above does not. – Jonathan Dec 18 '18 at 03:08

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
  • 55,668
  • 25
  • 164
  • 183
  • I have added more info about the question. check it – luv.preet Aug 06 '17 at 16:52
  • 1
    I didn't see the video, however I can guess that it meant to be "data accessed frequently is moved to the outer area of the swap" just like a stack, if you're using a file as a swap space it will be where ever it was created, same as a partition which you can't change it's physical location on disk using mkswap. – Ravexina Aug 06 '17 at 17:36
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,223