Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Gnattu

macrumors 65816
Sep 18, 2020
1,107
1,671
I don’t think this correct given what I’ve read. The issue is that F_FULLSYNC is slow and the reason that slowness doesn’t affect macOS is that macOS doesn’t do F_FULLSYNC on fsync where Linux does. Not doing full sync doesn’t seem like it is just on internal drives but a policy of macOS itself.
Oh, I mixed up two problems.

1. macOS(or the XNU Kernel)'s fsync() does not flush cache

2. F_FULLSYNC is slow on Apple's nvme controller

Obviously second one only affects internal drive if the software uses F_FULLSYNC.
 
  • Like
Reactions: crazy dave

jdb8167

macrumors 601
Nov 17, 2008
4,859
4,599
Oh, I mixed up two problems.

1. macOS(or the XNU Kernel)'s fsync() does not flush cache

2. F_FULLSYNC is slow on Apple's nvme controller

Obviously second one only affects internal drive if the software uses F_FULLSYNC.
So if iPadOS Files isn’t issuing the full flush command and is only doing fsync calls then it is entirely possible that this is what is causing corruption problems on external media. Though if the drive is ignoring the flush command anyway, it isn’t clear what Apple can do to fix the problem. But since there are reports that the corruption doesn’t happen with File Browser Pro, there must be a fix.
 

leman

macrumors Core
Oct 14, 2008
19,521
19,678
Because portable POSIX applications would assume fsync() does what F_FULLSYNC does.

Except POSIX makes no such guarantee. In fact, relying on POSIX doing the right thing for these kind of low-level implementation details is incredibly naive, more naive even than using C++ standard library and expecting good performance. If you develop stuff for macOS or FreeBSD and need to flush to physical storage, you have to use F_FULLSYNC — this is how it always has been.

1. macOS(or the XNU Kernel)'s fsync() does not flush cache

It does flush cache — the filesystem/kernel cache. It does not necessarily ensure that the data 100% lands on the physical storage. It's just like a regular POSIX fsync().
 

Gnattu

macrumors 65816
Sep 18, 2020
1,107
1,671
it is entirely possible that this is what is causing corruption problems on external media
And this would (almost?) only happen when you unplug that external media ungracefully, although this could be quite usual. But if you are doing this you will be at a very high risk to lose your data on any computer, because the OS may not even have the chance to issue the (correct) flush command before the drive is disconnected.
 

jdb8167

macrumors 601
Nov 17, 2008
4,859
4,599
And this would (almost?) only happen when you unplug that external media ungracefully, although this could be quite usual. But if you are doing this you will be at a very high risk to lose your data on any computer, because the OS may not even have the chance to issue the (correct) flush command before the drive is disconnected.
iPadOS Files app doesn’t have an eject command.
 

Gnattu

macrumors 65816
Sep 18, 2020
1,107
1,671
iPadOS Files app doesn’t have an eject command.
Now we have a problem. When I was using that, I waited until the drive's led stops flashing. But not all drives have an activity led so there is no way to tell when it is "safe" to unplug the drive, could be annoying if the data is important.
 

leman

macrumors Core
Oct 14, 2008
19,521
19,678
P.S. I got very curious about all this and I have dogged a bit more. If I understand it correctly now, Linux fsync() invokes the NVME flush operation (which is a low level guaranteed flush command) while Apple does not. That is probably what Hector means by saying that Linux does full flush by default. If that’s the case then I understand the problem better I think.
 
  • Like
Reactions: jdb8167

Danfango

macrumors 65816
Jan 4, 2022
1,294
5,779
London, UK
It appears that no one understands file systems or devices here.

fsync is not a guarantee the device is consistent. It’s only a guarantee that the device has been told it needs to be consistent. What happens inside the device is undefined. There is no guarantee a flush will do what you ask. This is why it’s pushed up a level to the filesystem.

Journaling file systems only guarantee consistency at one point in time not at the point of an fsync. Usually it’s before the point in time the fsync took place. Even if the device was issued fsync it doesn’t mean that the consistency point is then at all. The only way to get fully consistent systems is to do writes to two nodes and do a two phase commit. This is obviously not practical.

What we have is a complete best effort system.

As for data loss this means virtually nothing for the modern OS with low file system transaction churn and cloud sync’ed files.

This is completely blown out of proportion.
 
Last edited:

Wildkraut

Suspended
Nov 8, 2015
3,583
7,675
Germany
Maybe they just sold contaminated crap?! And the slowness “Bug” is a workaround?!


Western Digital is an Apple supplier. Kioxia NAND chips are used in many Apple products, including the iPhone 13 family, the 14- and 16-inch MacBook Pro, and iPad Pro.
 
Last edited:
  • Haha
Reactions: jdb8167

MauiPa

macrumors 68040
Apr 18, 2018
3,438
5,084
Hector Martin works on Asahi Linux for AppleSilicon Macs:

"Well, this is unfortunate. It turns out Apple's custom NVMe drives are amazingly fast - if you don't care about data integrity. If you do, they drop down to HDD performance. Thread."

"For a while, we've noticed that random write performance with fsync (data integrity) on Asahi Linux (and also on Linux on T2 Macs) was terrible. As in 46 IOPS terrible. That's slower than many modern HDDs. We thought we were missing something, since this didn't happen on macOS."

There is more:

more privacy friendly link:
Doesn’t that sound like a problem in Asahi Linux? Pretty clear to me, if you provided evidence this is a universal problem (not, oh, it’s not, macOS works fine so definitely asahi linux)
 

MauiPa

macrumors 68040
Apr 18, 2018
3,438
5,084
Maybe they just sold contaminated crap?! And the slowness “Bug” is a workaround?!


Western Digital is an Apple supplier. Kioxia NAND chips are used in many Apple products, including the iPhone 13 family, the 14- and 16-inch MacBook Pro, and iPad Pro.
That was pretty much all pulled before it entered market. Pretty clear problem is in asahi linux
 

MauiPa

macrumors 68040
Apr 18, 2018
3,438
5,084
I think we are saying the same thing. On Linux, apparently the only API to flush to the physical media is fsync which as you note with modern consumer SSDs and HDs isn’t guaranteed. Apple, apparently acknowledging that consumer hardware cheats, provides a non-standard non-POSIX API. Basically even though on Apple silicon hardware, F_FULLSYNC is slow, it is still more correct than the Linux solution for many users of consumer hardware as long as the macOS software is written correctly.
My point exactly. Fix linux
 
  • Haha
Reactions: sinoka56

jdb8167

macrumors 601
Nov 17, 2008
4,859
4,599
My point exactly. Fix linux
Well it really does look like a firmware problem but one that isn’t too consequential for macOS. Some unusual software might be slow but correctly written macOS software should be fine. This isn’t a functional bug but a performance problem for unusual work loads (unusual on the Mac).
 

JimmyjamesEU

Suspended
Jun 28, 2018
397
426
This is all curious. I have no reason to disagree with Hector and at the same time I spoke to a couple of people who have been or are at Apple (via Twitter). Both are familiar with macOS filesystem and firmware and have been briefed by Dominic Giampaolo, and both are adamant that unless you know the firmware honours write requests, you don't know! That is to say, never trust them. They treat third party drives as adversaries.

In any case, just in case some haven't seen it, it's worth checking out

for a good summary.

And:


They work at Apple and are very well versed with drive firmware and file systems.
 
  • Like
Reactions: jdb8167

crazy dave

macrumors 65816
Sep 9, 2010
1,453
1,229
Doesn’t that sound like a problem in Asahi Linux? Pretty clear to me, if you provided evidence this is a universal problem (not, oh, it’s not, macOS works fine so definitely asahi linux)

Not really. The issue seems to be a firmware performance bug that causes the SSD to be slow on flushes - basically writes from the SSD caches to the SSD - much slower than it should be by an order of magnitude. This happens on macOS and Linux and is likely the firmware. A performance bug in the firmware can be anything from performing an unnecessary action during a flush or performing a necessary action using the worst possible algorithm and thus unnecessarily slowly.

The other issue is more ... a design difference between macOS and Linux where Hector prefers the Linux version. On Linux, they use a flush during fsync (standard file system syncing) and they assume the flush command during fsync will be honored and, in practice, for direct-attached NVMe drives, it (often? always?) is. However, that flush doesn't *have* to be honored by an SSD controller. So Apple decided then to make an fsync that basically never flushes and provides a separate command that forces flushes to happen at specific times. Again, unfortunately this flush seems to be unusually slow, and is, again almost certainly a firmware bug as Hector can see no reason that a flush should be so slow.
 
  • Like
Reactions: jdb8167

crazy dave

macrumors 65816
Sep 9, 2010
1,453
1,229
This is all curious. I have no reason to disagree with Hector and at the same time I spoke to a couple of people who have been or are at Apple (via Twitter). Both are familiar with macOS filesystem and firmware and have been briefed by Dominic Giampaolo, and both are adamant that unless you know the firmware honours write requests, you don't know! That is to say, never trust them. They treat third party drives as adversaries.

In any case, just in case some haven't seen it, it's worth checking out

for a good summary.

And:


They work at Apple and are very well versed with drive firmware and file systems.

I was wondering if that was you :)
 
  • Like
Reactions: JimmyjamesEU

Slartibart

macrumors 68040
Aug 19, 2020
3,144
2,819
Now we have a problem. When I was using that, I waited until the drive's led stops flashing. But not all drives have an activity led so there is no way to tell when it is "safe" to unplug the drive, could be annoying if the data is important.
I remember that the developers of FileBrowser said they try to check this. In general FileBrowser reduces file corruption, file system inconsistency after unplugging is still a thing on iPadOS.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.