Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What does a defrag do really? Does it put the files that execute in sequence closer together?

share|improve this question

5 Answers

Actually it puts all the different parts of ONE file together, so if that particular file is needed, the harddisk doesn't have to move its arm (which is the real performance-breaker here) that much to gather all the bits of the file. ==> hence, better perfomance (although it's not always noticable).

Note that this only applies to hard disks with platters and movable parts. For SSD's this is no problem, as it takes the same time to fetch any data independent from where it's located on the disk. Defragging SSD's is actually a bad idea as they have a limited number of times they can be written to on each 'sector' (I don't think 'sector' is the right term here, but you know what I mean I hope).

share|improve this answer
2  
Not only is it not a problem for SSD's but defragging them is actually a bad idea due to their limits. – Jeff Yates Jul 27 '09 at 14:13
Indeed I'll update my answer. – fretje Jul 27 '09 at 14:29

It depends on the defragmentation program.

At a minimum it will aim to put the clusters for a single file or directory into a contiguous sequence, providing that there is space available to do this.

It may also sequence files and directories according to usage profiles, if it collects these.

It may not be able to move some files (certain open and system files typically).

The reason for defragmenting is that random reads are considerably slower than reading a continuous sequence of blocks/clusters off the disk. However, not all file systems or operating systems have the same requirements for (separate) defragmentation programs.

share|improve this answer
Defragmentation also usually groups the free space on the disk into clumps that are as big as possible. This helps to prevent newly-created files from being fragmented in the first place and allows them to be written out faster. – David Schwartz Aug 24 '11 at 2:37

Defragging can do two things:

  • Ensures all the pieces of a file are located in a continuous part of the hard drive. Most files are split into smaller "fragments" that are stuck wherever there is space. At first they will be stored continuously, but gaps/incontinuities will be created when files are deleted/modified. If a file is continuously stored, then it can be read faster.
  • Optimize the location on the harddrive (spinning harddrives only.) Hard drives are composed of spinning disk-shaped platters. The outside spins faster, so the harddrive will perform better when writing/reading near the outside of these platters because more data will be passing under the read/write head for a given time period.

Also, I'd like to add something about defragging SSD's:

Defragging an SSD

Long ago I promised to post on why defragging an SSD is still relevant and necessary. It’s true that with an SSD there are no physical platters that have to spin into place and no read/write arms that have to move wildly across the surface of a disk. For this reason, it seems like defragging is a waste of time. You could also argue that since SSDs eventually wear out, you should not waste rewrite cycles on something as simple as defragging your disk.

One of the facts about NAND flash memory technology used in SSDs is that writing data takes much longer than reading data. When a file is erased, much like standard hard disk technology, only the directory information is erased and the data cells are marked “usable” again. The data itself is still intact until something new overwrites it.

This means that if the memory space is in use with a “deleted” file, it must first be erased before it can be reprogrammed. If the free space is fragmented, a new file must be broken into several small write commands instead of one larger write command. This will cause a performance decrease for SSDs because write speed is slow, especially for small block write transfers. Yes, cache memory helps mask this performance issue, but no matter what the technology, one long write command is always better than multiple short write commands.

Net, defrag your disk regularly if you want maximum performance.

source: Inside the Box Lenovo blog

share|improve this answer
2  
This guy you quote is wrong. The SSD internally combines several writes to different logical blocks into a single flash write. Like reads, random writes are just as fast as sequential on an SSD. – psusi Jan 13 '11 at 20:29
3  
You also can't control where data is placed on most SSDs, due to the wear leveling algorithms. While it may be possible to overcome these algorithms with the use of special software, most "off-the-shelf" software won't cut it. – Breakthrough Aug 18 '11 at 15:01

Without getting into too much technical mumbo jumbo, it makes your hard drive look less like swiss cheese.

More details and an animated image here: http://en.wikipedia.org/wiki/Defrag

share|improve this answer

Defragmenting a drive can do a couple of different things. Typically the defrag process looks for files which have been broken up into chunks for whatever reason. Many cases this occurs from reading and writing to a drive over time. The defrag program assembles all of the fragments and then find a spot on the disk where that entire file will fit. In some cases it ends up being a but of a shell game to move things around making places for all the largest files.

Now something to be said about putting all of these files together concerns the typical "seek" time of the Read/Write head on the disk. Every time you have to move the read/write head somewhere else on the disk you typically incur a delay of a number of milliseconds. When reading a file that is all in one location, the read/write head does not have to move very far at all to continue reading the file. This is much faster than going to another spot entirely on the disk. In some cases defragmentation can be done to optimize the operating system by placing the system files accessed most frequently closer to the "landing zone" for the read/right head when it is not performing any reads/writes. This can in many cases speed things up quite a bit.

I have not seen a defrag tool out there which has the ability to keep statistics on the number of times a file has been accessed, but if there was, it could stack the disk first with the most frequently accessed files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.