1 Pages

Page的概念来源为处理器Processor的部件MMU(Memory Management Unit),MMU通过设置好的页表(通过设置CR3寄存器,指向页目录所在的物理内存)对内存进行管理,管理操作包括:

 

a) 建立线性内存地址与物理内存地址的对应关系,即pa()和va()函数;

b) 管理哪些内存页驻存(Resident)于物理内存中,而哪些内存被交换到Swap文件中;

c) 哪些内存页被映射到哪个进程的虚拟地址空间;

d) 管理哪些内存页存储磁盘上(或者文件系统中)文件的缓存;

 

数据结构, struct page

/*
 * Each physical page in the system has a struct page associated with
 * it to keep track of whatever it is we are using the page for at the
 * moment. Note that we have no way to track which tasks are using
 * a page, though if it is a pagecache page, rmap structures can tell us
 * who is mapping it.
 */
struct page {
/* Atomic flags, some possibly
                     * updated asynchronously */
/* Usage count, see below. */
union {
/*
         * Count of ptes mapped in
         * mms, to show when page is
         * mapped & limit reverse map
         * searches.
         *
         * Used also for tail pages
         * refcounting instead of
         * _count. Tail pages cannot
         * be mapped and keeping the
         * tail page _count zero at
         * all times guarantees
         * get_page_unless_zero() will
         * never succeed on tail
         * pages.
         */
  29:         atomic_t _mapcount;
  30:  
/* SLUB */
  32:             u16 inuse;
  33:             u16 objects;
  34:         };
  35:     };
union {
struct {
/* Mapping-private opaque data:
                          * usually used for buffer_heads
                         * if PagePrivate set; used for
                         * swp_entry_t if PageSwapCache;
                         * indicates order in the buddy
                         * system if PG_buddy is set.
                         */
/* 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.
                         */
  52:         };
#if USE_SPLIT_PTLOCKS
  54:         spinlock_t ptl;
#endif
/* SLUB: Pointer to slab */
/* Compound tail pages */
  58:     };
union {
/* Our offset within mapping. */
/* SLUB: freelist req. slab lock */
  62:     };
/* 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)
/* Kernel virtual address (NULL if
                       not kmapped, ie. highmem) */
/* WANT_PAGE_VIRTUAL */
#ifdef CONFIG_WANT_PAGE_DEBUG_FLAGS
/* Use atomic bitops on this */
#endif
  83:  
#ifdef CONFIG_KMEMCHECK
/*
     * kmemcheck wants to track the status of each byte in a page; this
     * is a pointer to such a status block. NULL if not tracked.
     */
void *shadow;
#endif
  91: };

相关文章: