Monday, June 13, 2011

Prototype PTE and Shared Memory

In order to enable Sharing Memory among different process, an additional layer is added in the Virtual to Physical address translation. For each memory section thats being shared, a Segment structure (courtesy Section Object) is created. It contain the complete list of Prototype PTEs pointing to shared pages for that Section.

Prototype PTE is a special type of PTE. It forms the basic construct for supporting Shared memory in Windows. Prototype PTEs are same as any other regular PTE but with Prototype Bit field set. It contain enough information to access the desired Physical memory. Information in Prototype PTE is very much similar to any other regular PTE. It help Memory manager to bring the Pages to the Memory if it is not already there. Like for Pages backed up in the Pagefile or Mapped File, it will contain information about the Page Offset, etc.

Prototype PTE does not feature in the Page Tables and are not directly used for Address translation. They are only present in the Segment Structure. When any process open the Section object to a Shared memory the Page Table for that process is populated with PTEs that point to the Prototype PTEs in the corresponding Segment structure. When the process actually first try referring to any of the Shared Memory mapped into the Process address space, the memory manager use information in the Prototype PTE to update the Process PTE with Page Frame number of the resident shared memory.

If this was the first time any process has made reference to that shared memory, the Prototype PTE is also updated to directly point to the resident memory. During this,  the corresponding PFN database entry is also updated to indicate the number of processes sharing that memory. The PFN database entry also contain a back pointer to the Prototype PTE so that sometime later if memory manager decide to change the Page state and move it to some other location, it can use this pointer to update the Prototype PTE accordingly.



No comments:

Post a Comment