mac: add readahead control to the posix_fadvise() shim
authorSitsofe Wheeler <sitsofe@yahoo.com>
Mon, 25 Aug 2025 21:38:42 +0000 (22:38 +0100)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Wed, 3 Sep 2025 19:26:33 +0000 (20:26 +0100)
commit407491a84e257a60a09209c624014757b816ee8e
tree758b49b22edf75a3329ccb8c94484b0bbb5e5bd4
parent41880b9b7aa4db7d537e096e15192437a990d9f1
mac: add readahead control to the posix_fadvise() shim

- Add support for POSIX_FADV_NORMAL in the posix_fadvise() shim by just
  ignoring it
- Add support for POSIX_FADV_SEQUENTIAL/POSIX_FADV_RANDOM by mapping
  them to enable/disable of readahead via fcntl(..., F_RDAHEAD, ...).
  Because macOS only lets you control readahead at the descriptor level
  the offset and len values passed will be ignored and range control is
  not done.

The impact of being able to tune readahead is demonstrated by the
bandwidths achieved by the following jobs running on an SSD of an
otherwise idle Intel Mac laptop with 16GBytes of RAM:

./fio --stonewall --size=128M --filename=fio.tmp --bs=4k --rw=read \
  --name=sequential-readahead --fadvise=sequential \
  --name=sequential-no-readahead --fadvise=random

[...]
sequential-readahead: (groupid=0, jobs=1): err= 0: pid=6250: Tue Sep  2 22:10:45 2025
  read: IOPS=331k, BW=1293MiB/s (1356MB/s)(128MiB/99msec)
[...]
sequential-no-readahead: (groupid=1, jobs=1): err= 0: pid=6251: Tue Sep  2 22:10:45 2025
  read: IOPS=25.9k, BW=101MiB/s (106MB/s)(128MiB/1263msec)

rm -f fio-huge.tmp
truncate -s 1T fio-huge.tmp
./fio --stonewall --filename=fio-huge.tmp --bs=32k --runtime=10s --rw=randread:3 \
  --name=partial-random-no-readahead --fadvise=random \
  --name=absorb-cache-invalidation --number_ios=1 --bs=4k \
  --name=partial-random-readahead --fadvise=sequential

[...]
partial-random-no-readahead: (groupid=0, jobs=1): err= 0: pid=6259: Tue Sep  2 22:12:35 2025
  read: IOPS=92.4k, BW=2888MiB/s (3029MB/s)(28.2GiB/10001msec)
[...]
partial-random-readahead: (groupid=2, jobs=1): err= 0: pid=6261: Tue Sep  2 22:12:35 2025
  read: IOPS=61.8k, BW=1931MiB/s (2024MB/s)(18.9GiB/10001msec)

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
os/mac/posix.c