Memory Pages monitoring in Windows/Linux Platform
Is there a way in Windows/Linux or any other operating system to know at instruction-level, if a memory access generated a Page Fault? The code I'm imagining about would look something like this:
Buffer *buffer = new Buffer();
...Do s开发者_如何学编程omething with the buffer...
if(thisProcess.generatedPageFault) {
...Do something...
}
...Do something else with the buffer...
if(thisProcess.generatedPageFault) {
...Do something...
}
For linux the closest thing you'll get is reading /proc/self/stat and parse out the no. of pagefaults before and after your calls - the format is described here: http://linux.die.net/man/5/proc
Keep in mind, reading/parsing that file could itself cause pagefaults - atleast the 1. time you do it, of if you allocate memory to read it (like calling fopen
)
Accordingly to the Intel documentation for the x86 processor - a page fault is Interrupt 14. The kernel at a low level would have an interrupt handler set up to trap that page fault. When that occurs, the kernel's interrupt handler handles the situation accordingly.
Now, since this is at the nuts and bolts level, and residing in ring 0 code, I would not think you can actually monitor that...you may get around that by creating a driver to simply watch for a page fault (again, dependent on the OS privileges and internal data structures occupied by the kernel), and pass the information back out to user-land space... I doubt if that would be easily exposable...
Hope this helps, Best regards, Tom.
精彩评论