OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Nov 25, 2020 10:15 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How mmap() (system call) works
PostPosted: Wed Oct 14, 2020 6:29 am 
Offline

Joined: Tue Jul 14, 2020 4:01 am
Posts: 20
I can't really find information on how this works, and the Linux source is way too complicated.


Top
 Profile  
 
 Post subject: Re: How mmap() (system call) works
PostPosted: Wed Oct 14, 2020 8:32 am 
Offline
Member
Member

Joined: Tue Aug 11, 2020 12:14 pm
Posts: 71
The current linux source is extremely complicated, but it might be worthwhile perusing one of the early sources. It looks like mmap first appeared in the 0.96 kernels.


Top
 Profile  
 
 Post subject: Re: How mmap() (system call) works
PostPosted: Wed Oct 14, 2020 9:23 am 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 394
Location: San Jose San Francisco Bay Area
I am studying kernel 2.6.x device driver book, mmap essentially maps device addresses to user address space in PAGE_SIZE granularity. Of course there are lot to it thou.

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: How mmap() (system call) works
PostPosted: Wed Oct 14, 2020 10:14 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3994
Location: Chichester, UK
Not just devices but, more generally, files.

But that's what it does, not how it does it.


Top
 Profile  
 
 Post subject: Re: How mmap() (system call) works
PostPosted: Wed Oct 14, 2020 3:21 pm 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 am
Posts: 76
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.html

I 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.


Top
 Profile  
 
 Post subject: Re: How mmap() (system call) works
PostPosted: Thu Oct 15, 2020 2:52 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3994
Location: Chichester, UK
I have an earlier version of the book that you mention (The Design and Implementation of the 4.4 BSD Operating System ) and I can heartily recommend it as an excellent explanation of the workings of an operating system. It was very expensive at the time I bought it (probably the most expensive book I had ever bought), but I note that the new version is much cheaper.

There are also a number of books explaining the Linux kernel, and the massive Mac OS X Internals, that are worth reading if you can find a copy. Much better than trying to understand any of these OSs by just reading the source.

I'm afraid that far too many people seem to plunge into OS development without doing any background reading - not even the essential programming manuals produced by the chip manufacturers. This is a huge mistake and just leads to reinvention of the wheel (or in most cases the invention of the square wheel). We can profitably build upon the experience of those who went before us. And a little research will hopefully do away with the situation where newbies come here with every single little problem that they hit along the way (the same old problems time and time again).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group