In the simple world of the past, storage consists of some that’s in use, and the rest that’s free and can be used on demand. Then came a third type, storage space that’s in use but for not so essential purposes, so it can be freed up and used for something else when necessary – purgeable space. This article looks in depth at what it is, what counts as being purgeable, and how it’s purged.
The Finder, Disk Utility and third-party utilities refer to storage space using different terms, most of which are opaque. Throughout this article I rely on Disk Utility, which is what you should rely on too. Although figures given by the Finder can be reliable at times, it updates those less frequently, and at times gets badly out of kilter with Disk Utility.
What is free?
To get the most accurate and up to date figures for your Mac, open Disk Utility and check its View tool at the left of the toolbar is set to Show All Devices. Then select the container containing the Macintosh HD volumes in the sidebar:
- Capacity is the total space available in your boot container (normally in your Mac’s internal SSD). This is slightly smaller than the full capacity of that SSD, as some is used by hidden containers.
- Free is the total space not being used for storage in that container, so available to all the volumes within it.
- Used is the current total size of all the volumes sharing that container, as broken down in the bar above.
- containerCapacity = containerFree + containerUsed, with no allowance made for any purgeable space within any of the volumes.
Now select the Data volume within that container:
- Available is the total space that could be made available by macOS.
- Purgeable is the space that macOS could free if necessary to maximise that available for that volume, and only includes space used by that volume. Other volumes may also have purgeable space, but those aren’t included here.
- volumeAvailable = containerFree + volumePurgeable, making it the maximum space that could be made available for that volume’s storage.
I’ll use those qualified terms like containerFree below, so you know exactly what I’m referring to.
What is purgeable?
The closest I can find to Apple’s definition of purgeable storage space is that given in the Disk Utility documentation explaining what Available means:
“Amount of space available, which can include both free space and “purgeable space” — or space that macOS can free up when needed by removing files from your computer (you can’t manually remove the files that are designated purgeable, but macOS removes them as space is required).”
Purgeable space is completely different from System Data shown in Storage settings, and the two correlate only weakly. For instance, my current purgeable space is shown in Disk Utility as 21.17 GB, while System Data is given as 72.71 GB. Figures for System Data appear to be notional if not fictional, and are best treated as arithmetic artefacts.
Oddly, documentation for most third-party utilities that claim to perform housekeeping repeats Apple’s statement that purgeable files can’t be removed manually, then proceed to claim how that utility can perform purging.
Users across many discussions and sites have come to assume that purgeable space includes some or all of the following:
- APFS volume snapshots
- iCloud Drive files that could be evicted from local storage
- purchased Store content including music and other media, and App Store apps, that could be downloaded again
- local caches controlled by macOS
- the version database in .DocumentRevisions-V100 and other similar hidden databases
- Spotlight indexes.
As those can be removed manually using only tools bundled with macOS, and some like snapshots are demonstrably included in purgeable space, Apple’s explanation is thus untenable, and reference to manual removal should itself be removed. Whether their removal should be left to macOS is another matter.
Apple does give more details about caches and temporary storage in developer documentation for two standard paths available to all apps, cachesDirectory and temporaryDirectory. Apple advises:
“When you download or otherwise generate content that your app can recover if it needs to, store that content in the cachesDirectory or the temporaryDirectory. The system automatically deletes content in the cachesDirectory and temporaryDirectory — an operation known as purging — when it detects that disk space is low.”
cachesDirectory is normally the path ~/Library/Caches, inside that app’s Container if it’s sandboxed, and temporaryDirectory is in a sandboxed app’s container at /Data/tmp, or in the warren of folders at /var/folders/…/T/ for apps that aren’t sandboxed.
How is purging performed?
When observed in the log, purging is performed by the deleted daemon in the subsystem com.apple.cache_delete. Repeated waves of purging take place routinely as part of events such as preparing to install a macOS update, and in response to shortage of containerFree space. Although the latter may be triggered when it reaches a set level resulting in a Lowdisk notification, the most reliable is an ENOSPC error reporting that there’s insufficient free space for a requested file operation. Lowdisk notifications are also sent for other writeable volumes in the same boot volume group, VM, Preboot and Update.
Before purging starts, background services that might request free space are shut down. This can be seen in the Spotlight server, which recycles and closes its stores until purging has been completed. deleted then sets itself a freespace goal, and subtracts current containerFree space from that to determine the amount it needs to delete if it’s to attain that goal, and records those in the log.
deleted manages the caching services listed in the property lists in /System/Library/CacheDelete, currently 28 including Spotlight, QuickLook, Time Machine and others. As those are in the SSV they can’t be modified or added to, so third-party apps that want their caches to be included normally set the isPurgeable flag on those files to true so they’re added to the com.apple.fspurgeable_data list that supplements the list of caching services.
Each caching service keeps an account of its cached files and the total space they take, some periodically refreshing that using a background service scheduled and dispatched by DAS-CTS. When deleted needs to know how much space could be freed by purging those caches, it obtains the current figure from each of those services in turn. It can then work out whether sufficient space could be purged to meet a request from macOS, thus whether that request can be accommodated by realising purgeable space. If it can, it’s then up to deleted to call for the selected caching services to purge their caches to provide the free space needed.
deleted then proceeds through a series of rounds to delete purgeable space, during which it calls on individual caching services to perform purging at increasing levels of ‘urgency’. Those rounds can take a few seconds each, and may halt when the freespace goal has been met, although when performed in preparation for a macOS update they normally run through to completion.
There is an obvious snag here, of pre-existing snapshots. Although a caching service might declare it can purge 2 GB of space, if the files involved are included in a snapshot, that increase in free space won’t occur until that snapshot has been deleted. Until then, those 2 GB are effectively transferred from caches to snapshots, and could be retained there for 24 hours until that snapshot is deleted routinely. When necessary, it’s possible that could trigger early snapshot deletion.
Purging is thus a slow and complex series of operations whose outcome isn’t known until they have completed.
Manual purging
As far as I have discovered, there’s no direct way for a user or third-party app to initiate purging. The most popular way advocated to trigger purging is to force it because there’s insufficient free space, and the most ingenious way to do that is to almost fill containerFree space, then attempt a write operation that requires more free space than that available in containerFree, so resulting in an ENOSPC error. Once purging has completed, the original operation that almost filled containerFree is then reversed.
As that apparently has no control over the freespace goal set by deleted, its results are unpredictable, and in many circumstances free space released by purging could be minimal. It’s seldom if ever likely to recover all purgeable space, and could prove fruitless.
Immediate evaluation of the success of purging can be misleading even without the complication of snapshot retention. Cached QuickLook thumbnails and previews, for instance, could be emptied completely, then over the following minutes and hours their size could readily increase to exceed those prior to purging. When hourly snapshots are being made to support backups, deleting all snapshots except the most recent could increase containerFree space substantially, only for that to fall again as the next 24 hours of snapshots are added.
Monitoring ‘free space’
Currently, macOS makes most available the figure for volumeAvailable space, that’s the sum of containerFree and volumePurgeable. While that can spare the user from seeing frequent changes in volumePurgeable, it also conceals marked rises in volumePurgeable that users need to be aware of, such as exceptionally large snapshots.
If a user isn’t given control of purging, it would surely be preferable for them to see containerFree instead, so alerting them early if that should fall markedly, indicating they should take early action to restore containerFree space.
Why purge?
Purging is intended to free storage space temporarily, to allow a macOS update to be installed correctly, or for purgeable space to be used for an immediate and more important purpose. It comes at a cost, though, as snapshots, caches and other data removed in purging would normally have been retained for a purpose. In many cases, that data will be recreated over the coming minutes, hours and days, and volumePurgeable will rise again. Purging buys time, and is no substitute for housekeeping, or improved storage management.
Reminder
- containerCapacity = containerFree + containerUsed, no allowance for purgeable space.
- volumeAvailable = containerFree + volumePurgeable, making Available the maximum space that could be made available for that volume’s storage after purging all purgeable space.
References
Caches and purging in macOS Tahoe
Why can purging snapshots fail?
Will flushing caches free up disk space?
