读书人

Linux内核之物理内存治理

发布时间: 2012-07-04 19:33:55 作者: rapoo

Linux内核之物理内存管理

Linux内核对于内存的管理摒弃了i386复杂的段式管理,而是采用了页式管理。Linux把整个的物理内存空间化为成一个个单独的页面,每页占4K空间大小。Linux把所有页面链接到一个全局的数组mem_map[]中,mem_map的每一个元素都是一个指针指向page数据结构。系统中的每个物理页面都对应着一个page数据结构,并根据需要把这些页面划分为不同的管理区:ZONE_DMA,ZONE_NORMAL和ZONE_HIGHMEM(用于物理内存超过1G空间的地址)。

?

typedef struct zone_struct {/* * Commonly accessed fields: */spinlock_tlock;unsigned longfree_pages;unsigned longpages_min, pages_low, pages_high;intneed_balance;/* * free areas of different sizes */free_area_tfree_area[MAX_ORDER];/* * wait_table-- the array holding the hash table * wait_table_size-- the size of the hash table array * wait_table_shift-- wait_table_size * == BITS_PER_LONG (1 << wait_table_bits) * * The purpose of all these is to keep track of the people * waiting for a page to become available and make them * runnable again when possible. The trouble is that this * consumes a lot of space, especially when so few things * wait on pages at a given time. So instead of using * per-page waitqueues, we use a waitqueue hash table. * * The bucket discipline is to sleep on the same queue when * colliding and wake all in that wait queue when removing. * When something wakes, it must check to be sure its page is * truly available, a la thundering herd. The cost of a * collision is great, but given the expected load of the * table, they should be so rare as to be outweighed by the * benefits from the saved space. * * __wait_on_page() and unlock_page() in mm/filemap.c, are the * primary users of these fields, and in mm/page_alloc.c * free_area_init_core() performs the initialization of them. */wait_queue_head_t* wait_table;unsigned longwait_table_size;unsigned longwait_table_shift;/* * Discontig memory support fields. */struct pglist_data*zone_pgdat;struct page*zone_mem_map;unsigned longzone_start_paddr;unsigned longzone_start_mapnr;/* * rarely used fields: */char*name;unsigned longsize;} zone_t;

?

读书人网 >UNIXLINUX

热点推荐