0

In the context of e.g. ext4 fs, I often stumble upon both 'fragment' and 'extent' words.

They appear to be both related to fragmentation, extents for example are pretty extensively (duh) explained here.

What's the difference between them?

1 Answer 1

0

Just to add confusion, there are two kinds of fragments and three kinds of fragmentation.

  • A fragmented file is a file that is stored in multiple chunks (or fragments, each of which might be an extent), so that when the file is read sequentially, the OS has to read all the pieces from different places on the disk, which can slow down the reading of the file. ext4fs has algorithms to try to prevent this by allocating blocks for the file as contiguously as possible. A file with multiple extents is said to be fragmented. However, the file could also be stored as a single fragment (i.e., not fragmented) that is a list of contiguous blocks and is not an extent.. so that is how fragments and extents are related.

  • A fragment can also be a file that is smaller than a block or the last piece of a file that is smaller than a block that is stored as a fragment in a full block with other fragments. When block sizes are large and you have a large number of small files, storing multiple file fragments in a single block saves a lot of space and possibly increases performance, especially if you are trying to read all of the files that share a block.

From the filesystem perspective, you can have internal fragmentation and external fragmentation.

  • Internal fragmentation is within a single file, same as in the first type of fragmentation above.

  • External fragmentation occurs when you have related files all in one directory that are scattered all over the disk. If you are trying to read every file in the directory, this can case as much performance issues as internal fragmentation does. The ext4fs algorithms also attempt to minimize external fragmentation by attempting to allocate blocks for files in the same cylinder group as other files in the same directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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