Compression really occurs when the inode is put, i.e. closed by every process that have a reference to it. Writing to a compressed file is done as if the file were not compressed (uncompressed data is written to the disk), but the file is marked dirty. When the inode is put, and if the file is dirty, the kernel scans every cluster and compresses those that are not compressed. Unneeded blocks are freed again.
Decompression occurs when needed, i.e. every time the kernel wants to read a compressed cluster. Of course, the cluster remains compressed on the disk. But this means that we will have to decompress the cluster every time it is accessed.
See section What if I decompress a file on a full device?, for a related question.
Go to the first, previous, next, last section, table of contents.