Speed up spinning drives

I use spinning drives for backup and was frustrated by their slow speeds on a modern Mac Mini even with a USB 3.1 dock - no faster than my old USB 2.0 dock!

I searched for a long time. Eventually, I found that while HFS+ Encrypted drives are deprecated and risky for Golden Gate and beyond, which is why I moved to APFS, they are also faster than APFS. Then I looked for the reason.

Apparently APFS scatters files into segments all across the drive, which is fine for an SSD but lousy for spinning rust. By default APFS, even spinning rust drives, does not have defragmentation enabled, so files explode into numerous parts.

You can manually set up defragmentation on APFS drives, though, so when files are touched or copied, they are made whole again, so stuff happens WAY faster. It’s all about seek time. For an SSD, there’s practically none; for a hard drive, the drive has to spin around and the heads have to move in and out.

Example: diskutil apfs defrag disk8s1 enable

(use diskutil list to figure out which disk you need)

3 Likes

APFS’s performance problems on HDDs is nothing new. People were talking about it back when it was first intrdouced in macOS 10.13 (“High Sierra”).

But I’m surprised you find it no faster than a USB 2.0 drive. That sounds like the drive itself isn’t very fast. I have three external HDDs (Toshiba N300 and N300 Pro) mounted in USB 3 enclosures. They’re significantly slower than SSDs, but much faster than my older drives that have USB 2.0 and FW400 enclosures.

If you’re using portable/laptop drives, they frequently use low-performance drives in their enclosures, spinning at 5400 RPM or less, and often use SMR to boost capacity. Both of which are performance killers on any interface.

Good information about the defrag option. I didn’t know it existed. I wonder if it was always there or was recently added.

1 Like

I believe the consensus is that “defrag” of an APFS HDD has very little if any benefit. See, for example, Should you enable defragmentation on APFS hard drives? – The Eclectic Light Company and An analysis of APFS enumeration performance on rotational hard drives - Bombich Software

The problem with APFS HDDs is not so much file fragmentation, rather it is file system metadata which gets scattered all over the disk. In part this is because of the copy-on-write method (rather than journaling) used to ensure file system integrity.

So the serious seek time bottleneck involves getting file system metadata. File data fragmentation is important, but less so.

Do you have a reference describing what the APFS defrag actually does? In particular does it defrag the file system metadata? To the best of my knowledge, Apple has been silent on this!

Sorry to be so negative about this.

2 Likes

I believe with Mojave. APFS itself was introduced with High Sierra.

I don’t know about the technical details. I was having 30-40 MB/s readings from Carbon Copy Cloner on five different drives in three different docks. I ran the command to put on defragmentation and suddenly the readings were 90-100 MB/s regardless of dock and drive.

In each case it’s encrypted APFS, encrypted because they are full backups, APFS because HFS+ encrypted is deprecated. I’ve had to move stuff around because Golden Gate does not like drives I formatted years ago; my Mojave machine has no problem with them, Golden Gate won’t even mount a couple of the volumes (but Carbon Copy Cloner would and did). Apple’s made it clear they don’t like spinning rust, I think.

I would suggest someone else volunteer to be a guinea pig and try it out. These drives are all pretty well used for backup, which does affect their speed, but having backup 2-3 times as fast is very nice especially when I was consolidating older, archived backups.

Thanks for the stats. Now it makes more sense. Still faster than USB 2, but you’re right that it’s pretty slow.

Doing a web search on this feature, I see that @mjtsai blogged about this back in 2019, sharing a link to an article by Howard Oakley and a 2023 follow-up via a Mastadon post that seems to track with your experience.

I may have to try it myself…

Ironically, that 2019 entry is what led me to do it. It’s really hard to find information on this, and then I couldn’t find my sources after trying it, or I’d have credited them. Thanks for digging that out so I can belatedly say “that’s the source.”

It’s kinda bizarre. I also don’t see much difference between drives, but since I’m mostly (right now) just moving stuff from one spinner to another, that makes sense. When I do my next regular backup, maybe I’ll see higher speeds - like the speeds I saw years ago, before Apple started playing these games.

I guess I should write to Bombich Software about making the command visible and/or default in Carbon Copy Cloner’s volume interface.

USB 2 isn’t all that slow by backup standards ;) I still remember being in wonder about the speeds of tape. I used to back up to floppies - over 100 of them. Tape was great for a while by comparison.

Tape used to be faster for sequential I/O than disk drives. It was the random access that was slow.

The two articles I quoted before are both rather old (2019) and things may have changed since then. But Bombich did some systematic testing and concluded “I found no significant difference in enumeration performance when defragmentation was enabled”.

His other paragraph says: “Apple quietly added a defragmentation feature to APFS in macOS Mojave. APFS defragmentation is disabled by default, and only lightly documented in the diskutil man page. Apple gives no indication of what this defragmentation feature actually does, in particular whether it defragments filesystem structures. Based on the results of the tests above, however, I would conclude that APFS defragmentation does not cause filesystem metadata to be physically clumped together on the disk.”

His report is the only one I have found with systematic testing.

I have enabled defrag on the container and volumes I am using for CCC. I will attempt to see if there is any significant change in performance.

FWIW, my CCC logs show:

  • My slower backup device (Toshiba N300, USB3 enclosure), took 31:32 to copy 18.86 GB, or about 10MB/s
  • My faster backup device (Toshiba N300 Pro, USB3 enclosure), took 19:08 to copy 18.13 GB, or about 16 GB/s.

Note that this isn’t just data-transfer times. It also includes all the time spent evaluating files to determine what needs to be backed up, since I don’t make backups often enough for it to use the FSEvents API to avoid the need to evaluate all of my files (about 1.1 TB) every time.

Tape? Yep. I used it and loved it before it became too expensive. I used a FireWire VXA-1 drive (33 GB uncompressed per tape). But when my data got larger than two tapes worth, it became too unwieldy to use on a regular basis. And higher capacity drives were just too expensive for personal use. Which is when I switched to hard drives

(Before the VXA drive, I had also used Travan TR-4, DAT DDS-2, 8mm Data8 and even QIC-24/DC-600 for my backups.)

I’d love to go back to tape, but the only tech that can hold a modern size backup is LTO. LTO-6 can hold 2.5 TB (uncompressed) on a tape. But LTO-6 is no longer available. Today, the smallest LTO drive I can find is LTO-7 (6 TB uncompressed) and a Thunderbolt-connected drive costs $6000. My budget isn’t even close to big enough to afford that.

2 Likes

Agreed. A common misconception is that tape is slow. Tape is very, very fast for sequential access as you note. In a lot of cases, faster than disks. That’s what makes them good for backups - as long as you can keep feeding them fast enough with data to take advantage of their speed.

Reminds me of an old saying when using tape in disaster recovery vs “the cloud” updated for today’s technology: never underestimate the bandwidth of a van full of tapes traveling at or above the speed limit.

2 Likes