On Thu, 25 Jul 2013 16:57:44 -0700, kernel neophyte said:
I am sorry, its still not clear to me. All I am asking is I want to know and understand how mmap works, given an address *X*, how does the Linux kernel figure out that *X* is an mmaped page?
Before you ask *how* it does it, first figure out if it does it *at all*. The reason you can't figure out how the swami is levitating is because they aren't actually levitating at all.
Is there a special flag in the page table entry?
No, because no flag is needed.
Does the access generate a page fault ?
Maybe, maybe not. If the page is resident in memory there's no page fault. And if it's not resident, it gets paged in from wherever the backing page happens to be.
If so, how does the handler find out it is an mmaped address?
The handler doesn't *care* if it's mmaped. All it has to know is (1) this page isn't in memory, (2) it needs to be in memory, and (3) so please schedule the I/O to read it from block NNNN of device XXYY just like any *other* page being read in because of a page fault. The *only* thing "magical" about an mmap'ed page is that the pointer to where to read/write it might (sometimes) point at someplace that's not a swap space. Though for some uses of mmap(), it *does* point at swap space (for instance, the anonymous pages created by mmap() as used from malloc() in glibc).