<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 25, 2013 at 11:33 AM, Greg Freemyer <span dir="ltr"><<a href="mailto:greg.freemyer@gmail.com" target="_blank">greg.freemyer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On Thu, Jul 25, 2013 at 1:52 PM, kernel neophyte<br>
<<a href="mailto:neophyte.hacker001@gmail.com">neophyte.hacker001@gmail.com</a>> wrote:<br>
> ok,<br>
><br>
> I am sorry maybe I did not ask the question correctly, all I want to know is<br>
> how mmap works underneath, given an address X how does kernel figure out its<br>
> a mmaped page ?<br>
><br>
> -Neo<br>
><br>
><br>
> On Thu, Jul 25, 2013 at 10:04 AM, <<a href="mailto:Valdis.Kletnieks@vt.edu">Valdis.Kletnieks@vt.edu</a>> wrote:<br>
>><br>
>> On Thu, 25 Jul 2013 09:14:03 -0700, kernel neophyte said:<br>
>><br>
>> > Could anyone please explain, how mmap works underneath ? when kernel<br>
>> > traveses pgd->pud->pmd->pte how does it know that a particular page is a<br>
>> > mmaped page ? is there any special flag ?<br>
>><br>
>> Why would the address mapping hardware even *care* that it's an mmap'ed<br>
>> page, once the mapping is set up? For that matter, why would most of<br>
>> the kernel code care?<br>
>><br>
>> Only time an mmap'ed page is any different than any other process page is<br>
>> while the mmap is actually being set up, modified, or torn down.<br>
>><br>
>> (And in fact, that's part of why getting the varions sync() calls to play<br>
>> nice with mmap() is so hard - because an mmap'ed file page is just a page.<br>
>> So noticing that a page got modified and knowing to do stuff like update<br>
>> the atime and mtime of the backing file is difficult...)<br>
>><br>
<br>
</div></div>Neo,<br>
<br>
First be aware this is bottom post only mailing list, as are most of<br>
the LKML lists, so if you are going to post on the public lists you<br>
will need to start bottom posting.<br>
<br>
As to your question, the more specific you are the better.<br>
<br>
There are 3 situations I can think of offhand, but I don't know which<br>
one you are interested in:<br>
<br>
1) Userspace does a read/write to a data page that is not memory<br>
resident and the page is backed by a mmap'ed file.<br>
<br>
2) Userspace does a read/write to a data page that is memory resident<br>
<br>
3) The kernel decides a memory page is needed for another use and<br>
needs to be sync'ed to disk if any data updates are not to be lost.<br>
<br>
Valdis is saying for case 2) the kernel doesn't care. The kernel is<br>
not even in the loop. The userspace app has the memory pages<br>
available to it via the standard MMU mapping so the data accesses just<br>
work.<br>
<br>
The kernel in general only has to handle case 1) and case 3)</blockquote><div><br></div><div>I am sorry, its still not clear to me. All I am asking is <span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,sans-serif;font-size:15px"> I want to know and understand how mmap works, given an address </span><i style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,sans-serif;font-size:15px">X</i><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,sans-serif;font-size:15px">, how does the Linux kernel figure out that </span><i style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,sans-serif;font-size:15px">X</i><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Arial,sans-serif;font-size:15px"> 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?</span> </div>
<div><br></div><div>Sorry for the inconvenience caused, Thanks a lot for your time in replying. </div><div><br></div><div>-Neo</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><font color="#888888"><br>
Greg<br>
</font></span></blockquote></div><br></div></div>