NO DEFRAGMENTATION NEEDED IN LINUX

We all must have heard about defragmenting our hard drives to speed up performance. Sound of that similar to windows users but we don’t have any defragment utility, hell, we don’t need to defragment! And why is that? Lets find out-

I remember when I was new to Linux, a friend of mine came with a hard disk and asked me to defragment it (yeah, we all have faced it).  It was easy in windows, how hard it could be in Linux?  I connected the spare bus to his hard disk and then started a mission to defragment via Linux. I can’t stress this enough that I was new to Linux and didn’t know much about how things work. After trying every bit I knew, looked up the mighty google and it came like a bolt from the blue- NO DEFRAGMENTATION NEEDED IN LINUX. </chitchat>

What do you mean by fragmentation of hard disk?

I’ll cover it in as short as possible; your hard disk is divided into sectors. These sectors are capable of storing small pieces of data. So, when the size of file is more than size of a sector then the file is saved over multiple sectors, as simple as that. As the new file comes, it is saved next to previous sector. But, when the size of first file increases, it might not find free sectors near original file so it will be saved few sectors apart, this goes on and on. While reading this file, the head will have to skip physical locations which ultimately will make things slower. Defragmentation is the process in which file is put back in continuous fashion so that there is no skipping of sectors.

Note: Defragmenting is not recommended for SSD drives. They have a different theory, doing so will reduce their life.

How it works in case of Linux?

Linux’s file systems deal with fragmentation in an intelligent way. Instead of placing files next to each other, it keeps a lot of space between the sectors of two files therefore leaving space for these files to grow. This keeps fragmentation far away, yet not impossible. Even if there are fragments, file system attempts to move the files thereby reducing the fragmentation. The system is designed to avoid fragmentation in normal use. You might face some fragmentation when your space fills up, may be 80% or 90%. The more suitable method to deal with it is to get a new hard drive with more space else you can copy your files to other drive, delete original files and then copy them back- they will be arranged automatically.