mmap how does kernel know a page is mmaped

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Thu Jul 25 16:23:15 EDT 2013


On Thu, 25 Jul 2013 14:33:21 -0400, Greg Freemyer said:

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

And here, the kernel can cheat some more and re-use existing code.  There's 2
parts to it:

A) Writeback a page - which can be done the exact same way that any other page
gets written back to disk.  Only difference is writing to an offset in a file
as opposed to an offset in a swap space.  And if you consider the case of doing
a 'swapon' on a regular disk file, there's no real difference between "write
page 38F3E to block 3 of swap space on file /foo/bar/swap3" and "write page
38F3E to block 3 of file /foo/bar/swap3".

Similarly, the retrieval of a non-resident page backed by an mmap file is
pretty much the same as retrieving a non-resident page backed by swap space.

B) Possibly invalidate the mapping, because the page frame is needed.
At which point, future references to that page end up in case (1) above.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130725/11e39171/attachment.bin 


More information about the Kernelnewbies mailing list