
Global Kernel Locks in APFS - indygreg2
https://gregoryszorc.com/blog/2018/10/29/global-kernel-locks-in-apfs/
======
kiwijamo
I wonder if this is why recent versions of macOS performs so poorly on old
HDD-based MacBooks. The difference between my work's 2012 MacBook (HDD) and my
personal 2015 (SSD) MacBook is like night and day. Most apps open in a second
on my SSD MacBook yet take up to a minute to open on my employer's HDD
MacBook. It's not just this MacBook, I also see the same on a work iMac as
well. Such a shame as these older machines previously didn't run so slowly.

~~~
bradknowles
Replacing an HDD with an SSD really is a night-and-day kind of difference for
any laptop I've ever seen, regardless of the OS or filesystem.

IMO, that's likely to be a much bigger factor than the filesystem.

~~~
awiesenhofer
Unfortunately not the biggest one though. I too have a old 2012 macbook pro
with hdd. While it was flying under snow leopard it now grinds to a halt every
time i open any app or document. Already ordered an ssd but still dreaming of
downgrading it back to snow leopard.

~~~
tssva
Microsoft Windows used to be notorious for slowing down over time. A fresh OS
install would restore performance. Many would recommend doing a fresh Windows
install yearly to maintain performance.

I have a late 2012 MacBook Pro Retina with a SSD and unfortunately notice the
same decreased performance over time with macOS. A fresh OS install breaths
new life into the machine.

When you get your SSD do a fresh OS install instead of restoring the complete
HD to the SSD.

~~~
trevyn
Or just clean out your random LoginItems and kexts and whatever now and then.
Check Activity Monitor and uninstall anything running that you don’t need.

------
chmaynard
The author worked very hard to determine the root cause of the problem but he
was stymied because the APFS source code is not available. Why not? Apple has
open-sourced the Swift compiler with great success, but there seems to be no
movement within Apple to open up other system software components.

~~~
mikhailt
They do plan to document it fully later:

> Is APFS open source?

> An open source implementation is not available at this time. Apple plans to
> document and publish the APFS volume format specification.

Source:
[https://developer.apple.com/library/archive/documentation/Fi...](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/APFS_Guide/FAQ/FAQ.html)

My theory is that Apple rushed APFS and its implementation isn't in a great
shape for the public review. APFS doesn't feel any faster on my SSDs on macOS.
I suspect they'll add it in a few years, after a few iterations.

~~~
MBCook
What makes you think it’s a rush job?

Perhaps it’s just the lawyer reviews holding it up.

~~~
mrpippy
My personal guess is that they wanted to release the printed spec before they
released the code. The spec has now been released, the 10.14 source has not,
maybe apfs.kext will be in the 10.14 source drop.

(also, HFS+ and its fsck have always been open-source with OS X)

~~~
pfranz
HFS+ was first released for Mac OS 8.1 in 1998. The earliest source code I see
is from Mac OS X 10.0, which was released in March of 2001 (not sure when the
source was released). The first iPod was released in October of 2001 which
used HFS+. I imagine by the time that code was released it had been battle
hardened quite a bit.

------
twotwotwo
I'm too late to the thread, but wonder if locking might have to do with
updating access times on the dirs on read--that would help justify a read-only
workload taking some sort of exclusive lock. The "fix" there would be
something like relatime to get atimes set infrequently.

There're def a ton of other possibilities. Some locking could be overbroad,
like an exclusive lock where a reader lock would be enough. I don't see super-
strong evidence that any locks involved are actually _global_ , just that
they're under contention here. And I can understand shipping a product with
somewhat excessive locking because perf issues with specific workloads are a
better problem to have with your shiny new FS rollout than data loss.

Anyway it's mostly shooting in the dark for us here (though cool some folks
disassembled the functions), but there are some shots in the dark that look
different from what I could find in the comments already here :)

------
lelf
Absolutely _nothing_ there indicates the presence of global kernel locks.
_readdir_ (obviously!!!) needs to hold a lock, it’s not global, it’s per-DIR.

------
georgn
As someone who used to work on BitKeeper, I'm tickled to see a more popular
SCM's test suite as a kind of de facto filesystem benchmark -- confirming what
we had been observing ourselves forever.

