We are observing an issue where certain file write patterns perform inexplicably slow, in the range of 100ms instead of the in the low hundreds of microseconds. We are running on macOS 10.14.6 using unencrypted APFS volumes and we've tested on MacMini (2018) and MBP 15" (2017) with very similar results. Both of these systems are capable of reaching write throughput in the 2~3GB range and we do see that in general. Certain IO patterns however, bring the system down to a crawl, namely around 10MB/s. We first observed this in our own application and then were able to reproduce the scenario using FIO (https://github.com/axboe/fio) to illustrate the problem. We basically generate a largish file, say 16Gb which doesn't fit entirely in the disk cache and then start writing sequentially to it, using buffered large IOs and sending multiple IOs at a time. Here is the fio job file:
Here is a typical result:
Run status group 0 (all jobs):
WRITE: bw=10.5MiB/s (11.0MB/s), 10.5MiB/s-10.5MiB/s (11.0MB/s-11.0MB/s), io=6325MiB (6632MB), run=600665-600665msec
Note that switching to direct IO (direct=1) immediatelly brings up the throughput to 2GB/s+. Lowering the iodepth down to 1 also brings it up to 1~1.5GB/s which is to be expected with a single IO. Reducing the file size (I guess so the entire file fits in the cache) also has a dramatic performance boost.
All in all, we are forced to conclude that there must be some performance issue in the disk cache on macOS to explain this behavior. We haven't tested with prior OS verions or HFS+ so not sure if the issue is specific to the OS or the file system.
Thanks in advance,