Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is file hole and how can it be used? [closed]

To my understanding, holes are perhaps maintained as metadata at inode, but actual disk is not filled with empty zeros.

  1. Can someone explain with real life usage examples, where holes in a file can be useful?

  2. Is holes same as soft preallocation? From diskusage perspective, even though actual disk space is not used, but that space is also not available for other process.

like image 389
Jimm Avatar asked Dec 21 '12 00:12

Jimm


2 Answers

Files with holes are usually referred to as sparse files.

They are useful when a program needs to access a wide range of addresses (offset) but is unlikely to touch all of the potential blocks. This can be used by virtualization products to store virtual disks. Let's say you configure a virtual machine with a 20 GB disk but it won't be full of data quickly. It is much faster to create a 20 GB sparse file that will only use a couple of disk blocks at the beginning and then have the VM creating a file system and storing files at a low pace.

A large sparse file can also have its size reduced when some of its blocks are blanked (i.e. filled with null bytes). The sparse file aware program doing it can, instead of actually writing to the blocks, remove them from the file (i.e. punch holes in the file) with the very same effect because unallocated blocks are returning zeroes when read by a program.

Sparse files are the opposite of preallocation, they are what is called thin provisioning or might also be called disk overcommitment. This allows creating more "virtual disk space" than the actual hardware supports and add more disk to grow the file system only when necessary.

like image 162
jlliagre Avatar answered Oct 03 '22 11:10

jlliagre


Holes are "useful" in the sense that they reduce disk space use (they make more space available). They aren't use able in any other sense. The existence of holes as part of a filesystem representation is "useful" when one has sparse files that contain large blocks of zeroes.

Holes don't have anything to do with pre-allocation. Pre-allocation makes space available on the disk for data in a file before the file actually has that data. Holes are a representation of data ... specifically of blocks consisting solely of zeroes.

like image 36
Jim Balter Avatar answered Oct 03 '22 09:10

Jim Balter