Nonpaged Pool(非分頁池) 和 Paged Pool(分頁池) 在Windows中的用處

pamxy發表於2013-06-24

轉自:http://www.cnblogs.com/Amaranthus/archive/2012/11/15/2771523.html

很多DBA對nonpage pool 和 paged pool 搞不太清楚幹嘛用的,看perfmon中的說明也看得稀裡糊塗。找到一個資料就翻譯一下。

From:http://blogs.technet.com/b/markrussinovich/archive/2009/03/26/3211216.aspx

Nonpaged Pool(非分頁池)

The kernel and device drivers use nonpaged pool to store data that might be accessed when the system can’t handle page faults. The kernel enters such a state when it executes interrupt service routines (ISRs) and deferred procedure calls (DPCs), which are functions related to hardware interrupts. Page faults are also illegal when the kernel or a device driver acquires a spin lock, which, because they are the only type of lock that can be used within ISRs and DPCs, must be used to protect data structures that are accessed from within ISRs or DPCs and either other ISRs or DPCs or code executing on kernel threads. Failure by a driver to honor these rules results in the most common crash code, IRQL_NOT_LESS_OR_EQUAL.

核心或者裝置驅動使用非分頁池來儲存可能訪問的資料,但是在訪問的時候又不能出現也錯誤。當核心執行中斷服務程式並且延遲呼叫過程的時候就會進入這種狀態,這個狀態和硬體中斷相關聯。當核心或者裝置驅動在這個狀態後,獲取了一個自旋鎖,頁錯誤也是不被允許的,自旋鎖是唯一能在延遲呼叫或者中斷服務程式中能用的鎖型別,用來保護被延遲過程呼叫和中斷服務程式訪問的資料,可能來自於延遲過程呼叫和中斷服務程式,也可能來自其他的延遲過程呼叫和中斷服務程式,或者其他的核心執行緒。如果驅動程式在執行整個規則的時候出錯會得到一個 IRQL_NOT_LESS_OR_EQUAL 的崩潰程式碼

Nonpaged pool is therefore always kept present in physical memory and nonpaged pool virtual memory is assigned physical memory. Common system data structures stored in nonpaged pool include the kernel and objects that represent processes and threads, synchronization objects like mutexes, semaphores and events, references to files, which are represented as file objects, and I/O request packets (IRPs), which represent I/O operations.

非分頁池因此總是報錯在記憶體中,非分頁池的虛擬地址被實體地址分配。通用的系統資料結構被儲存在非分頁池中包含核心和代表程式和執行緒的物件,互斥物件,同步訊號量,引用檔案(代表檔案物件),和I/O請求包(代表I/O操作)

Paged Pool(分頁池)

Paged pool, on the other hand, gets its name from the fact that Windows can write the data it stores to the paging file, allowing the physical memory it occupies to be repurposed. Just as for user-mode virtual memory, when a driver or the system references paged pool memory that’s in the paging file, an operation called a page fault occurs, and the memory manager reads the data back into physical memory. The largest consumer of paged pool, at least on Windows Vista and later, is typically the Registry, since references to registry keys and other registry data structures are stored in paged pool. The data structures that represent memory mapped files, called sections internally, are also stored in paged pool.

分頁池,從字面意思來說,也就是可以存到系統的分頁檔案中,允許實體記憶體重定向。如使用者模式的虛擬記憶體,當驅動或者系統引用分頁池記憶體在分頁檔案中,那麼一個操作就會呼叫頁錯誤,記憶體管理系統把資料從分頁檔案中讀取到實體記憶體。在windows vista和之後的版本,分頁池最大的使用者是登錄檔,引用的註冊鍵值和其他登錄檔資料都是儲存在分頁池中。記憶體對映檔案(內部叫做記憶體物件[Sections])也存在分頁池中。

 

Device drivers use the ExAllocatePoolWithTag API to allocate nonpaged and paged pool, specifying the type of pool desired as one of the parameters. Another parameter is a 4-byte Tag, which drivers are supposed to use to uniquely identify the memory they allocate, and that can be a useful key for tracking down drivers that leak pool, as I’ll show later.

裝置驅動可以使用ExAllocatePoolWithTag API來申請非分頁池和分頁池,可以使用引數來指定在那個型別的池中申請。另外一個引數是4個位元組的tag,用來唯一標示分配記憶體的驅動程式,並且在跟蹤驅動程式是否缺少池十分有用。


相關文章