7 ms·
Yes. fsync() on Linux pushes down to stable storage, not just drive cache. OpenBSD, though, apparently behaves like macOS. I'm not sure I like that.
by marcan_42 5y ago
Yes. fsync() on Linux pushes down to stable storage, not just drive cache.
OpenBSD, though, apparently behaves like macOS. I'm not sure I like that.
- supermatt 5y agoSo its basically implementation specific, and macOS has its own way of handling it. That doesnt make it worse - in fact it permits the flexibility you are now struggling with. edit: downvotes for truth? nice. go read the posix spec then come back and remove your downvotes...
- marcan_42 5y agoWhat is worse is their NVMe controller having 50x worse flush performance than the competition.
- supermatt 5y agoThe competitions controller may be ignoring the F_FULLFSYNC. This is a known issue which is why apple have approved vendors for mac pro drives.
- marcan_42 5y agoIt isn't, because otherwise it would be showing the ~same performance with and without sync commands, as I showed in the thread. There is a significant performance loss for every drive, but Apple's is way worse. There is no real excuse for a single sector write to take ~20ms to flush to NAND, all the while the NAND controller is generating some 10MB/s of DRAM traffic. This is a dumb firmware design issue.
- supermatt 5y agoIt may be interpreting it differently. You arent comparing apples to apples, quite literally. Why not compare macOS and linux on approved x86 mac hardware. i.e. fusion drive or whatever. Also, as suggested - try F_BARRIERFSYNC, which flushes anything before the barrier (used for WAL IIRC).
- throwawaylinux 5y agoIt seems to be pretty apples to apples, they're running the same benchmark using equivalent data storage APIs on both systems. What are you thinking might be different? The Linux+WD drive isn't making the data durable? Or that OSX does something stupid which could be the cause of the slowdown rather than the drive? Both seem implausible.
- marcan_42 5y agoThis affects T2 Macs too, which use the same NVMe controller design as M1 Macs. We've looked at NVMe command traces from running macOS under a transparent hypervisor. We've issued NVMe commands outside of Linux from a bare-metal environment. The 20ms flush penalty is there for Apple's NVMe implementation. It's not some OS thing. And other drives don't have it. And I checked and Apple's NVMe controller is doing 10MB/s of DRAM memory traffic when issued flushes, for some reason (yes, we can get those stats). And we know macOS does not properly flush with just fsync() because it actively loses data on hard shutdowns. We've been fighting this issue for a while now, it's just that it only just hit us yesterday/today that there is no magic in macOS - it just doesn't flush, and doesn't guarantee data persistence, on fsync().
- supermatt 5y agoIve just been scanning through linux kernel code (inc ext4). Are you sure that its not issuing a PREFLUSH? What are your barrier options on the mount? I think you will find these are going to be more like F_BARRIERFSYNC. I couldnt find much info about it - but the official docs are here: https://kernel.org/doc/html/v5.17-rc3/block/writeback_cache_control.html https://kernel.org/doc/html/v5.17-rc3/block/writeback_cache_...
- marcan_42 5y agoThose are Linux concepts. What you're looking for is the actual NVMe commands. There's two things: FLUSH (which flushes the whole cache), and a WRITE with the FUA bit set (which basically turns that write into write-through, but does not guarantee anything about other commands). The latter isn't very useful for most cases, since you usually want at least barrier semantics if not a full flush for previously completed writes. And that leaves you with FLUSH. Which is the one that takes 20ms on these drives.
- dathinab 5y agoProbably more like downvoted because missing the point. Sure fsync allows that behavior, but also it's so widely misunderstood that a lot of programs which should do a "full" flush only do a fsync, including Benchmarks. In which case they are not comparable and doing so is cheating. But that's not the point! The point is that with the M1 Macs SSDs the performance with fully flushing to disk is abysmal bad. And as such any application with cares for data integrity and does a full flush can expect noticable performance degradation. The fact that Apple neither forces frequent full syncs or at least full syncs when a Application is closed doesn't make it better. Though it is also not surprising as it's not the first time Apple set things up under the assumption their hardware is unfailable. And maybe for a desktop focused high end designs where most devices sold are battery powered that is a reasonable design choice.
- ClumsyPilot 5y ago"And maybe for a desktop focused high end designs where most devices sold are battery powered that is a reasonable design choice" Does the battery last forever? Do they never shut down from overheating, shut down from being too cold, freeze up, they are water and coffee proof? Talk to anyone that repairs mac about how high-end and reliable their designs trully are - they are better than bottomn of the barrel craptops, sure, but not particularly amazing and have some astounding design flaws.
- BenjiWiebe 5y agoHow cold is too cold for a computer?
- michaelmrose 5y agoThe CPU can't possibly get too cold. See for example overclocking performed by cooling the CPU with liquid nitrogen. Condensation is a factor as is lost of ductility of plastic at low temp making it brittle. Expansion and contraction of materials especially when different materials expand to different degrees.
- rsync 5y agoI downvoted you because you complained about your downvotes.
- supermatt 5y agoHow did that work out for you?
- shellac 5y ago*BSDs mostly followed this semantic, as I recall. Probably inherited from a common ancestor.
- mrjin 5y agoMacOS was really just FreeBSD with a fancier UI. Not sure what is the behavior now, but I'm pretty sure FreeBSD behaved almost exactly the same as a power loss rendered my system unbootable over 10 years ago.
- xoa 5y ago>MacOS was really just FreeBSD with a fancier UI. I'm sorry but this is incorrect. NeXTSTEP was the primary foundation for Mac OS X, and the XNU kernel was derived from Mach and IIRC 4.4BSD. FreeBSD source was certainly an important sync jumping off point for a number of Unix components of the kernel and CLI userland, there was some code sharing going on for a while (still?), but large components of the kernel and core frameworks were unique (for better or worse).
- masklinn 5y ago> and IIRC 4.4BSD 4.3, only Rhapsody incorporated elements from 4.4, but that was the tail end of nextstep, essentially the initial preview of macos (it was released as osx server 1.0, then forked to darwin from which the actual OSX 10.0 would be built, two major pieces missing from rhapody were Classic and Carbon, so it really was nextstep with an OS9 skin).
- xoa 5y agoThanks for the correction, man has it been a long, long time. I had the Public Beta and than got on the OS X train pretty fast on a good old B&W G3. Even with the slowness the multitasking still allowed getting around it and having all Unix right there with a big rush to initial porting was really interesting, good times. I remember calling Apple for help getting Apache compiled and got forwarded right out of the regular call system to some dev whose name I sadly forget and we worked through it. Everything is a million times more refined and overall better now but I do have a bit of nostalgia for the community and really getting your hands dirty back then while still having a fairly decent fallback. I haven't actually needed to mess with kernel stuff since 10.5 or so but thinking back makes me wonder about paths not taken.
- olliej 5y agoLinux does that now. It didn't in the past (something like 2008), and I recall many people arguing about performance or similar at that time :D
- CyberRabbi 5y agoI like that. Fsync() was designed with the block cache in mind. IMO how the underlying hardware handles durability is its own business. I think a hack to issue a “full fsync” when battery is below some threshold is a good compromise.
- ribit 5y agoSomething that is not quite clear to me yet (I did read the discussion below, thank you Hector for indulging us, very informative): isn't the end behaviour up to the drive controller? That is, how can we be sure that Linux actually does push to the storage or is it possible that the controller cheats? For example, you mention the USB drive test on a Mac — how can we know that the USB stick controller actually does the full flush? Regardless, I certainly agree that the performance hit seems excessive. Hopefully it's just an algorithm, issue and Apple can fix this with a software update.
- monocasa 5y agoLast time I checked (which is a while at this point, pre SSD) nearly all consumer drives and even most enterprise drives would lie in response to commands to flush the drive cache. Working on a storage appliance at the time, the specifics of a major drive manufacturer's secret SCSI vendor page knock to actually flush their cache was one of the things on their deepest NDAs. Apparently ignoring cache flushing was so ubiquitous that any drive manufacturer looking to have correct semantics would take a beating in benchmarks and lose marketshare. : \ So, as of about 2014, any difference here not being backed by per manufacturer secret knocks or NDAed, one-off drive firmware was just a magic show, with perhaps Linux at least being able to say "hey, at least the kernel tried and it's not our fault". The cynic in me thinks that the BSDs continuing to define fsync() as only hitting the drive cache is to keep a semantically clean pathway for "actually flush" for storage appliance vendors to stick on the side of their kernels that they can't upstream because of the NDAs. A sort of dotted line around missing functionality that is obvious 'if you know to look for it'. It wouldn't surprise me at all if Apple's NVME controller is the only drive you can easily put your hands on that actually does the correct things on flush, since they're pretty much the only ones without the perverse market pressure to intentionally not implement it correctly. Since this is getting updoots: Sort of in defense of the drive manufacturers (or at least stating one of the defenses I heard), they try to spec out the capacitance on the drive so that when the controller gets a power loss NMI, they generally have enough time to flush then. That always seemed like a stretch for spinning rust (the drive motor itself was quite a chonker in the watt/ms range being talked about particularly considering seeks are in the 100ms range to start with, but also they have pretty big electrolytic caps on spinning rust so maybe they can go longer?), but this might be less of a white lie for SSDs. If they can stay up for 200ms after power loss, I can maybe see them being able to flush cache. Gods help those HMB drives though, I don't know how you'd guarantee access to the host memory used for cache on power loss without a full system approach to what power loss looks like.
- garaetjjte 5y agoFlush with other vendors at least does something as they block for some time too, just not as long as Apple. Apple implementation is weird because actual amount of data written doesn't seem to affect flush time.