views:

31

answers:

1

All my driver code currently does this, mostly because I worked with a very senior driver programmer for a couple years who had previously worked on the Windows kernel team for 15 years and he demanded it. I got in the habit of it and never really asked the question "Why?"

I know the obvious reasons, such as nonpaged pool is scarce compared to paged and you cannot make assumptions about the target system (like how much nonpaged memory will be available). But we recently inherited a slew of Linux driver programmers who started working with my driver code (apparently there is no such distinction in Linux) and they got all up in a bunch when I told them that code/data must be put in paged pool whenever possible.

So, what are the real reasons we do the paged/non-paged pool allocations?

+1  A: 

In short, Windows tries to minimize memory consumption by paging its kernel allocations.

Longer version: Any nonpaged allocation must remain in physical memory until deallocated. Thus, these allocations consume virtual address space and physical memory. Virtual addresses are very limited in a 32bit system, and therefore driver allocations are made out of a scarce space (since the allocations are global). On a 64bit Windows system, there is considerable VA space and so this isn't particularly a concern.

However, every allocation still uses physical memory. Memory that is therefore unavailable to the user, which might be small (about 2.5% currently on my machine). A greater concern comes when running in a VM environment, as these allocations are cumulative. So decreasing the nonpaged allocations will allow more VM instances to run on a physical machine.

Paged allocations can be paged to disk, and therefore are only to be accessed at PASSIVE and APC level, else you might see a bluescreen as Windows cannot service the page fault at the higher IRQLs.

To reprise:

  1. if your driver operates at DPC or higher IRQL, then determine a reasonable partition of your code / data into sections required for these levels and make them NONPAGED.
  2. if your driver does not change IRQLs, nor take interrupts, then make all allocations PAGED to be a good citizen and minimize your physical memory usage.
Brian
Enough info to get what I need from Google. Thanks.
Karl Strings