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

📄 init.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/arch/arm/mm/init.c * *  Copyright (C) 1995-2000 Russell King * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */#include <linux/config.h>#include <linux/signal.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/types.h>#include <linux/ptrace.h>#include <linux/mman.h>#include <linux/mm.h>#include <linux/swap.h>#include <linux/swapctl.h>#include <linux/smp.h>#include <linux/init.h>#include <linux/bootmem.h>#include <linux/blk.h>#include <asm/segment.h>#include <asm/mach-types.h>#include <asm/pgalloc.h>#include <asm/dma.h>#include <asm/hardware.h>#include <asm/setup.h>#include <asm/mach/arch.h>#include <asm/mach/map.h>#ifndef CONFIG_DISCONTIGMEM#define NR_NODES	1#else#define NR_NODES	4#endif#ifdef CONFIG_CPU_32#define TABLE_OFFSET	(PTRS_PER_PTE)#else#define TABLE_OFFSET	0#endif#define TABLE_SIZE	((TABLE_OFFSET + PTRS_PER_PTE) * sizeof(void *))static unsigned long totalram_pages;pgd_t swapper_pg_dir[PTRS_PER_PGD];extern char _stext, _text, _etext, _end, __init_begin, __init_end;/* * The sole use of this is to pass memory configuration * data from paging_init to mem_init. */static struct meminfo meminfo __initdata = { 0, };/* * empty_bad_page is the page that is used for page faults when * linux is out-of-memory. Older versions of linux just did a * do_exit(), but using this instead means there is less risk * for a process dying in kernel mode, possibly leaving a inode * unused etc.. * * empty_bad_pte_table is the accompanying page-table: it is * initialized to point to BAD_PAGE entries. * * empty_zero_page is a special page that is used for * zero-initialized data and COW. */struct page *empty_zero_page;struct page *empty_bad_page;pte_t *empty_bad_pte_table;pte_t *get_bad_pte_table(void){	pte_t v;	int i;	v = pte_mkdirty(mk_pte(empty_bad_page, PAGE_SHARED));	for (i = 0; i < PTRS_PER_PTE; i++)		set_pte(empty_bad_pte_table + i, v);	return empty_bad_pte_table;}void __handle_bad_pmd(pmd_t *pmd){	pmd_ERROR(*pmd);#ifdef CONFIG_DEBUG_ERRORS	__backtrace();#endif	set_pmd(pmd, mk_user_pmd(get_bad_pte_table()));}void __handle_bad_pmd_kernel(pmd_t *pmd){	pmd_ERROR(*pmd);#ifdef CONFIG_DEBUG_ERRORS	__backtrace();#endif	set_pmd(pmd, mk_kernel_pmd(get_bad_pte_table()));}#ifndef CONFIG_NO_PGT_CACHEstruct pgtable_cache_struct quicklists;int do_check_pgt_cache(int low, int high){	int freed = 0;	if(pgtable_cache_size > high) {		do {			if(pgd_quicklist) {				free_pgd_slow(get_pgd_fast());				freed++;			}			if(pmd_quicklist) {				free_pmd_slow(get_pmd_fast());				freed++;			}			if(pte_quicklist) {				free_pte_slow(get_pte_fast());				 freed++;			}		} while(pgtable_cache_size > low);	}	return freed;}#elseint do_check_pgt_cache(int low, int high){	return 0;}#endifvoid show_mem(void){	int free = 0, total = 0, reserved = 0;	int shared = 0, cached = 0, node;	printk("Mem-info:\n");	show_free_areas();	printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));	for (node = 0; node < numnodes; node++) {		struct page *page, *end;		page = NODE_MEM_MAP(node);		end  = page + NODE_DATA(node)->node_size;		do {/* This is currently broken * PG_skip is used on sparc/sparc64 architectures to "skip" certain * parts of the address space. * * #define PG_skip	10 * #define PageSkip(page) (machine_is_riscpc() && test_bit(PG_skip, &(page)->flags)) *			if (PageSkip(page)) { *				page = page->next_hash; *				if (page == NULL) *					break; *			} */			total++;			if (PageReserved(page))				reserved++;			else if (PageSwapCache(page))				cached++;			else if (!page_count(page))				free++;			else				shared += atomic_read(&page->count) - 1;			page++;		} while (page < end);	}	printk("%d pages of RAM\n", total);	printk("%d free pages\n", free);	printk("%d reserved pages\n", reserved);	printk("%d pages shared\n", shared);	printk("%d pages swap cached\n", cached);#ifndef CONFIG_NO_PGT_CACHE	printk("%ld page tables cached\n", pgtable_cache_size);#endif	show_buffers();}struct node_info {	unsigned int start;	unsigned int end;	int bootmap_pages;};#define O_PFN_DOWN(x)	((x) >> PAGE_SHIFT)#define V_PFN_DOWN(x)	O_PFN_DOWN(__pa(x))#define O_PFN_UP(x)	(PAGE_ALIGN(x) >> PAGE_SHIFT)#define V_PFN_UP(x)	O_PFN_UP(__pa(x))#define PFN_SIZE(x)	((x) >> PAGE_SHIFT)#define PFN_RANGE(s,e)	PFN_SIZE(PAGE_ALIGN((unsigned long)(e)) - \				(((unsigned long)(s)) & PAGE_MASK))/* * FIXME: We really want to avoid allocating the bootmap bitmap * over the top of the initrd.  Hopefully, this is located towards * the start of a bank, so if we allocate the bootmap bitmap at * the end, we won't clash. */static unsigned int __initfind_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages){	unsigned int start_pfn, bank, bootmap_pfn;	start_pfn   = V_PFN_UP(&_end);	bootmap_pfn = 0;	for (bank = 0; bank < mi->nr_banks; bank ++) {		unsigned int start, end;		if (mi->bank[bank].node != node)			continue;		start = O_PFN_UP(mi->bank[bank].start);		end   = O_PFN_DOWN(mi->bank[bank].size +				   mi->bank[bank].start);		if (end < start_pfn)			continue;		if (start < start_pfn)			start = start_pfn;		if (end <= start)			continue;		if (end - start >= bootmap_pages) {			bootmap_pfn = start;			break;		}	}	if (bootmap_pfn == 0)		BUG();	return bootmap_pfn;}/* * Scan the memory info structure and pull out: *  - the end of memory *  - the number of nodes *  - the pfn range of each node *  - the number of bootmem bitmap pages */static unsigned int __initfind_memend_and_nodes(struct meminfo *mi, struct node_info *np){	unsigned int i, bootmem_pages = 0, memend_pfn = 0;	for (i = 0; i < NR_NODES; i++) {		np[i].start = -1U;		np[i].end = 0;		np[i].bootmap_pages = 0;	}	for (i = 0; i < mi->nr_banks; i++) {		unsigned long start, end;		int node;		if (mi->bank[i].size == 0) {			/*			 * Mark this bank with an invalid node number			 */			mi->bank[i].node = -1;			continue;		}		node = mi->bank[i].node;		if (node >= numnodes) {			numnodes = node + 1;			/*			 * Make sure we haven't exceeded the maximum number			 * of nodes that we have in this configuration.  If			 * we have, we're in trouble.  (maybe we ought to			 * limit, instead of bugging?)			 */			if (numnodes > NR_NODES)				BUG();		}		/*		 * Get the start and end pfns for this bank		 */		start = O_PFN_UP(mi->bank[i].start);		end   = O_PFN_DOWN(mi->bank[i].start + mi->bank[i].size);		if (np[node].start > start)			np[node].start = start;		if (np[node].end < end)			np[node].end = end;		if (memend_pfn < end)			memend_pfn = end;	}	/*	 * Calculate the number of pages we require to	 * store the bootmem bitmaps.	 */	for (i = 0; i < numnodes; i++) {		if (np[i].end == 0)			continue;		np[i].bootmap_pages = bootmem_bootmap_pages(np[i].end -							    np[i].start);		bootmem_pages += np[i].bootmap_pages;	}	/*	 * This doesn't seem to be used by the Linux memory	 * manager any more.  If we can get rid of it, we	 * also get rid of some of the stuff above as well.	 */	max_low_pfn = memend_pfn - O_PFN_DOWN(PHYS_OFFSET);	mi->end = memend_pfn << PAGE_SHIFT;	return bootmem_pages;}static int __init check_initrd(struct meminfo *mi){	int initrd_node = -2;#ifdef CONFIG_BLK_DEV_INITRD

⌨️ 快捷键说明

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