A trap-based mechanism is provided for gaining greater visibility into the
memory usage of a process. To detect and record the memory accesses of a
process, a virtual address range (or a plurality of address ranges) of
the process is set to a protected status. This address range represents
the range of virtual addresses that are to be monitored for access. By
setting the address range to a protected status, whenever a memory access
(in one implementation, whenever a memory write) is made to a virtual
address within that address range, a trap arises. When the trap arises, a
trap handler is invoked. When invoked, the trap handler records the
virtual address that was accessed. In this manner, the access of the
virtual address is detected and recorded without having to add extensive
instrumentation code to the process.