7

I was reading about the ext4 filesystem that it supports compression, encryption and a feature called extents which is used to save disk space. What are extents and how are they are effective for saving disk space?

  • "Extents allocate space on a storage device in blocks and only store the starting block location in the inode table. This helps save space in the inode table by not having to list all the data blocks used to store data from the file". See also ext4 faq and IBM's ext4 articles – don_crissti Aug 14 '15 at 21:46
3

Extents save space by reducing the amount of metadata needed to keep track of the data blocks for large files. Instead of storing a list of every individual block which makes up the file, the idea is to store just the address of the first and last block of each continuous range of blocks. These continuous ranges of data blocks (and the pairs of numbers which represent them) are called extents.

The addresses of a file's first few data blocks are stored in the inode, but since the inode has a fixed size, this only works for small files. In ext2 or ext3, large files require the use of indirect blocks to store the rest of the list of block addresses which won't fit in the inode itself. That is, the inode contains the address of a block which itself contains a list of blocks. These indirect blocks are the space that's saved by using extents in ext4.

  • Not exactly, I think. You will typically still need indirect blocks, but the amount of metadata (in inode and indirect blocks together) will be much smaller (if the file system is not extremely fragmented). – Philippos Apr 21 '17 at 10:01
  • 1
    The inode can still point to additional blocks if there are too many extents to fit in the inode itself. They're called extent nodes, though, rather than indirect blocks. See ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Extent_Tree – sengi Apr 28 '17 at 19:43
  • @sengi - Is the purpose of extents to only reduce the number of indirect blocks associated with large files? What do offset extents refer to? – Motivated Dec 31 '18 at 23:55
  • @Philippos - In reading sengi's response, it suggests that there are no longer indirect blocks? Is this your understanding? – Motivated Dec 31 '18 at 23:56
0

From http://ext2read.blogspot.ch/2010/03/how-ext4-extents-work-earlier-ext2-and.html :

Earlier Ext2 and Ext3 had the limitation on the size of the file. It used 32 bit block number to access the data blocks. So that limited the maximum size of file to be 2^32 * blocksize(eg. 4k**) = 16TB*. Also the access time for large Files were slow because in had to go through lots of indirection.Ext4 Filesystem can support very large files it has 48 bits to adress a block. Also its uses extents to store data so access time is faster for large files.

The information for the data blocks are stored in the i_data of the inode structure. In a system without Extents, the first 12 entries contains the block numbers of the first 12 blocks of data. Then it contains the block number for the Indirect blocks. That block contains the array of block numbers which point to the data. Similarly, there is Double indirect block and triple indirect block. So if we need to get the data from a very large file, we need to go through those indirection.

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.