What do defrag, compress and shrink mean?
The file system gets fragmented when files are deleted or truncated. When the file system reuses the free fragments for new files that are created, or for new content added to existing files, blocks are dispersed across discrete fragments and may not be allocated contiguously. Fragmentation can cause performance degradation when a read/write request for the next block requires a seek to a different cylinder on the disk, essentially the dispersion of data on the disk causes random seeks for reading/writing the next block.
Defragmenation is applied to a disk and causes all the used blocks of a file to move towards the beginning of each file and all the free blocks to move towards the end. The free space can then be reclaimed by truncating the file.
Data Compression causes the reduction in storage requirements for data using a particular encoding scheme so that the encoded data uses less space than the unencoded data. The Windows zip file format and the UNIX gzip utility are examples of compressed file formats.
While compressing a file, i.e., compressing data within it, can cause a reduction in storage requirements through a change of representation, there is a conversion overhead to be paid for reading and writing to such a file. Note that data compression cannot recover free space from a fragmented file.
Reclaiming unused space through Compacting or Shrinking a File
Unused (free) space is reclaimed from a file by performing two discrete operations:
- Defragmenting it
- Truncating it so that only the used blocks (content) remains and contiguous free space is returned to the file system.
The two operations may be packaged together in a single tool, e.g., the VM Shrink from VMWare, and their effect is to resize, i.e., compact or shrink the file to a smaller size. While the term compression may be a misnomer, it also also seems to be used in the context of shrinking files