Defragmentation

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 70.150.196.243 (talk) at 16:02, 5 January 2006 (→‎Utilities: Removed blatant Diskeeper advertisement.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In the context of administering computer systems, defragmentation (or defragging) is a process that eliminates fragmentation in file systems. It does this by physically reorganizing the contents of the disk in order to store the pieces of each file close together and in order (contiguously). It also attempts to create large regions of free space using compaction, to impede the return of fragmentation.

Aims of defragmentation

Reading and writing data on a heavily fragmented hard drive is slowed down as the time for the heads to move between fragments on the disk surface can be substantial. The disk operates at speeds millions of times slower than the CPU; thus the desire to process more efficiently encourages defragmentation. Operating system manufacturers often recommend periodic defragmentation in order to keep hard drive access as fast as possible.

Fragmented data also spreads over more disk than it needs. Thus one may defragment in order to compact data storage before splitting a single partition into two or more partitions (for example, with GNU Parted, or PartitionMagic).

Causes and cures

Fragmentation occurs when the operating system cannot or will not allocate enough contiguous space to store a complete file as a unit, but instead puts parts of it in gaps between other files (usually those gaps exist because they formerly held a file that the operating system has subsequently deleted or because the operating system allocated excess space for the file in the first place). As advances in technology bring us larger disk drives, the performance loss due to fragmentation squares with each doubling of the size of the drive. Larger files and greater numbers of files also contribute to fragmentation and consequent performance loss. Defragmentation restores a drive to its original speed.

[Source: Jensen, Craig (1994). Fragmentation the Condition, the Cause, the Cure. Executive Software International. ISBN 0-9640049-0-9.]

A defragmentation program must move files around within the free space available in order to undo fragmentation. This is a memory intensive operation and cannot be performed on a file system with no free space. The reorganization involved in defragmentation does not change logical location of the files (defined as their location within the directory structure).

Defragmentation issues

The presence of immovable system files (or of files that the defragmenter will not move in order to simplify its task), especially a swap file, can impede defragmentation. ntfsresize can safely move these files in order to resize an NTFS partition.

Certain file systems exhibit a greater susceptibility to fragmentation than others, for example, a FAT file system becomes fragmented much more quickly than NTFS. Many file systems on Unix-like platforms do not require defragmentation at all. These systems attempt to keep fragmentation below a certain point so defragmenting is not necessary. This fragmentation resistance works well as long as the file system has a fairly large amount of space free.

On systems without fragmentation resistance, fragmentation builds upon itself when left unhandled, so periodic defragmentation is necessary to keep disk performance at peak and avoid the excess overhead of less frequent defragmentation.

Utilities

File:Windows XP-Disk Defragmenter.png
Microsoft Windows XP Disk Defragmenter.

Defragmentation programs often come bundled with an operating system (although Windows NT 4 notably did not include one).

Perhaps the best-known defragmentation utility is the MS-DOS and Windows program DEFRAG. It can be accessed in modern versions of Windows as "Disk Defragmenter", found on the All Programs -> Accessories -> System Tools folder of the Start Menu.

Filesystems

  • FAT comes with a defragmentation utility called Defrag.
  • Ext2 uses an offline defragmenter called e2defrag.
  • Ext3 has no defragmentation tool, but can be temporarily downgraded to ext2.
  • JFS provides defragfs utility.
  • HFS Plus in 1998 introduced a number of optimisations to the allocation algorithms in an attempt to defragment files automatically without requiring an external defragmenter.
  • XFS provides an online defragmentation utility called "xfs_fsr" (although it is largerly unnecessary).