Non-pageable memory and the truth about VirtualLock()

New Message Reply About this list Date view Thread view Subject view Author view

Peter Gutmann (pgut001@cs.auckland.ac.nz)
Tue, 16 Feb 1999 01:29:02 (NZDT)


Windows NT has a function called VirtualLock() which (from a glance at the
manual page) looks like it should lock a page in physical memory, making it
non-pageable. Digging deeper indicates that this isn't quite what it does but
until now there's never been a precise explanation of its behaviour, however a
new book on NT device drivers, due to appear in early April, finally clears up
the mystery. The following text is a sidebar from Chapter 6 of the book,
forwarded with the permission of the author and publisher. One of the sample
drivers from the book allocates contiguous non-paged memory, and can be
changed to allocate non-contiguous, non-paged memory. This sounds like a
perfect NT match for the Win95 SCNSM driver.
                                                     
Peter.
 
---------------------------
The sidebar from chapter 6, Developing Windows NT Device Drivers: A
Programmer's Handbook, by Edward Dekker and Joseph Newcomer, published by
Addison-Wesley, March 1999, ISBN 0201695901.
 
I have corrected many Windows NT application programmers who think that they
have optimized their application by calling the Win32 function VirtualLock on a
large buffer (1 to 75MB). The programmer thinks that this function locks the
buffer into physical memory and that doing this improves the performance of the
application and the system.
 
The programmer is wrong.
 
Some of the “better” programmers think that the application performance will
improve at the cost of lower system performance.
 
These programmers are wrong, too.
 
VirtualLock does not lock pages into physical memory. It locks pages into the
application’s working set. This requires that all pages of the buffer must be
resident in physical memory before the application can run. Locking a large
buffer in the working set will increase the application’s use of physical
memory. The increased use of memory means more time spent paging. Locking pages
in the working set will not prevent the pages from being paged out when the
application is not the active process. The larger working set for the
application means more pages of the application will be paged out when other
applications and tasks run. Other tasks that will run include all User mode
portions of NT, the file system, updates to the clock in the task bar, as well
as other user applications.
 
When the NT scheduler gives the application a chance to run, the application is
not able to start until all pages of the buffer have been paged into main
memory. This results in a much longer delay to start execution at the beginning
of each execution quantum or completion of I/O. And the result of this is lower
application performance.
 
There will be less memory available for the file cache, so all file I/O will be
slower (for all processes). Other tasks, when given a quantum, will also be
slower starting, since they will compete for memory and need to be paged in.
The increased total paging activity and the delays starting other tasks result
in a lower system performance.
 
So you end up trading lower system performance for lower application
performance.
------------------------------------------------------


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Sat Apr 10 1999 - 01:18:27