Compacting eliminates unused space in an archive. It also performs routine maintenance and optimizes the archive's structure.
It is recommended that archives be occasionally compacted to recover wasted space and to optimize performance.
Compact an archive by:
To avoid wasting time and resources, the compact action only performs a full compact if the recoverable space in the archive exceeds 12% of its total size. You can schedule a compact action to run regularly, but it will only perform basic maintenance until there's enough free space to warrant a full compact.
The compact menu command (
➤ ) has no threshold. Starting a compact manually will perform a full compact of the archive, regardless of how much space there is to recover.The threshold of recoverable space (12%)
can be modified in the advanced preferences.
You can also specify the threshold when using the
qrecall
command line tool.
An archive is compacted by relocating its individual records so there is no unused space between them. Records may also be reordered to make them more efficient.
Before:
After:
Once all of the records are relocated, the end of the archive's file will be truncated, reducing its size and returning the unused space back to the volume.
A compact also performs the following maintenance procedures:
The compact action can be very time consuming, particularly if the archive is large or I/O is slow.
It is perfectly safe to stop a compact action in progress. The compact will stop its work and gracefully close the archive. The next compact action will resume where it left off.
You can compact exceeding large or slow archives without interfering with your work by scheduling a compact action to run regularly and then adding a condition to stop the action after it has run for some reasonable amount of time (say, 6 hours).
The compact action will run for a few hours each time, until the archive is completely compacted.
Abnormal termination of a compaction process (due to power failure, system/process crash, I/O failure, and similar disruptions) on a non-APFS volume is one of the few situations where the archive can't easily repair itself. (See auto-repair.)
If this occurs, the archive will have to be repaired. The repair command will likely log two kinds of problems, both of which are perfectly normal:
This is due to how records are moved during a compact action. If the archive started out like this:
It might look like this when interrupted:
As records are copied, duplicates of those records exist for a time at their original position in the archive. The repair notes these duplicate records, but they will not affect the integrity of the archive.
There will likely be at least one region of invalid data where a record has been partially written or overwritten. This is also normal and does not mean data has been lost.