Unix Tip: Fragmentation and Unix file systems

By Sandra Henry-Stocker, ITworld.com |  Operating Systems Add a new comment

Send in your Unix questions today!


See additional Unix tips and tricks


People who have had bad experiences on Windows disks that performed poorly after they had become very fragmented often wonder if they need to apply some kind of periodic analysis and defragmentation on their Unix systems as they transition into a Unix admin or user role. For the most part, the answer is no. Most Unix file systems don't become fragmented the way FAT and NTFS file systems do. But, rather than give a quick yes/no answer, let's take a look at what fragmentation, and why Unix file systems are not as prone to fragmentation as their Windows cousins and what you need to do when a Unix file system is fragmented.

What Causes Fragmentation?

Fragmentation comes about when a system cannot or will not allocate enough contiguous disk space to store an entire file in a single location on a disk. Instead, the file ends up being broken into a number of pieces that are written to various locations on the disk and the file system must then maintain some kind of file system structure that keeps track of where all the related file pieces are stored.

When a file is written to disk, it isn't always possible to write it to the disk in consecutive blocks. The disk may be too full to provide a single location that is large enough to accommodate the file. It takes longer to read a file when it is not stored in consecutive blocks since the disk's read-write head has to move more to gather the individual pieces of the file. While fragmentation is a performance issue, it is less of a problem on a system with an affective buffer cache with read-ahead. On such file systems, the file system may be fetching portions of a file while the user or the application is still occupied with the first few blocks.

Fragmentation on Windows

To see fragmentation on a Windows 2000 system, open Programs -> Accessories -> System Tools -> Disk Defragmenter. Then, click on the Analyze button. This will bring up a graphical display in which the disk areas containing fragmented files are shown in red and, optionally (i.e., if you click on View Report) a list of fragmented files, their sizes and number of fragments. Depending on the degree of fragmentation, the tool will recommend that you defragment the disk. You can then click on Defragment to assemble the files in a non-fragmented fashion. This operation may take quite a while to run, but may make a noticeable difference in your disk's performance.

Fragmentation is more of a problem on FAT file systems than NTFS, largely because the FAT32 file system predates many of the innovations in file system design that have made them work more efficiently.

Fragmentation on Unix

Most modern Unix file systems attempt to fragmentation at a minimum, though they do this in various ways. The ufs file systems used by Solaris and nearly all BSD variants of Unix attempt to keep fragmentation to a minimum by writing related data blocks within the same cylinder group. This reduces seek time when the files are accessed. And, while a large block size is used to improve throughput, a smaller unit of storage -- referred to as a fragment -- is used to store portions of files that don't require a full block. This reduces the wasted space within the file system and one variety of fragmentation sometimes referred to as "internal fragmentation".

The ext2 and ext3 file systems most often used on Linux systems also attempt to keep fragmentation at a minimum. These file systems keep all blocks in a file close together. How they do this is by preallocating disk data blocks to regular files before they are actually used. Because of this, when a file increases in size, several adjacent blocks are already reserved, reducing file fragmentation. It is, therefore, seldom necessary to analyze the amount of fragmentation on a Linux system, never mind actually run a defragment command. An exception exists for files that are constantly appended to as the reserved blocks will only last so long.

Using fsck

To see fragmentation on a Unix system, you would generally use a command such as fsck that reports the percentage of fragmentation on the file system. An example from a fsck output from a Solaris UFS file system is shown here:

1 comment

    Anonymous 3 years ago
    You article is a very good starting point for someone who wants to learn about this topic.The availability of ext4 and online disk fragmentaiton tools should alleviate this problem on open source UNIX implementations. Read my survey at http://sharevm.wordpress.com/2008/12/16/435/The Veritas file system support online defragmentation on all platforms on whic it runs. ufs on Solaris also support online defragmentation.

      Add a comment

      Post a comment using one of these accounts
      Or join now
      At least 6 characters

      Note: Comment will appear soon after you have activated your account.
      Obscene/spam comments will be removed and accounts suspended.
      The information you submit is subject to our Privacy Policy and Terms of Service.

      ITworld LIVE

      Operating SystemsWhite Papers & Webcasts

      White Paper

      Microsoft Enterprise Agreement Program Overview

      Discover how flexible the Microsoft Enterprise Agreement Program is to help you build the right software solution agreement for your business. This paper highlights all the available options-from on-premise software and cloud service solutions, to payment options and enrollment programs, and more.

      White Paper

      Watson - A System Designed for Answers. The future of workload optimized systems design

      Watson is a workload optimized system designed for complex analytics, made possible by integrating massively parallel POWER7 processors and DeepQA technology. Read the white paper about Watson's workload optimized system design.

      See more White Papers | Webcasts

      Ask a question

      Ask a Question