clementttttttttt wrote:
I can't really find information on how this works, and the Linux source is way too complicated.
Have a look for BSD VM documentation. This is a nice overview:
http://blog.pr4tt.com/2016/02/02/BSD-virtual-memory/FreeBSD is based on the Mach VM subsystem used in 4.4 BSD.
NetBSD/OpenBSD replaced the Mach VM based subsystem with a simpler system called UVM but retains the Mach VM pmap interface to handle the CPU specific page mapping. It is described here:
https://www.netbsd.org/docs/kernel/uvm.htmlI find areas such as describing VM are better served by traditional text books. The "Design and Implementation of the FreeBSD Operating System" gives a good detailed overview of the FreeBSD VM, and should help in understanding how mmap is implemented.
I also find the BSDs VM subsystems are structured better than the Linux VM subsystem, which looks quite messy in comparison, and they tend to be better described in text books. I prefer the separation of hardware independent and hardware dependent layers via an API rather than the abstract page table data structure used by Linux.
TL;DR
Study the BSD VM subsystems. If you understand how they work, the mechanism of mmap should be simple. But you really need to know how VM works as a whole in order to understand mmap.