The Linux Kernel Primer. A Top-Down Approach for x86 and PowerPC Architectures
4.1. Pages
As the basic unit of memory managed by the memory manager, a page has a lot of state that it needs to be kept track of. For example, the kernel needs to know when pages become available for reallocation. To do this, the kernel uses page descriptors. Every physical page in memory is assigned a page descriptor. This section describes various fields in the page descriptor and how the memory manager uses them. The page structure is defined in include/linux/mm.h. ----------------------------------------------------------------------------- include/linux/mm.h 170 struct page { 171 unsigned long flags; 172 173 atomic_t count; 174 struct list_head list; 175 struct address_space *mapping; 176 unsigned long index; 177 struct list_head lru; 178 179 union { 180 struct pte_chain *chain; 181 182 pte_addr_t direct; 183 } pte; 184 unsigned long private; 185 ... 196 #if defined(WANT_PAGE_VIRTUAL) 197 void *virtual; 198 199 #endif 200 }; ----------------------------------------------------------------------------- 4.1.1. flags
Atomic flags describe the state of the page frame. Each flag is represented by one of the bits in the 32-bit value. Some helper functions allow us to manipulate and test particular flags. Also, some helper functions allow us to access the value of the bit corresponding to the particular flag. The flags themselves, as well as the helper functions, are defined in include/linux/page-flags.h. Table 4.1 identifies and explains some of the flags that can be set in the flags field of the page structure.
4.1.1.1. count
The count field serves as the usage or reference counter for a page. A value of 0 indicates that the page frame is available for reuse. A positive value indicates the number of processes that can access the page data.[4] [4] A page is free when the data it was holding is no longer used or needed. 4.1.1.2. list
The list field is the structure that holds the next and prev pointers to the corresponding elements in a doubly linked list. The doubly linked list that this page is a member of is determined in part by the mapping it is associated with and the state of the page. 4.1.1.3. mapping
Each page can be associated with an address_space structure when it holds the data for a file memory mapping. The mapping field is a pointer to the address_space of which this page is a member. An address_space is a collection of pages that belongs to a memory object (for example, an inode). For more information on how address_space is used, go to Chapter 7, "Scheduling and Kernel Synchronization," Section 7.14. 4.1.1.4. lru
The lru field holds the next and prev pointers to the corresponding elements in the Least Recently Used (LRU) lists. These lists are involved with page reclamation and consist of two lists: active_list, which contains pages that are in use, and incactive_list, which contains pages that can be reused. 4.1.1.5. virtual
virtual is a pointer to the page's corresponding virtual address. In a system with highmem,[5] the memory mapping can occur dynamically, making it necessary to recalculate the virtual address when needed. In these cases, this value is set to NULL. [5] Highmem is the physical memory that surpasses the virtually addressable range. See Section 4.2, "Memory Zones."
|
Категории