If possible, i.e. if the requested range is resident valid in the vm object queue, and some secondary conditions hold, copy data for read(2) directly from the valid cached pages, avoiding vnode lock and instantiating buffers. I intentionally do not start read-ahead, nor handle the advises on the cached range.
It is only enabled for UFS right now. Tmpfs does not save file size in the swap object so I cannot clip at EOF. In principle this can work for ZFS.
Sample on 2.5G file read, first read is for guaranteed uncached file from spinning disk:
root@:/ # umount /mnt root@:/ # mount -r /dev/da0p2 /mnt root@:/ # sysctl debug.vn_io_pgcache_read_enable=0 debug.vn_io_pgcache_read_enable: 0 -> 0 root@:/ # time dd if=/mnt/work/kernbuild.stacks of=/dev/zero 5256686+1 records in 5256686+1 records out 2691423676 bytes transferred in 19.233627 secs (139933240 bytes/sec) 19.25 real 1.58 user 16.58 sys root@:/ # time dd if=/mnt/work/kernbuild.stacks of=/dev/zero 5256686+1 records in 5256686+1 records out 2691423676 bytes transferred in 17.040581 secs (157942009 bytes/sec) 17.04 real 1.77 user 15.27 sys root@:/ # time dd if=/mnt/work/kernbuild.stacks of=/dev/zero 5256686+1 records in 5256686+1 records out 2691423676 bytes transferred in 16.993587 secs (158378784 bytes/sec) 16.99 real 1.89 user 15.09 sys root@:/ # umount /mnt root@:/ # mount -r /dev/da0p2 /mnt root@:/ # sysctl debug.vn_io_pgcache_read_enable=1 debug.vn_io_pgcache_read_enable: 0 -> 1 root@:/ # time dd if=/mnt/work/kernbuild.stacks of=/dev/zero 5256686+1 records in 5256686+1 records out 2691423676 bytes transferred in 18.191389 secs (147950421 bytes/sec) 18.21 real 1.77 user 9.71 sys root@:/ # time dd if=/mnt/work/kernbuild.stacks of=/dev/zero 5256686+1 records in 5256686+1 records out 2691423676 bytes transferred in 10.764700 secs (250023107 bytes/sec) 10.76 real 1.67 user 9.08 sys root@:/ # time dd if=/mnt/work/kernbuild.stacks of=/dev/zero 5256686+1 records in 5256686+1 records out 2691423676 bytes transferred in 10.720573 secs (251052233 bytes/sec) 10.72 real 1.70 user 9.01 sys