title: File Holes and Shared Memory in Linux?
body: <p>Since I read the Linux Programming Interface book (very good read) I discovered the file holes in Linux. Therefore using Unix file formats like Ext4 one can open a new file write 1000 bytes seek to the position of 1000.000.000 write another 1000 bytes and depending the block size of the file format end up with a file consuming just 2048 bytes for a block size of 1024 or 512.</p>
  
  <p>So basically the file is created as a 1GB + 1000 bytes long file where only two blocks of real drive space are used.</p>
  
  <p>Can I erase the middle of a file forcing the system to deallocate those blocks on the drive?</p>
  
  <p>Is there an equivalent where I allocate (shared memory) with or without a file backing it where it has also holes that are just filled as the memory pages are written? </p>
  
  <p>Would be nice to allocate 1GB shared memory but never utilize it fully until necessary just to avoid remapping if the shared memory block should grow.</p>