Page Cache for shared memory
In the following link within the 4th image from the top:
http://duartes.org/gustavo/blog/post/page-cache-the-affair-between-memory-and-files
- The scenario depicted, is that of two processes, "render" and "3drender", sharing a file. The author is going about describing how the sharing mechanism, plays along with the page cache.
- Originally render had it's virtual pages mapped onto the page cache.
- In step 4 "render" is allocated a new anonymous page of it's own, which would contain certain changes, that it would want to make to "scene.dat #2".
- Once "render" makes it's changes, how is this change reflected to "3drender" which has continued to point to the page cache page frame containing "scene.dat #2" ?
- Also, shou开发者_开发技巧ldn't this change made by "render", make it's way back to the page cache, there by replacing the old page cache copy of "scene.dat #2" ?
- The part that remains unclear to me, is what happens "after" one of the processes writes to a shared page and how this "update" makes it's way to the page cache and disk, such that other processes which share the same file, see this change.
It be great if someone could throw some light.
Thanks, VIjay
In the scenario described in the linked article, render and render3d have private memory-mapped copies of a single file. As far as the processes can tell, the OS allocated a bunch of pages in each process's address space and just copied the file contents in there. If they modify those pages, nothing happens. No changes go back to the file. No changes go between render and render3d. That's what it means to have a private mapping.
Of course, giving each process a full copy of the file is really slow, so the OS uses a virtual memory trick. Until a process writes to the file, it can use a shared copy (shared with other processes and the page cache, also called a buffer cache). The private copy only happens when the process first tries to change the page.
精彩评论