what Defragmentation is


what Defragmentation is

In: Technology

Imagine your computer was a vast library full of books, with the location of every book catalogued and stored to quickly find it later. This is basically how your computer stores information. Now imagine that sometimes a book is too big to fit on a shelf, and the shelf next to that shelf is also full. This isn’t a problem because you have all the location of the books catalogued, so what you do is cut the book in half and catalogue part one on one shelf and part two on a shelf down the hall. This data is now fragmented. This works fine, but can obviously get annoying to have to run to two sections of the library to go get that info. So you under go the great library defragmentation. You basically take all the books down and re-arrange them so no book is broken up like that. This is data defragmentation.

Taking things that are separated and putting them back together.

If referencing computers, back when hard drives used circular platters and a magnetic needle to read and write data to sections of the platter. As you make and delete little bits of data on some sections of the platter, there is not enough room there, so data has to be stored on other sections. Then, when you need to read that data, you need to wait for the magnetic needle to travel all over the platter back and forth, increasing the time it take to access the data. Defragmenting took all that data and rearranged it like a bookshelf to keep everything in order and reduce travel of the magnetic needle to make reading the data quicker.

Nowadays, we mostly use solid state drives that don’t have the needle and platters and also have advanced file systems that automatically arrange the data for you so that defragmenting is no longer necessary.

A hard disk is a spinning physical disk. The disk is divided into blocks, think of them as little boxes to hold your data.
Your files are split up into these little boxes, the bigger the file the more boxes it’ll need.
Now to read your files, the disk moves an arm with a reader over to where the blocks your files are, then it spins the disk so the part where your files are.
Moving the arm is really complicated, hard and slow, and waiting for the disk to spin is also slow. (at least for computer standards)
So you want to have you file’s blocks all in a neat little row, so they don’t need to move the arm and just spin the disk, and even then it doesn’t have to skip over blocks it doesn’t care about right now.
Now lets say you have 5 blocks, 1-5.
You have 5 files, all 1 blocks each.
1:File 1
2:File 2
3:File 3
4:File 4
5:File 5

Now you delete files 1,4 and 5
2:File 2
3:File 3

Now you want to write a big new files that takes up 3 blocks.
Computer slots it in
1:New File
2:File 2
3:File 3
4:New File
5:New File

Now your computer has a problem, to read the new file it has to skip blocks 2 and 3, meaning you’ll have to wait for the platter to spin. We can say that the New File is fragmented.
Now this is a tiny example, but a badly fragmented file system might mean that the disk head is jumping all over the place and waiting a lot for the disk to spin, as it tries to find hundreds of files in millions of blocks.
So defragmenting says.

We’ll swap block 3 and block 1. Now the files system looks like:

1:File 3
2:File 2
3:New File
4:New File
5:New File
and all is good

When a computer stores a file, it starts at the first available spot on the disk and keeps writing until it bumps into something else, then it finds the next available spot and leaves a little note that the different parts of a file are in different spots. Defragmentation is when you go through and move all the files around so they’re all in one piece instead of being written partway through each other. You do this because if everything is thoroughly chopped up, it takes longer to read and write files because you have to keep going back to those notes on where everything is.

You know how a frag grenade sends lots of tiny bits all over the place? Defragmenting is putting them back again. It’s easier to pick up and move as one piece than it is as many.