by rnnr · 3y ago · 0 comments
* Fewer context switches among user space / kernel syscalls
* No need to copy _modified_ data into the swap. The behavior for read only data doesn't change
That's it, nothing miraculous about it.> * Fewer context switches among user space / kernel syscalls
This is not necessarily true. There's lots of cases where it's actually slower.
Note that each page fault to read an mmaped page is also a context switch from user space into the kernel. The kernel entry/exit paths for syscalls and page faults have much in common.
Mmaped pages can in principle use fault-ahead to reduce the number of page faults when sequential access is detected. An equivalent reduction is available for read syscalls by reading larger blocks at a time.
In practice, mmap files are faster in some scenarios compared with read syscalls and slower in others. Same with O_DIRECT reads, those are faster in some scenarios and slower in others.