Open In App

Sparse Files

Last Updated : 03 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Sparse Files are a type of computer file that allows for efficient storage allocation for large data. A file is considered to be sparse when much of its data is zero (empty data). Support for the creation of such files is generally provided by the File system. This type of file is used significantly in computer science areas such as DBMS (Database Management Systems), Digital Image Processing, etc. 

Working : Sparse files are created differently than a normal (non-empty) file. Whenever a sparse file is created metadata representing the empty blocks (bytes) of disks is written to the disk, rather than the actual bytes which make up block, using less disk space. This is because empty bytes don’t need to be saved, thus they can be represented by metadata. Actual data blocks are only written when any non-empty (zero) data is written to the file. When reading sparse files, the file system transparently converts metadata representing empty blocks into “real” blocks filled with null bytes at runtime. The application is unaware of this conversion as conversion happens at the file system level. A sparse file need not be totally filled with null data, rather certain empty sections of a file could also be flagged as sparse. The data still follows the aforementioned mechanism, but on a smaller scale. 

Advantages of Sparse files :

  • A large amount of storage space can be allocated without physically writing any sectors, and therefore allows for faster file creation.
  • Allocation occurs only when non-empty data is written, therefore disk space is saved.
  • Since the logical space of sparse files is more than allocated space, therefore more data can be read then allocated.
  • If the initial allocation requires writing all zeros to space, then no actual allocation occurs thus preventing unnecessary disk read-writes.
  • On files which aren’t completely sparse it reduces time of first write as system doesn’t have to allocate blocks for “skipped” space.
  • In certain scenarios is better than file compression.

Disadvantages of Sparse files :

  • Most file copy operations destroy the sparse properties the file. Therefore, sparse regions of file are explicitly allocated on disk, losing their sparse properties.
  • Since logical size of file can be greater than their allocated size, file system free space reports may not be correct.
  • Several applications do not work efficiently with sparse files.
  • Sparse files may become fragmented overtime with valid data writes

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads