Tuesday, February 11, 2014

Why shouldn't I defragment my SSD drive?

Many years ago, I read a book called Hard Disk Smarts: Everything You Need to Choose and Use Your Hard Disk.

Great book that helped me understand how a hard disk works, and how to organize my data in files and folders. Basic stuff that most kids know by age 10 now. But in 1988, people were still figuring that stuff out - this book was really helpful to me. It explained what was physically going on inside the hard drive.

It was the first time I'd heard about maintaining your Hard Drive (HD) performance by running a defragmentation utility.

Defragmentation (defragging) has become a standard maintenance operation on hard drives, and it's something I automatically set up on machines that I build. I'm sure I'm not alone.

But, I'm going to have to change.

I recently bought a Chromebook with 16GB of solid state (SS) storage, and no hard drive. (I love this machine, but that's another post). The operating system comes from SS, and I'm meant to keep my data files in the cloud. It boots extremely fast, and I am rarely waiting for data from the cloud. In other words, this Chromebook feels faster than any other machine I have.

The speedy feel is due to the solid state storage. It's not the CPU. It's not the amount of RAM. I have other machines that have more/better of both, and still feel slower. It's the hard drive.

Solid State Drives (SSDs) are generally faster than Hard Disk Drives (HDDs). But why not defragment?

Defragmentation does two main things:

  1. It moves data to "fast" parts of the HDD
  2. It consolidates file fragments
It turns out that neither of these things makes any sense on an SSD, and can actually be harmful.

To understand why, let's look at how HDDs work.


HDDs have spinning platters in them (see video below). In other words, there are moving parts.


Here's a video showing clearly the multiple platters on an old-school drive:


In order to read or write from a platter, the read/write head must move to the right position on the spinning disk (access time), then wait until the appropriate spot on the disk spins to the position under the read/write head (rotational latency time). Then, all the magnetic spots on the platters have to travel under the read/write head.

These two physical operations take time. And because these are physical operations we can affect how long each one takes.

So what do we mean by "fast" parts of the disk? In short, the outside edges of the platters, and/or near the head park location.

Each platter is "lined" from center to edge, creating circular regions called tracks. Then each track is sliced into pieces that contain data called sectors. Because the outside track is longer than the inside track, there are typically more sectors on the outside track. The actuator arms (the arms that move the read/write heads across the platters) move the read/write head from track to track, then sectors are read as they spin under the read/write head.

To reduce access time we could put data in a spot on the platter that does not require the actuator arm to move very far. In other words, put data on tracks close together. In the videos above, notice that read/write heads begin "parked" near the spindle at the center of the platter(s). To reduce access time, we could position data near the center of platters. Then the actuator arms do not have to move as far, so the access time is reduced.

Once the read/write head is in the right spot, it must read the magnetic sectors on the disk as they pass under the read/write head. Because there are more sectors on the outside tracks, more data can be read/written in one revolution of the platter. So, outside edges are "faster".

And what do we mean by "consolidate file fragments". 

Files commonly get split into multiple pieces and stored in fragments on a drive. This usually happens when a file is too big to fit into an open space on a disk. Over time, this can happen to many files, and each file can be split up into many pieces (tens, hundreds, or even thousands of pieces.)

So, if a user want to open a file that is actually split into two pieces on the hard drive, the activities are:
  1. access the track where fragment 1 is located (access time)
  2. wait for platter to rotate the first sector of fragment 1 under the read/write head (rotational latency)
  3. allow all sectors of fragment 1 to pass under the read/write head (read time)
  4. access the track where fragment 2 is located (access time)
  5. wait for platter to rotate the first sector of fragment 2 under the read/write head (rotational latency)
  6. allow all sectors of fragment 2 to pass under the read/write head (read time)

 If the file was all in one piece, items 4 and 5 would not have to be done! Imagine a file in a thousand pieces - that's a lot of extra work!

Alright, so fragmentation on a HDD can make it take longer to read/write data files. And to speed things up, we can de-fragment, which puts all the file fragments together, and puts them on fast parts of the platters.

But why not do that with SSDs?

Well, SSDs do not have spinning platters, or moving actuator arms - they have no moving parts. They consist of solid-state chips accessed electronically. This means that access times are the same for any storage location in the SSD. There are no fast locations and there are no slow locations. 

Also, because the time to get to a piece of data does not depend on the location, having file fragments physically next to each other means nothing. Said another way, accessing sectors 1 and 2 is no faster or slower than accessing locations 1 and 50000. Proximity means nothing.

OK, so consolidating files doesn't help on an SSD. And there are no fast/slow sectors in an SSD. But why not defragment anyway?

Well, solid state memory chips actually have a limited life cycle, meaning that they wear out. Writing to the sector actually wears it out a little. So moving data around in a defragmentation operation actually reduces the life of your SSD.

So:
  • defragment your HDDs - it will help performance
  • DON'T defragement your SDDs - it won't help, and it actually hurts





No comments:

Post a Comment

Followers