Monday, October 28, 2019

Enabling Defragmentation on APFS Hard Drives

Howard Oakley:

You can try this yourself, although the documentation of defragmentation is minimal. The diskutil apfs command allows you to enable and disable defragmentation at Container or Volume level, with a command such as diskutil apfs defragment volumeDevice enable enabling it on the specified volume. But I wouldn’t expect it to have any significant impact on the poor performance that you’re experiencing on APFS-formatted hard drives. I hate to say it, but if you possibly can, it would make good sense to keep those in HFS+ format until you replace them with SSDs.

Previously:

Update (2023-08-31): Felix Schwarz:

Three days ago, I noticed an external HDD’s write performance had deteriorated to about 2-5 MB/s, making me wonder if it was about to fail - or if it is an APFS performance issue.

I subsequently learned about APFS defragmentation and enabled it for the HDD’s APFS container via

diskutil apfs defragment [disk] enable

Coming back to the disk two days later, write performance is back to normal.

5 Comments RSS · Twitter

See, @Howard and I are on the same page! I do not see a true advantage to switching spinning platters over to APFS. Lot of downsides to making that switch.

To reiterate, SSDs? No brainer.

Got to go with the flow there. The file system seems specifically designed with SSD characteristics in mind. Coupled to better volume management and likely better data safety, no problem with APFS on SSD.

Sören Nils Kuklau

So Apple doesn't actually use the defragmentation feature? Did they ship it knowing that it wasn't really helping, but also not hurting (and have dropped the effort for being a useless design?)? Are they working on improving it?

Stay tuned for some or none of these answers by 10.19 Death Valley.

Sören Nils Kuklau

Got to go with the flow there. The file system seems specifically designed with SSD characteristics in mind. Coupled to better volume management and likely better data safety, no problem with APFS on SSD.

Definitely.

(Though it seems even on SSDs, APFS isn’t quite as fast as HFS+. Maybe they’ll tweak that over time?)

But they have to come up with a backup story at some point, even if it is “you know what, just use btrfs on an HDD”. (That’s what I do with Synology and Time Machine. Seems fine?)

Is there any way to explicitly run a full defrag?

I'm trying to lower the high watermark on some APFS-formatted sparsebundles, hoping I could then `hdiutil compact` them

Leave a Comment