mmap how does kernel know a page is mmaped
neophyte.hacker001 at gmail.com
Thu Jul 25 19:57:44 EDT 2013
On Thu, Jul 25, 2013 at 11:33 AM, Greg Freemyer <greg.freemyer at gmail.com>wrote:
> On Thu, Jul 25, 2013 at 1:52 PM, kernel neophyte
> <neophyte.hacker001 at gmail.com> wrote:
> > ok,
> > I am sorry maybe I did not ask the question correctly, all I want to
> know is
> > how mmap works underneath, given an address X how does kernel figure out
> > a mmaped page ?
> > -Neo
> > On Thu, Jul 25, 2013 at 10:04 AM, <Valdis.Kletnieks at vt.edu> wrote:
> >> On Thu, 25 Jul 2013 09:14:03 -0700, kernel neophyte said:
> >> > Could anyone please explain, how mmap works underneath ? when kernel
> >> > traveses pgd->pud->pmd->pte how does it know that a particular page
> is a
> >> > mmaped page ? is there any special flag ?
> >> Why would the address mapping hardware even *care* that it's an mmap'ed
> >> page, once the mapping is set up? For that matter, why would most of
> >> the kernel code care?
> >> Only time an mmap'ed page is any different than any other process page
> >> while the mmap is actually being set up, modified, or torn down.
> >> (And in fact, that's part of why getting the varions sync() calls to
> >> nice with mmap() is so hard - because an mmap'ed file page is just a
> >> So noticing that a page got modified and knowing to do stuff like update
> >> the atime and mtime of the backing file is difficult...)
> First be aware this is bottom post only mailing list, as are most of
> the LKML lists, so if you are going to post on the public lists you
> will need to start bottom posting.
> As to your question, the more specific you are the better.
> There are 3 situations I can think of offhand, but I don't know which
> one you are interested in:
> 1) Userspace does a read/write to a data page that is not memory
> resident and the page is backed by a mmap'ed file.
> 2) Userspace does a read/write to a data page that is memory resident
> 3) The kernel decides a memory page is needed for another use and
> needs to be sync'ed to disk if any data updates are not to be lost.
> Valdis is saying for case 2) the kernel doesn't care. The kernel is
> not even in the loop. The userspace app has the memory pages
> available to it via the standard MMU mapping so the data accesses just
> The kernel in general only has to handle case 1) and case 3)
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? Is there a special flag in
the page table entry? Does the access generate a page fault ? If so, how
does the handler find out it is an mmaped address?
Sorry for the inconvenience caused, Thanks a lot for your time in replying.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Kernelnewbies