Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/sched.h> |
2 | #include <linux/kernel.h> | |
3 | #include <linux/errno.h> | |
4 | #include <linux/mm.h> | |
27eb0b28 | 5 | #include <linux/nmi.h> |
1da177e4 LT |
6 | #include <linux/swap.h> |
7 | #include <linux/smp.h> | |
8 | #include <linux/highmem.h> | |
9 | #include <linux/slab.h> | |
10 | #include <linux/pagemap.h> | |
11 | #include <linux/spinlock.h> | |
052e7994 | 12 | #include <linux/module.h> |
f1d1a842 | 13 | #include <linux/quicklist.h> |
1da177e4 LT |
14 | |
15 | #include <asm/system.h> | |
16 | #include <asm/pgtable.h> | |
17 | #include <asm/pgalloc.h> | |
18 | #include <asm/fixmap.h> | |
19 | #include <asm/e820.h> | |
20 | #include <asm/tlb.h> | |
21 | #include <asm/tlbflush.h> | |
22 | ||
23 | void show_mem(void) | |
24 | { | |
25 | int total = 0, reserved = 0; | |
26 | int shared = 0, cached = 0; | |
27 | int highmem = 0; | |
28 | struct page *page; | |
29 | pg_data_t *pgdat; | |
30 | unsigned long i; | |
208d54e5 | 31 | unsigned long flags; |
1da177e4 | 32 | |
f90e7185 | 33 | printk(KERN_INFO "Mem-info:\n"); |
1da177e4 | 34 | show_free_areas(); |
ec936fc5 | 35 | for_each_online_pgdat(pgdat) { |
208d54e5 | 36 | pgdat_resize_lock(pgdat, &flags); |
1da177e4 | 37 | for (i = 0; i < pgdat->node_spanned_pages; ++i) { |
27eb0b28 PB |
38 | if (unlikely(i % MAX_ORDER_NR_PAGES == 0)) |
39 | touch_nmi_watchdog(); | |
408fde81 | 40 | page = pgdat_page_nr(pgdat, i); |
1da177e4 LT |
41 | total++; |
42 | if (PageHighMem(page)) | |
43 | highmem++; | |
44 | if (PageReserved(page)) | |
45 | reserved++; | |
46 | else if (PageSwapCache(page)) | |
47 | cached++; | |
48 | else if (page_count(page)) | |
49 | shared += page_count(page) - 1; | |
50 | } | |
208d54e5 | 51 | pgdat_resize_unlock(pgdat, &flags); |
1da177e4 | 52 | } |
f90e7185 CL |
53 | printk(KERN_INFO "%d pages of RAM\n", total); |
54 | printk(KERN_INFO "%d pages of HIGHMEM\n", highmem); | |
55 | printk(KERN_INFO "%d reserved pages\n", reserved); | |
56 | printk(KERN_INFO "%d pages shared\n", shared); | |
57 | printk(KERN_INFO "%d pages swap cached\n", cached); | |
6f4e1e50 | 58 | |
b1e7a8fd | 59 | printk(KERN_INFO "%lu pages dirty\n", global_page_state(NR_FILE_DIRTY)); |
ce866b34 CL |
60 | printk(KERN_INFO "%lu pages writeback\n", |
61 | global_page_state(NR_WRITEBACK)); | |
65ba55f5 | 62 | printk(KERN_INFO "%lu pages mapped\n", global_page_state(NR_FILE_MAPPED)); |
972d1a7b CL |
63 | printk(KERN_INFO "%lu pages slab\n", |
64 | global_page_state(NR_SLAB_RECLAIMABLE) + | |
65 | global_page_state(NR_SLAB_UNRECLAIMABLE)); | |
df849a15 CL |
66 | printk(KERN_INFO "%lu pages pagetables\n", |
67 | global_page_state(NR_PAGETABLE)); | |
1da177e4 LT |
68 | } |
69 | ||
70 | /* | |
71 | * Associate a virtual page frame with a given physical page frame | |
72 | * and protection flags for that frame. | |
73 | */ | |
d494a961 | 74 | void set_pte_vaddr(unsigned long vaddr, pte_t pteval) |
1da177e4 LT |
75 | { |
76 | pgd_t *pgd; | |
77 | pud_t *pud; | |
78 | pmd_t *pmd; | |
79 | pte_t *pte; | |
80 | ||
81 | pgd = swapper_pg_dir + pgd_index(vaddr); | |
82 | if (pgd_none(*pgd)) { | |
83 | BUG(); | |
84 | return; | |
85 | } | |
86 | pud = pud_offset(pgd, vaddr); | |
87 | if (pud_none(*pud)) { | |
88 | BUG(); | |
89 | return; | |
90 | } | |
91 | pmd = pmd_offset(pud, vaddr); | |
92 | if (pmd_none(*pmd)) { | |
93 | BUG(); | |
94 | return; | |
95 | } | |
96 | pte = pte_offset_kernel(pmd, vaddr); | |
d494a961 JF |
97 | if (pte_val(pteval)) |
98 | set_pte_present(&init_mm, vaddr, pte, pteval); | |
b0bfece4 JB |
99 | else |
100 | pte_clear(&init_mm, vaddr, pte); | |
1da177e4 LT |
101 | |
102 | /* | |
103 | * It's enough to flush this one mapping. | |
104 | * (PGE mappings get flushed as well) | |
105 | */ | |
106 | __flush_tlb_one(vaddr); | |
107 | } | |
108 | ||
109 | /* | |
110 | * Associate a large virtual page frame with a given physical page frame | |
111 | * and protection flags for that frame. pfn is for the base of the page, | |
112 | * vaddr is what the page gets mapped to - both must be properly aligned. | |
113 | * The pmd must already be instantiated. Assumes PAE mode. | |
114 | */ | |
115 | void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags) | |
116 | { | |
117 | pgd_t *pgd; | |
118 | pud_t *pud; | |
119 | pmd_t *pmd; | |
120 | ||
121 | if (vaddr & (PMD_SIZE-1)) { /* vaddr is misaligned */ | |
f90e7185 | 122 | printk(KERN_WARNING "set_pmd_pfn: vaddr misaligned\n"); |
1da177e4 LT |
123 | return; /* BUG(); */ |
124 | } | |
125 | if (pfn & (PTRS_PER_PTE-1)) { /* pfn is misaligned */ | |
f90e7185 | 126 | printk(KERN_WARNING "set_pmd_pfn: pfn misaligned\n"); |
1da177e4 LT |
127 | return; /* BUG(); */ |
128 | } | |
129 | pgd = swapper_pg_dir + pgd_index(vaddr); | |
130 | if (pgd_none(*pgd)) { | |
f90e7185 | 131 | printk(KERN_WARNING "set_pmd_pfn: pgd_none\n"); |
1da177e4 LT |
132 | return; /* BUG(); */ |
133 | } | |
134 | pud = pud_offset(pgd, vaddr); | |
135 | pmd = pmd_offset(pud, vaddr); | |
136 | set_pmd(pmd, pfn_pmd(pfn, flags)); | |
137 | /* | |
138 | * It's enough to flush this one mapping. | |
139 | * (PGE mappings get flushed as well) | |
140 | */ | |
141 | __flush_tlb_one(vaddr); | |
142 | } | |
143 | ||
052e7994 JF |
144 | unsigned long __FIXADDR_TOP = 0xfffff000; |
145 | EXPORT_SYMBOL(__FIXADDR_TOP); | |
052e7994 | 146 | |
052e7994 JF |
147 | /** |
148 | * reserve_top_address - reserves a hole in the top of kernel address space | |
149 | * @reserve - size of hole to reserve | |
150 | * | |
151 | * Can be used to relocate the fixmap area and poke a hole in the top | |
152 | * of kernel address space to make room for a hypervisor. | |
153 | */ | |
bef1568d | 154 | void __init reserve_top_address(unsigned long reserve) |
052e7994 | 155 | { |
7c7e6e07 | 156 | BUG_ON(fixmaps_set > 0); |
7ce0bcfd ZA |
157 | printk(KERN_INFO "Reserving virtual address space above 0x%08x\n", |
158 | (int)-reserve); | |
052e7994 JF |
159 | __FIXADDR_TOP = -reserve - PAGE_SIZE; |
160 | __VMALLOC_RESERVE += reserve; | |
1da177e4 | 161 | } |
bef1568d YL |
162 | |
163 | /* | |
164 | * vmalloc=size forces the vmalloc area to be exactly 'size' | |
165 | * bytes. This can be used to increase (or decrease) the | |
166 | * vmalloc area - the default is 128m. | |
167 | */ | |
168 | static int __init parse_vmalloc(char *arg) | |
169 | { | |
170 | if (!arg) | |
171 | return -EINVAL; | |
172 | ||
173 | __VMALLOC_RESERVE = memparse(arg, &arg); | |
174 | return 0; | |
175 | } | |
176 | early_param("vmalloc", parse_vmalloc); | |
177 | ||
178 | /* | |
179 | * reservetop=size reserves a hole at the top of the kernel address space which | |
180 | * a hypervisor can load into later. Needed for dynamically loaded hypervisors, | |
181 | * so relocating the fixmap can be done before paging initialization. | |
182 | */ | |
183 | static int __init parse_reservetop(char *arg) | |
184 | { | |
185 | unsigned long address; | |
186 | ||
187 | if (!arg) | |
188 | return -EINVAL; | |
189 | ||
190 | address = memparse(arg, &arg); | |
191 | reserve_top_address(address); | |
192 | return 0; | |
193 | } | |
194 | early_param("reservetop", parse_reservetop); |