VirtualAlloc vs ProbeAndLockPages

What are the differences between allocating a buffer in user mode
with VirtualAlloc(MEM_COMMIT…) and using ProbeAndLockPages
on a pointer allocated by malloc ?

what happens to these locked pages when the allocatin
process crashes ?

Cheers,
Tomer Goldberg

VirtualAlloc allocates free, zeroed pages to the process address space
(or more correctly it ensures they can be allocated if the process
touches them by ensuring there’s enough page-file space to back them).

ProbeAndLockPages has nothing to do with address spaces - it increments
the lock count on the physical pages to ensure they aren’t paged out.
It does not ensure they aren’t VirtualFree’d by the client, or that they
aren’t removed from the client’s working set (which invalidates the page
and prepares to write it out to disk - if it’s locked it will probably
remain in transition until referenced or unlocked)

The process’s user address space is destoryed as part of process
termination, and all the pages are released. If any of them are still
locked, however, the system will bugcheck. Drivers that lock process
pages are required to ensure that they unlock the pages as the process
terminates.

The expectation is that locked pages are only associated with I/O
requests, and that hte pages should only be locked for the life of the
I/O request. Since the process can’t exit until all outstanding I/O has
completed or been successfully cancelled, the driver has a chance to
clean everything up when the process terminates. If it doesn’t then
there’s a bug in a kernel component (the driver).

Much of this is explained in Inside Windows 2000’s chapters on memory
management and I/O.

-p


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of tomerg
Sent: Thursday, July 22, 2004 11:40 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] VirtualAlloc vs ProbeAndLockPages

What are the differences between allocating a buffer in user mode
with VirtualAlloc(MEM_COMMIT…) and using ProbeAndLockPages
on a pointer allocated by malloc ?

what happens to these locked pages when the allocatin
process crashes ?

Cheers,
Tomer Goldberg

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com