APFS purgeable space

APFS has this weird feature of purgeable space which is basically disk space that should be empty but is still reported as used. If anything tries to claim disk space it will be purged but for any reporting purposes the disk might look full.

So in case you always seem to be on the brink of running out of disk space you might want to run this (at your own risk of course :))

sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -P  /System/Volumes/Data/private/var/db/*

Note that this might take a while (few minutes) on a first run. Given that it might be deleting 100s of GB it makes sense.

As an example it looked like this for me:

$ df -h .
Filesystem     Size   Used  Avail Capacity iused     ifree %iused  Mounted on
/dev/disk3s1  926Gi  846Gi   43Gi    96% 4057305 448723440    1%   /System/Volumes/Data

$ time -p sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -P  /System/Volumes/Data/private/var/db/*
request has flags: 0x0 type: 0x0 min_size 0 max_age 0 desired_amt 0 (size: 32)
Purging files on /System/Volumes/Data/private/var/db/Accessibility returned 0 (OK).  Deleted amount: 303885606912
real 220.16
user 0.01
sys 55.53

$ df -h .
Filesystem     Size   Used  Avail Capacity iused      ifree %iused  Mounted on
/dev/disk3s1  926Gi  563Gi  326Gi    64% 3657478 3415215200    0%   /System/Volumes/Data

Subsequent runs are really fast though:

$ time -p sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -P  /System/Volumes/Data/private/var/db/*
request has flags: 0x0 type: 0x0 min_size 0 max_age 0 desired_amt 0 (size: 32)
Purging files on /System/Volumes/Data/private/var/db/Accessibility returned 0 (OK).  Deleted amount: 0
real 0.04
user 0.01
sys 0.02