iCloud Drive in Sonoma: Optimise Mac Storage or not?

There are two fundamental controls for iCloud Drive: whether to Optimise Mac Storage, and whether to put Desktop & Documents Folders into iCloud Drive. This is the first of two articles that looks at what each does, and how it works. This starts with the simpler choice, based on whether you want iCloud Drive and your Mac’s local copies of files to remain in sync at all times.

Prior to Sonoma, the Optimise Mac Storage control made little if any difference to the behaviour of iCloud Drive. Regardless of the chosen setting, both the user and macOS were able to remove files from local storage, a process known as eviction. For several years, this wasn’t easy in the Finder, as there was no accessible control to evict files, although this was a major feature in my free app Cirrus and its menu bar companion Bailiff (no longer supported).

At that time, eviction replaced the local file with a hidden stub file containing a reference to the complete copy held in iCloud Drive. Any attempt to open the local file then resulted in the download of the file’s data, a process now known as materialisation.

Sonoma changed this for a new system based on a FileProvider mechanism, as used by third-party cloud services. This operates in either of two modes:

  • replicating, with Optimise Mac Storage turned off, where local and remote iCloud Drive folders and files should remain identical, and eviction isn’t allowed;
  • non-replicating, with Optimise Mac Storage turned on, where local files can be evicted and rendered dataless, and only iCloud Drive holds all the files complete with their data.

The most critical phase is the transition between those two modes, when the Optimise Mac Storage setting is changed.

Turn Optimise Mac Storage on

After a few seconds, the control turns itself off again, and needs to be turned on a second time for the new setting to stick. It’s unclear why that should occur, or whether it affects what happens. There should be no immediate effect on file storage, as in the previous state local and remote files should have formed a perfect mirror, and none could have been evicted.

Changing the setting is first reported by bird, which then triggers FileProvider to iterate through all items in iCloud Drive setting them to be evictable, with a great many log entries of the form
✍️ FS snapshot mutation: update<s:fileID(674133) […] diffs:evictable why:item changed
✍️ persist job: <J2 ⏳ update-item(propagated:[…] diffs:evictable) why:itemChangedRemotely sched:background#1709468042.083435 ⧗persisted>
┳15d1e ✅ done executing <J2 ✅ update-item(propagated:[…] diffs:evictable) why:itemChangedRemotely […] [duration 106ms634µs]

and covering both local and remote (FP and FS) directory trees.

There’s additional housekeeping to be performed on local property lists for the different domains, which include a separate domain for shared Photos libraries, as revealed in log entries such as
[NOTICE] ┏158b5 writing domain properties for com.apple.CloudDocs.MobileDocumentsFileProvider onto […]
[NOTICE] ┏158d0 writing domain properties for com.apple.Photos.PhotosFileProvider onto […]
[NOTICE] ┏158da writing domain properties for com.apple.CloudDocs.iCloudDriveFileProvider onto […]
[NOTICE] ┏158de Updating list of extensions
[NOTICE] ┏158df Listing domains & providers in <AppSupport>/FileProvider
[NOTICE] ┏158e0 Listing domains & providers in […]

Early snapshot mutations are followed by container patching, such as
Patching container <FPFSItem 0x15002a560:__fp/fs/fileID(691051) (replacing:a52) l:"S{7}s" container bid:com.apple.shortcuts […]> with <FPFSItem […] ul:uploaded dl:current rec-dl:yes>

As there are no files to be materialised, the process of change is determined by the number of items in iCloud Drive, and shouldn’t normally require any syncing of file data. That said, in early versions of Sonoma, and macOS that had only been recently upgraded, some users have reported long syncing as a result. When it works properly, turning Optimise Mac Storage on should be an administrative task for FileProvider, and accomplished quickly.

Turn Optimise Mac Storage off

The control behaves similarly, turning itself back on after a few seconds, and has to be returned to off a second time. This has a similar effect on FileProvider, which iterates through the entire contents of iCloud Drive changing the evictable property of all folders and files. However, this also requires the materialisation (download) of all files and folders that are currently evicted.

One distinctive log entry announces the background download:
[NOTICE] ⏱ com.apple.fileproviderd.background-download: new watcher registered for c{60})
following which FileProvider iterates through all items inn iCloud Drive removing the evictable property, in entries such as
✍️ FS snapshot mutation: update<s:fileID(690953) […] diffs:evictable why:item changed
✍️ persist job: <J1 ⏳ update-item(propagated:[…] diffs:evictable) why:itemChangedRemotely sched:background#1709453882.838437 ⧗persisted>
┳1021 ✅ done executing <J1 ✅ update-item(propagated:[…] diffs:evictable) why:itemChangedRemotely […] [duration 8ms30µs]

icdOMSoff1

This early torrent of log entries is accompanied by the download and materialisation of all evicted items, which can take a long time. You should see a progress window reporting the amount of downloaded data. Thus the time required to complete this sync is largely determined by both the number of items stored in iCloud Drive and the total amount of data that must be downloaded to materialise all evicted files. Some early adopters reported an initial sync of the entire contents of their iCloud Drive, but that isn’t required and shouldn’t happen now.

icdOMSoff2

Storage debt

The only real danger of running with Optimise Mac Storage turned on is that the total space occupied by data from evicted files can come to exceed the total free space on that Mac. In that case, turning it off again won’t work, as there’s insufficient local free space to accommodate all the materialised files.

For instance, if the total original size of the files that are now evicted is 1 TB, but that Mac has only 100 GB free on its internal SSD, then there isn’t sufficient room to turn Optimise Mac Storage off again. In the short term, many of those files must remain stored in iCloud Drive, and only some of them could be downloaded into local storage. That in turn has the disadvantage that those evicted files are no longer available for backup or Spotlight search.

There doesn’t appear to be any simple way to determine whether your Mac has entered storage debt. If you use Get Info on the iCloud Drive location, the total size reported may represent that currently in use by locally stored files. Comparing that with the size given for the Documents category in the bar chart at the top of iCloud settings may give an idea of the total that would be required if all evicted files were to be downloaded, but it’s not clear how accurate that would be in practice.

Summary

  • When Optimise Mac Storage is on, that sets iCloud Drive into non-replicated mode, allowing both the user and macOS to evict files and folders from local storage.
  • When Optimise Mac Storage is off, iCloud Drive runs in replicated mode, no eviction is possible, but local and remote files are synced to remain identical.
  • Turning Optimise Mac Storage on requires settings on every file in iCloud Drive to be changed, and the time required is proportional to the total number of files in iCloud Drive. Provided that you have already upgraded iCloud Drive to Sonoma, this shouldn’t require any downloads or uploads, and should complete relatively quickly.
  • Turning Optimise Mac Storage off not only requires settings on every file in iCloud Drive to be changed, but also requires the download of all evicted files to local storage. It will thus take significantly longer, and the greater the total size of evicted files, the longer it will take. In some cases, that could be many hours, even if you have already upgraded iCloud Drive to Sonoma.
  • Storage debt can occur when Optimise Mac Storage is turned on, if the total size of evicted files exceeds free space on your Mac. If that’s the case, then you won’t be able to turn it off, and will have to keep some files evicted, where they can’t be backed up locally or searched by Spotlight.
  • As it doesn’t appear easy to get an accurate estimate for the total size that would be required to accommodate the download of all evicted files, it’s not easy to know whether your Mac has entered storage debt.