eli5: what does (de-)fragmentation even mean?

36 views
0

After reading another post about why defragmentation isn’t as necessary with modern devices, i started wondering what exactly fragmentation even is. How and why does it happen and doesn’t it screw up your data?

In: 0

My dad always told me it was like tidying your room, and organising everything alphabetically, but in your disc c 😂

Old mechanical hard drives with platters and stylus reader would take longer to travel over the physical magnetic disk in multiple places to pull all the bits of data associated with a program. Defrag consolidates all the data together into one physical chunk on the disk, so the stylus and disk doesn’t have to move around as much or travel as far to access all the data. Modern solid state drives have no moving parts but contain a controller with address bits to each piece of data, so there is no speed decrease by accessing data from multiple places on the drive. The controller directs the drive to each bit of data, and because electrons move at the speed of light, more or less, it doesn’t matter if the data is contained within address bit #1 or #736347, etc… the speed is the same. Defrag is not necessary for SSD.

Let’s say you have a hard disk with 10 files on it, and file #4 is 8 blocks long. If you delete file #4, there is an 8 block “hole”. If you add a new 12 block file, there might be space at the end of the 10 files. At some point, however, there won’t be enough unused space at the end to fit the next file. Eventually, 8 blocks of some file will pe put where file #4 used to be and the rest of that file will be someplace else. That file will be in two fragments, one where file #4 used to be and another one someplace else. If you do this enough and the disk as little free space, eventually you’ll only have a bunch of 1 block holes. That means a new 15 block file will be split into 15 fragments, and that will take 15 times as long to read as if the file was all together. SSDs have no access time, eliminating this “longer time to read” effect.

Defragmentation is the process of copying all the files into a pattern where every file only needs one fragment. This involves a lot of copying and work, particularly if your disk has little free space.

Today, hard drives are big and running them almost completely full is uncommon, so the problem doesn’t occur much. The newest operating systems work to minimize fragmentation, and SSD drives are worn down by frequent defragmentation, so it’s not a common thing to do manually anymore.

Imagine you have a book (Your hard drive) it has a story but the data is spread out. Some words on page 1, a few more on page 2, a bunch on page 3 and so on. This is done by the computer to fill up any available space. Defrag essentially takes all the words and moves them to page 1…this makes it faster to read and therefore more efficient.

Let’s say you have a library. And you are in the mood to read a book. So you just grab the book and read it, front to back. EZ.

But, let’s say, when you’re trying to put the book back, for whatever reason, there isn’t enough room for it to fit on the shelf. So, instead, you rip the book in half, put half of it on the shelf where it used to be, and the other half in the next available free spot. You also include a note with the first half explaining where to find the second.

The next time you’re in the mood to read that book, you’ll grab the first half, read it, but then you’ll have to stop and find the second half to continue reading.

This is fragmentation. And, if done a lot, can really slow down the loading and reading of files.

*De*fragmentation is the process of sitting down, taking all the books off the shelves, putting them back together, and putting them back on the shelves, whole.

It’s not really a thing anymore because the ways in which we store and organize files are better, the ways in which we load and read files is better, and the configuration and speed of newer hardware (e.g. SSDs) makes fragmentation largely irrelevant.