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 reduce 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 are called indirect blocks. These extra blocks are not usually needed when using extents, because storing an extent takes a constant amount of space regardless of how big a range of blocks it describes.
A very fragmented file might still need extra metadata blocks (which ext4 calls extent nodes) to store a long list of extents, but typically still much fewer than would be needed otherwise.
The reduction in metadata size is usually quite small in proportion to the size of the file, though. The main motivation for extents is about improving performance (by reducing fragmentation and having fewer metadata blocks to read and write) rather than saving space per se.
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.