Wednesday, April 3, 2024

Seven Years of APFS

Howard Oakley:

Although APFS has certainly had its moments over the last seven years, Apple’s gambles have paid off, and proved key to the success of Apple silicon Macs. Had there been no APFS, many of the fundamental technologies like Secure Boot and the Signed System Volume (SSV) would have been far tougher if not impossible to implement.

[…]

What has attracted almost no attention, though, is how APFS is designed to prolong the working life of SSDs by minimising the number of write/erase cycles. Although the user may be unable to realise the space efficiency achieved with the use of sparse and clone files, for instance, by reducing the number of storage blocks actually written in order to store files, with APFS each write/erase cycle should store unique data rather than needless copies or null data.

This is of little or no comfort to those condemned to use hard disks for storage, even if only for Time Machine backups. Although the great majority of APFS users’ devices will never be connected to a hard disk, for the small minority running it in macOS, they remain the medium of choice for backups and other bulk storage, and vulnerable to performance degradation resulting from fragmentation by the file system.

[…]

Although Apple dropped early hints that APFS might be released as open source, after seven years information about its internals released by Apple still appears to be insufficient to allow third-party developers to create maintenance tools independent of those bundled in macOS. This isn’t just about the potential for someone outside Apple to improve on the performance of fsck or Disk Utility, but also concerns features that Apple shows no sign of supporting.

For me, the biggest issues are:

Previously:

11 Comments RSS · Twitter · Mastodon

Another big issue is the terrible UX of Disk Utility which makes it unintuitive to partition an external APFSl drive:

Disk Utility can make you believe that you are following exactly the right steps to create partitions and then it fails miserably with incorrect error messaging and no suggestions when trying to apply the changes.

Is there a better choice for HDD? On recent versions of macOS, APFS is the only option if you need an encrypted partition. Give up on encryption and go with MacOS Extended?

Is the problem of drives that don't mount (or take hours to do so) really an APFS problem? My external hard drive is HFS Plus, and it often requires manual intervention to mount, sometimes takes forever to do so, and noticeably slows IO to my APFS internal drive while that drive is busy.

@Matthew I’m not sure. It seems to have started somewhat after APFS was introduced, but it doesn’t seem to affect my HFS+ drives, though I don’t have many of those left.

> APFS is designed to prolong the working life of SSDs by minimising the number of write/erase cycles

A shame that this benefit is mitigated on most Macs since the default SKUs ship with so little RAM that swapping is a common occurrence.

improbability

@Michael,

I gave up on portable HDDs awhile ago, because basically all of them have fallen to the SMR plague over the past decade or so. I think these disks are basically unfit for purpose without regular reformats; regardless of filesystem, rewriting disk blocks causes performance to eventually degrade to horrible. Could it be this you're hitting? Apple being Apple, they don't optimize their software for this kind of third-party jank, so macOS can behave really poorly when a disk is regularly freezing all I/O for some arbitrary long time to do garbage collection.

Lots of desktop-class drives have gone SMR too, so it pays to do your homework before buying any spinning storage these days. If you must use an SMR drive, reformat it using the vendor disk tool whenever performance goes south (though I've seen a couple drive models smart enough to reset to a clean state if you just erase and repartition in Disk Utility.)

It's pretty dumb, and honestly even dumber that this isn't talked about more, but that's where storage is at now. These disks are OK for archiving, but terrible for long-term incremental backups or pretty much anything that isn't a write-once-rarely-modify kind of usage. I pity anyone stuck using one of these as a boot drive.

https://en.wikipedia.org/wiki/Shingled_magnetic_recording

@improbability Thanks for that. I was not aware of SMR. That could be part of the problem, although I have also seen slow reads and performance on the same drive that get worse after switching it to APFS.

I still default to HFS+ anytime I can, unless I have a specific need for APFS or I'm forced to use it.

improbability

@Michael interesting. AFAIK, Apple is sticking to its story that APFS is for storage of the future with super cheap seeks, and I doubt they’ve done much more than bandaid things for spinning disks. Maybe the cost of SMR makes that a lot more obvious? A freshly-formatted SMR disk always felt to me like a blazing fast Time Machine target (mere hours for a >1TB backup) compared to the same disk awhile later (sometimes as bad as a full day to do an incremental backup if I let things deteriorate beyond all reason, especially on HFS+.)

APFS actually felt slightly better in the long run than HFS+ to me, but I never measured it in a rigorous way. I do know HFS+ Time Machine performance was embarrassingly bad churning through changes in very large directories (Slack, caches, email, calendars, etc.), because of the way directory hardlinks work. APFS is much, much, much faster here, though I’m sure slower elsewhere.

@Michael Anecdotally, enabling APFS defragmentation helped restore performance for an external HDD of mine that, after converting it to APFS, had deteriorated to a point (2-5 MB/s) where I was wondering if it needed replacement.

That was last August ( https://mjtsai.com/blog/2019/10/28/enabling-defragmentation-on-apfs-hard-drives/ ) and performance has remained consistently good since.

@Felix At that time, I found that APFS defragmentation was already enabled for my drives, so it unfortunately didn’t make the difference for me.

Leave a Comment