page结构大致说明如下:
-
struct page {
-
/*page相关标记 */
-
page_flags_t flags; /* Atomic flags, some possibly
-
* updated asynchronously */
-
/*页框引用计数 */
-
atomic_t _count; /* Usage count, see below. */
-
/*页框的映射此时,表示有多少个pte映射到此page;-1:表示没有页表项映射该页框;0:表示页非共享;>0:表示页共享*/
-
atomic_t _mapcount; /* Count of ptes mapped in mms,
-
* to show when page is mapped
-
* & limit reverse map searches.
-
*/
-
/*私有数据,不同场景作用不同,可用于伙伴系统*/
-
unsigned long private; /* Mapping-private opaque data:
-
* usually used for buffer_heads
-
* if PagePrivate set; used for
-
* swp_entry_t if PageSwapCache
-
* When page is free, this indicates
-
* order in the buddy system.
-
*/
-
/* 当页被用作page cache或者当页为匿名页时使用)。*/
-
struct address_space *mapping; /* If low bit clear, points to
-
* inode address_space, or NULL.
-
* If page mapped as anonymous
-
* memory, low bit is set, and
-
* it points to anon_vma object:
-
* see PAGE_MAPPING_ANON below.
-
*/
-
-
pgoff_t index; /* Our offset within mapping. */
-
/*lru链表 */
-
struct list_head lru; /* Pageout list, eg. active_list
-
* protected by zone->lru_lock !
-
*/
-
/*
-
* On machines where all RAM is mapped into kernel address space,
-
* we can simply calculate the virtual address. On machines with
-
* highmem some memory is mapped into kernel virtual memory
-
* dynamically, so we need a place to store that address.
-
* Note that this field could be 16 bits on x86 ... ;)
-
*
-
* Architectures with slow multiplication can define
-
* WANT_PAGE_VIRTUAL in asm/page.h
-
*/
-
#if defined(WANT_PAGE_VIRTUAL)
-
/* 如果进行了内存映射,则表示虚拟地址。仅对高端内存有意义。 */
-
void *virtual; /* Kernel virtual address (NULL if
-
not kmapped, ie. highmem) */
-
#endif /* WANT_PAGE_VIRTUAL */
-
};
mem_mmap:内核全局变量,包含系统中所有的物理内存对应的page结构的数组,每个数组元素对应一个物理页,数组的索引对应于该物理页在物理内存中的位置,比如物理内存的第一个页对应于mem_map[0],NUMA结构中有所差别(这里不描述~)
page和物理页帧转换
-
#define pfn_to_page(pfn) (mem_map + (pfn)) //pfn相当于该page在mem_map数组中的索引号,mem_map+pfn相当于mem_map[pfn]
-
#define page_to_pfn(page) ((unsigned long)((page) - mem_map))) //page-mem_map得到该page在mem_map数组中的索引,索引号就是物理页帧号pfn
阅读(4182) | 评论(0) | 转发(3) |