next up previous contents index
Next: 4.6 Initializing Kernel Page Up: 4. Page Table Management Previous: 4.4 Translating and Setting   Contents   Index

4.5 Allocating and Freeing Page Tables

The last set of functions deal with the allocation and freeing of page tables. Page tables, as stated, are physical pages containing an array of entries and the allocation and freeing of physical pages is a relatively expensive operation, both in terms of time and the fact that interrupts are disabled during page allocation. The allocation and deletion of page tables, at any of the three levels, is a very frequent operation so it is important the operation is as quick as possible.

Hence the pages used for the page tables are cached in a number of different lists called quicklists. Each architecture implements these caches differently but the principles used across all of them are the same. For example, not all architectures bother to cache PGD's because the allocation and freeing of them is only during process creation and exit. As these are both very expensive operations, the allocation of another page will not make much of a difference.

PGD's, PMD's and PTE's have two sets of functions each for the allocation and freeing of page tables. The allocation functions are pgd_alloc, pmd_alloc and pte_alloc respectively and the free functions are, predictably enough, called pgd_free, pmd_free and pte_free.

Broadly speaking, the three implement caching with the use of three caches called pgd_quicklist, pmd_quicklist and pte_quicklist. Architectures implement these three lists in different ways but one method is through the use of a LIFO type structure. Ordinarily, a page table entry contains points to other pages containing page tables or data. While cached, the first element of the list is used to point to the next free page table. During allocation, one page is popped off the list and during free, one is placed as the new head of the list. A count is kept of how many pages are used in the cache.

The quick allocation function from the pgd_quicklist is not externally defined outside of the architecture although get_pgd_fast is a common choice for the function name. The cached allocation function for PMD's and PTE's are publicly defined as pmd_alloc_one_fast and pte_alloc_one_fast.

If a page is not available from the cache, a page will be allocated using the physical page allocator (See Section 6). The functions for the three levels of page tables are get_pgd_slow, pmd_alloc_one and pte_alloc_one.

Obviously a large number of pages could end up on these caches and so there is a way of pruning the size of the cache. Each time the caches grow or shrink, a counter is incremented or decremented and it has a high and low watermark. check_pgt_cache() is called in two places to check these watermarks. When the high watermark is reached, entries from the cache will be freed until the cache size returns to the low watermark. The function is called after clear_page_tables() when a large number of page tables are potentially reached and is it also called by the system idle task.


next up previous contents index
Next: 4.6 Initializing Kernel Page Up: 4. Page Table Management Previous: 4.4 Translating and Setting   Contents   Index
Mel 2003-01-14