Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1855695
  • 博文数量: 317
  • 博客积分: 1557
  • 博客等级: 上尉
  • 技术积分: 1208
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-26 23:38
个人简介

如果想出发,就不要等到明天!

文章分类

全部博文(317)

文章存档

2016年(1)

2015年(41)

2014年(152)

2013年(114)

2012年(4)

2011年(1)

2009年(4)

分类: LINUX

2014-08-27 10:44:46

page结构大致说明如下:

点击(此处)折叠或打开

  1. struct page {
  2.     /*page相关标记     */
  3.     page_flags_t flags;        /* Atomic flags, some possibly
  4.                      * updated asynchronously */
  5.     /*页框引用计数     */
  6.     atomic_t _count;        /* Usage count, see below. */
  7.     /*页框的映射此时,表示有多少个pte映射到此page;-1:表示没有页表项映射该页框;0:表示页非共享;>0:表示页共享*/
  8.     atomic_t _mapcount;        /* Count of ptes mapped in mms,
  9.                      * to show when page is mapped
  10.                      * & limit reverse map searches.
  11.                      */
  12.     /*私有数据,不同场景作用不同,可用于伙伴系统*/
  13.     unsigned long private;        /* Mapping-private opaque data:
  14.                      * usually used for buffer_heads
  15.                      * if PagePrivate set; used for
  16.                      * swp_entry_t if PageSwapCache
  17.                      * When page is free, this indicates
  18.                      * order in the buddy system.
  19.                      */
  20.     /* 当页被用作page cache或者当页为匿名页时使用)。*/
  21.     struct address_space *mapping;    /* If low bit clear, points to
  22.                      * inode address_space, or NULL.
  23.                      * If page mapped as anonymous
  24.                      * memory, low bit is set, and
  25.                      * it points to anon_vma object:
  26.                      * see PAGE_MAPPING_ANON below.
  27.                      */
  28.     pgoff_t index;            /* Our offset within mapping. */
  29.     /*lru链表     */
  30.     struct list_head lru;        /* Pageout list, eg. active_list
  31.                      * protected by zone->lru_lock !
  32.                      */
  33.     /*
  34.      * On machines where all RAM is mapped into kernel address space,
  35.      * we can simply calculate the virtual address. On machines with
  36.      * highmem some memory is mapped into kernel virtual memory
  37.      * dynamically, so we need a place to store that address.
  38.      * Note that this field could be 16 bits on x86 ... ;)
  39.      *
  40.      * Architectures with slow multiplication can define
  41.      * WANT_PAGE_VIRTUAL in asm/page.h
  42.      */
  43. #if defined(WANT_PAGE_VIRTUAL)
  44.     /* 如果进行了内存映射,则表示虚拟地址。仅对高端内存有意义。 */
  45.     void *virtual;            /* Kernel virtual address (NULL if
  46.                      not kmapped, ie. highmem) */
  47. #endif /* WANT_PAGE_VIRTUAL */
  48. };
mem_mmap:内核全局变量,包含系统中所有的物理内存对应的page结构的数组,每个数组元素对应一个物理页,数组的索引对应于该物理页在物理内存中的位置,比如物理内存的第一个页对应于mem_map[0],NUMA结构中有所差别(这里不描述~)

点击(此处)折叠或打开

  1. struct page *mem_map;

page和物理页帧转换

点击(此处)折叠或打开

  1. #define pfn_to_page(pfn) (mem_map + (pfn)) //pfn相当于该page在mem_map数组中的索引号,mem_map+pfn相当于mem_map[pfn]
  2. #define page_to_pfn(page) ((unsigned long)((page) - mem_map))) //page-mem_map得到该page在mem_map数组中的索引,索引号就是物理页帧号pfn


阅读(1027) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~