How can I find the PFN_NUMBER or PHYSICAL_ADDRESS of the Dummy page used to modify system MDLs?
I have a filter driver that manipulates the data in the read/write buffers.
Unfortunately under Vista/Win7 the system uses a system-wide dummy page to replace valid user-mode pages that are not modified/read. Here is an article about it:
http://msdn.microsoft.com/en-us/windows/hardware/gg463193
The suggestion is to use a secondary buffer and copy the data between the two. Unfortunately this causes a huge performance hit which I would like to avoid.
- Is there a way to figure out what page the system uses as its dummy page so I don’t have to double buffer if the DUMMY page is not present?
- the MS documentation states that this is a single page. Is that true? I have noticed that the page (PFN) changes when the system reboots but I have no proof that only one page is used as a DUMMY page at any time.
I do have two methods for figuring out when a dummy page is used but I need something faster:
A. (while in the caller’s thread context) create a duplicate MDL analogous to the system supplied MDL using the user mode virtual address. Lock both MDLs (MmProbeAndLockPages). Since they are describing the same virtual address space they should be using the same physical pages. If you compare the PFNs they should be the same. If they are not, than the system used a dummy page.
B. walk the MDL (or the system buffer) and compare the physical pages describing the range to each other. If a more than one page is mapped to the dummy page, this can find it.
C. use the PFN discovered by ?A? and or ?B?
Each of those methods have its pros and cons.
- ?A? works only if you are in the caller?s thread context. It also pokes inside the MDL’s PFN array which is frowned upon.
- ?B? is fast and works in any context (as long as the MDL pages are locked) but can miss MDLs with a single dummy page.
- ?C? assumes that there is only one ?System-wide? dummy page and relies on the output from ?A? and/or ?B?.
Any suggestions?