- 论坛徽章:
- 11
|
- struct zonelist {
- struct zone *zones[MAX_NUMNODES * MAX_NR_ZONES + 1]; // NULL delimited
- };
- typedef struct pglist_data {
- struct zone node_zones[MAX_NR_ZONES];
- struct zonelist node_zonelists[MAX_ZONELISTS];
- int nr_zones;
- #ifdef CONFIG_FLAT_NODE_MEM_MAP /* means !SPARSEMEM */
- struct page *node_mem_map;
- #ifdef CONFIG_CGROUP_MEM_RES_CTLR
- struct page_cgroup *node_page_cgroup;
- #endif
- #endif
- #ifndef CONFIG_NO_BOOTMEM
- struct bootmem_data *bdata;
- #endif
- #ifdef CONFIG_MEMORY_HOTPLUG
- /*
- * Must be held any time you expect node_start_pfn, node_present_pages
- * or node_spanned_pages stay constant. Holding this will also
- * guarantee that any pfn_valid() stays that way.
- *
- * Nests above zone->lock and zone->size_seqlock.
- */
- spinlock_t node_size_lock;
- #endif
- unsigned long node_start_pfn;
- unsigned long node_present_pages; /* total number of physical pages */
- unsigned long node_spanned_pages; /* total size of physical page
- range, including holes */
- int node_id;
- wait_queue_head_t kswapd_wait;
- struct task_struct *kswapd;
- int kswapd_max_order;
- enum zone_type classzone_idx;
- } pg_data_t;
复制代码 如上的 pglist_data 结构, 一直以为 node_zones 和 node_zonelists 关系如下:
node_zones 是实际上的 zone 结构, 每个 pglist_data 存在最多三个 zone
node_zonelists 代表分配策略, node_zonelists 是 zonelist 数组, 每个zonelist 又是 zone 的一个链表;
因此形成如下的关系:
pglist_data_0 = {
.node_zones = {.node_zones = {zone_0_dma, zone_0_normal, zone_0_high},}
.node_zonelists = {.zones = {&zone_0_high, &zone_1_high, &zone_0_normal, &zone_1_normal, 0}}
}
pglist_data_0 = {
.node_zones = {.node_zones = {zone_1_dma, zone_1_normal, zone_1_high},}
.node_zonelists = {.zones = {&zone_1_high, &zone_0_high, &zone_1_normal, &zone_0_normal, 0}}
}
但看以下代码有点傻眼:- static unsigned int nr_free_zone_pages(int offset)
- {
- pg_data_t *pgdat;
- unsigned int sum = 0;
- for_each_pgdat(pgdat) {
- struct zonelist *zonelist = pgdat->node_zonelists + offset;
- struct zone **zonep = zonelist->zones;
- struct zone *zone;
- for (zone = *zonep++; zone; zone = *zonep++) {
- unsigned long size = zone->present_pages;
- unsigned long high = zone->pages_high;
- if (size > high)
- sum += size - high;
- }
- }
- return sum;
- }
复制代码 如果按照我的理解, 很显然 sum 值是实际值的2倍, 因为计算 pglist_data_0 时其实将 zone_1_high, zone_1_normal 也计算进去了, pglist_data_1 时同理将 zone_0_high, zone_0_normal 计算进去了
不知实际上node_zones 和 node_zonelists 关系到底是什么样的 |
|