⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 discontig.c

📁 h内核
💻 C
📖 第 1 页 / 共 2 页
字号:
					__per_cpu_start;				cpu_data += PERCPU_PAGE_SIZE;			}		}	}	return 0;}/** * free_node_bootmem - free bootmem allocator memory for use * @start: physical start of range * @len: length of range * @node: node where this range resides * * Simply calls the bootmem allocator to free the specified ranged from * the given pg_data_t's bdata struct.  After this function has been called * for all the entries in the EFI memory map, the bootmem allocator will * be ready to service allocation requests. */static int __init free_node_bootmem(unsigned long start, unsigned long len,				    int node){	free_bootmem_node(mem_data[node].pgdat, start, len);	return 0;}/** * reserve_pernode_space - reserve memory for per-node space * * Reserve the space used by the bootmem maps & per-node space in the boot * allocator so that when we actually create the real mem maps we don't * use their memory. */static void __init reserve_pernode_space(void){	unsigned long base, size, pages;	struct bootmem_data *bdp;	int node;	for_each_online_node(node) {		pg_data_t *pdp = mem_data[node].pgdat;		bdp = pdp->bdata;		/* First the bootmem_map itself */		pages = bdp->node_low_pfn - (bdp->node_boot_start>>PAGE_SHIFT);		size = bootmem_bootmap_pages(pages) << PAGE_SHIFT;		base = __pa(bdp->node_bootmem_map);		reserve_bootmem_node(pdp, base, size);		/* Now the per-node space */		size = mem_data[node].pernode_size;		base = __pa(mem_data[node].pernode_addr);		reserve_bootmem_node(pdp, base, size);	}}/** * initialize_pernode_data - fixup per-cpu & per-node pointers * * Each node's per-node area has a copy of the global pg_data_t list, so * we copy that to each node here, as well as setting the per-cpu pointer * to the local node data structure.  The active_cpus field of the per-node * structure gets setup by the platform_cpu_init() function later. */static void __init initialize_pernode_data(void){	int cpu, node;	pg_data_t *pgdat_list[MAX_NUMNODES];	for_each_online_node(node)		pgdat_list[node] = mem_data[node].pgdat;	/* Copy the pg_data_t list to each node and init the node field */	for_each_online_node(node) {		memcpy(mem_data[node].node_data->pg_data_ptrs, pgdat_list,		       sizeof(pgdat_list));	}	/* Set the node_data pointer for each per-cpu struct */	for (cpu = 0; cpu < NR_CPUS; cpu++) {		node = node_cpuid[cpu].nid;		per_cpu(cpu_info, cpu).node_data = mem_data[node].node_data;	}}/** * find_memory - walk the EFI memory map and setup the bootmem allocator * * Called early in boot to setup the bootmem allocator, and to * allocate the per-cpu and per-node structures. */void __init find_memory(void){	int node;	reserve_memory();	if (num_online_nodes() == 0) {		printk(KERN_ERR "node info missing!\n");		node_set_online(0);	}	min_low_pfn = -1;	max_low_pfn = 0;	if (num_online_nodes() > 1)		reassign_cpu_only_nodes();	/* These actually end up getting called by call_pernode_memory() */	efi_memmap_walk(filter_rsvd_memory, build_node_maps);	efi_memmap_walk(filter_rsvd_memory, find_pernode_space);	/*	 * Initialize the boot memory maps in reverse order since that's	 * what the bootmem allocator expects	 */	for (node = MAX_NUMNODES - 1; node >= 0; node--) {		unsigned long pernode, pernodesize, map;		struct bootmem_data *bdp;		if (!node_online(node))			continue;		bdp = &mem_data[node].bootmem_data;		pernode = mem_data[node].pernode_addr;		pernodesize = mem_data[node].pernode_size;		map = pernode + pernodesize;		/* Sanity check... */		if (!pernode)			panic("pernode space for node %d "			      "could not be allocated!", node);		init_bootmem_node(mem_data[node].pgdat,				  map>>PAGE_SHIFT,				  bdp->node_boot_start>>PAGE_SHIFT,				  bdp->node_low_pfn);	}	efi_memmap_walk(filter_rsvd_memory, free_node_bootmem);	reserve_pernode_space();	initialize_pernode_data();	max_pfn = max_low_pfn;	find_initrd();}/** * per_cpu_init - setup per-cpu variables * * find_pernode_space() does most of this already, we just need to set * local_per_cpu_offset */void *per_cpu_init(void){	int cpu;	if (smp_processor_id() == 0) {		for (cpu = 0; cpu < NR_CPUS; cpu++) {			per_cpu(local_per_cpu_offset, cpu) =				__per_cpu_offset[cpu];		}	}	return __per_cpu_start + __per_cpu_offset[smp_processor_id()];}/** * show_mem - give short summary of memory stats * * Shows a simple page count of reserved and used pages in the system. * For discontig machines, it does this on a per-pgdat basis. */void show_mem(void){	int i, total_reserved = 0;	int total_shared = 0, total_cached = 0;	unsigned long total_present = 0;	pg_data_t *pgdat;	printk("Mem-info:\n");	show_free_areas();	printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));	for_each_pgdat(pgdat) {		unsigned long present = pgdat->node_present_pages;		int shared = 0, cached = 0, reserved = 0;		printk("Node ID: %d\n", pgdat->node_id);		for(i = 0; i < pgdat->node_spanned_pages; i++) {			if (!ia64_pfn_valid(pgdat->node_start_pfn+i))				continue;			if (PageReserved(pgdat->node_mem_map+i))				reserved++;			else if (PageSwapCache(pgdat->node_mem_map+i))				cached++;			else if (page_count(pgdat->node_mem_map+i))				shared += page_count(pgdat->node_mem_map+i)-1;		}		total_present += present;		total_reserved += reserved;		total_cached += cached;		total_shared += shared;		printk("\t%ld pages of RAM\n", present);		printk("\t%d reserved pages\n", reserved);		printk("\t%d pages shared\n", shared);		printk("\t%d pages swap cached\n", cached);	}	printk("%ld pages of RAM\n", total_present);	printk("%d reserved pages\n", total_reserved);	printk("%d pages shared\n", total_shared);	printk("%d pages swap cached\n", total_cached);	printk("Total of %ld pages in page table cache\n", pgtable_cache_size);	printk("%d free buffer pages\n", nr_free_buffer_pages());}/** * call_pernode_memory - use SRAT to call callback functions with node info * @start: physical start of range * @len: length of range * @arg: function to call for each range * * efi_memmap_walk() knows nothing about layout of memory across nodes. Find * out to which node a block of memory belongs.  Ignore memory that we cannot * identify, and split blocks that run across multiple nodes. * * Take this opportunity to round the start address up and the end address * down to page boundaries. */void call_pernode_memory(unsigned long start, unsigned long len, void *arg){	unsigned long rs, re, end = start + len;	void (*func)(unsigned long, unsigned long, int);	int i;	start = PAGE_ALIGN(start);	end &= PAGE_MASK;	if (start >= end)		return;	func = arg;	if (!num_node_memblks) {		/* No SRAT table, so assume one node (node 0) */		if (start < end)			(*func)(start, end - start, 0);		return;	}	for (i = 0; i < num_node_memblks; i++) {		rs = max(start, node_memblk[i].start_paddr);		re = min(end, node_memblk[i].start_paddr +			 node_memblk[i].size);		if (rs < re)			(*func)(rs, re - rs, node_memblk[i].nid);		if (re == end)			break;	}}/** * count_node_pages - callback to build per-node memory info structures * @start: physical start of range * @len: length of range * @node: node where this range resides * * Each node has it's own number of physical pages, DMAable pages, start, and * end page frame number.  This routine will be called by call_pernode_memory() * for each piece of usable memory and will setup these values for each node. * Very similar to build_maps(). */static __init int count_node_pages(unsigned long start, unsigned long len, int node){	unsigned long end = start + len;	mem_data[node].num_physpages += len >> PAGE_SHIFT;	if (start <= __pa(MAX_DMA_ADDRESS))		mem_data[node].num_dma_physpages +=			(min(end, __pa(MAX_DMA_ADDRESS)) - start) >>PAGE_SHIFT;	start = GRANULEROUNDDOWN(start);	start = ORDERROUNDDOWN(start);	end = GRANULEROUNDUP(end);	mem_data[node].max_pfn = max(mem_data[node].max_pfn,				     end >> PAGE_SHIFT);	mem_data[node].min_pfn = min(mem_data[node].min_pfn,				     start >> PAGE_SHIFT);	return 0;}/** * paging_init - setup page tables * * paging_init() sets up the page tables for each node of the system and frees * the bootmem allocator memory for general use. */void __init paging_init(void){	unsigned long max_dma;	unsigned long zones_size[MAX_NR_ZONES];	unsigned long zholes_size[MAX_NR_ZONES];	unsigned long pfn_offset = 0;	int node;	max_dma = virt_to_phys((void *) MAX_DMA_ADDRESS) >> PAGE_SHIFT;	/* so min() will work in count_node_pages */	for_each_online_node(node)		mem_data[node].min_pfn = ~0UL;	efi_memmap_walk(filter_rsvd_memory, count_node_pages);	for_each_online_node(node) {		memset(zones_size, 0, sizeof(zones_size));		memset(zholes_size, 0, sizeof(zholes_size));		num_physpages += mem_data[node].num_physpages;		if (mem_data[node].min_pfn >= max_dma) {			/* All of this node's memory is above ZONE_DMA */			zones_size[ZONE_NORMAL] = mem_data[node].max_pfn -				mem_data[node].min_pfn;			zholes_size[ZONE_NORMAL] = mem_data[node].max_pfn -				mem_data[node].min_pfn -				mem_data[node].num_physpages;		} else if (mem_data[node].max_pfn < max_dma) {			/* All of this node's memory is in ZONE_DMA */			zones_size[ZONE_DMA] = mem_data[node].max_pfn -				mem_data[node].min_pfn;			zholes_size[ZONE_DMA] = mem_data[node].max_pfn -				mem_data[node].min_pfn -				mem_data[node].num_dma_physpages;		} else {			/* This node has memory in both zones */			zones_size[ZONE_DMA] = max_dma -				mem_data[node].min_pfn;			zholes_size[ZONE_DMA] = zones_size[ZONE_DMA] -				mem_data[node].num_dma_physpages;			zones_size[ZONE_NORMAL] = mem_data[node].max_pfn -				max_dma;			zholes_size[ZONE_NORMAL] = zones_size[ZONE_NORMAL] -				(mem_data[node].num_physpages -				 mem_data[node].num_dma_physpages);		}		if (node == 0) {			vmalloc_end -=				PAGE_ALIGN(max_low_pfn * sizeof(struct page));			vmem_map = (struct page *) vmalloc_end;			efi_memmap_walk(create_mem_map_page_table, NULL);			printk("Virtual mem_map starts at 0x%p\n", vmem_map);		}		pfn_offset = mem_data[node].min_pfn;		NODE_DATA(node)->node_mem_map = vmem_map + pfn_offset;		free_area_init_node(node, NODE_DATA(node), zones_size,				    pfn_offset, zholes_size);	}	zero_page_memmap_ptr = virt_to_page(ia64_imva(empty_zero_page));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -