blob: 369cf065b6a48f78f9870ddaf9f27e59b6980c0c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/sched.h>
2#include <linux/kernel.h>
3#include <linux/errno.h>
4#include <linux/mm.h>
Prarit Bhargava27eb0b22007-10-17 18:04:34 +02005#include <linux/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#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>
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -070012#include <linux/module.h>
Christoph Lameterf1d1a842007-05-12 11:15:24 -070013#include <linux/quicklist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
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
23void 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;
Dave Hansen208d54e2005-10-29 18:16:52 -070031 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Christophe Lucasf90e7182005-06-25 14:59:24 -070033 printk(KERN_INFO "Mem-info:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 show_free_areas();
KAMEZAWA Hiroyukiec936fc2006-03-27 01:15:59 -080035 for_each_online_pgdat(pgdat) {
Dave Hansen208d54e2005-10-29 18:16:52 -070036 pgdat_resize_lock(pgdat, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 for (i = 0; i < pgdat->node_spanned_pages; ++i) {
Prarit Bhargava27eb0b22007-10-17 18:04:34 +020038 if (unlikely(i % MAX_ORDER_NR_PAGES == 0))
39 touch_nmi_watchdog();
Dave Hansen408fde82005-06-23 00:07:37 -070040 page = pgdat_page_nr(pgdat, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 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 }
Dave Hansen208d54e2005-10-29 18:16:52 -070051 pgdat_resize_unlock(pgdat, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 }
Christophe Lucasf90e7182005-06-25 14:59:24 -070053 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);
Martin J. Bligh6f4e1e52005-06-23 00:08:08 -070058
Christoph Lameterb1e7a8f2006-06-30 01:55:39 -070059 printk(KERN_INFO "%lu pages dirty\n", global_page_state(NR_FILE_DIRTY));
Christoph Lameterce866b32006-06-30 01:55:40 -070060 printk(KERN_INFO "%lu pages writeback\n",
61 global_page_state(NR_WRITEBACK));
Christoph Lameter65ba55f2006-06-30 01:55:34 -070062 printk(KERN_INFO "%lu pages mapped\n", global_page_state(NR_FILE_MAPPED));
Christoph Lameter972d1a72006-09-25 23:31:51 -070063 printk(KERN_INFO "%lu pages slab\n",
64 global_page_state(NR_SLAB_RECLAIMABLE) +
65 global_page_state(NR_SLAB_UNRECLAIMABLE));
Christoph Lameterdf849a12006-06-30 01:55:38 -070066 printk(KERN_INFO "%lu pages pagetables\n",
67 global_page_state(NR_PAGETABLE));
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
70/*
71 * Associate a virtual page frame with a given physical page frame
72 * and protection flags for that frame.
73 */
74static void set_pte_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
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);
Jan Beulichb0bfece2006-12-07 02:14:09 +010097 if (pgprot_val(flags))
Jan Beulichaa506dc2007-10-17 18:04:33 +020098 set_pte_present(&init_mm, vaddr, pte, pfn_pte(pfn, flags));
Jan Beulichb0bfece2006-12-07 02:14:09 +010099 else
100 pte_clear(&init_mm, vaddr, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
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 */
115void 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 */
Christophe Lucasf90e7182005-06-25 14:59:24 -0700122 printk(KERN_WARNING "set_pmd_pfn: vaddr misaligned\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return; /* BUG(); */
124 }
125 if (pfn & (PTRS_PER_PTE-1)) { /* pfn is misaligned */
Christophe Lucasf90e7182005-06-25 14:59:24 -0700126 printk(KERN_WARNING "set_pmd_pfn: pfn misaligned\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return; /* BUG(); */
128 }
129 pgd = swapper_pg_dir + pgd_index(vaddr);
130 if (pgd_none(*pgd)) {
Christophe Lucasf90e7182005-06-25 14:59:24 -0700131 printk(KERN_WARNING "set_pmd_pfn: pgd_none\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 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
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700144static int fixmaps;
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700145unsigned long __FIXADDR_TOP = 0xfffff000;
146EXPORT_SYMBOL(__FIXADDR_TOP);
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
149{
150 unsigned long address = __fix_to_virt(idx);
151
152 if (idx >= __end_of_fixed_addresses) {
153 BUG();
154 return;
155 }
156 set_pte_pfn(address, phys >> PAGE_SHIFT, flags);
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700157 fixmaps++;
158}
159
160/**
161 * reserve_top_address - reserves a hole in the top of kernel address space
162 * @reserve - size of hole to reserve
163 *
164 * Can be used to relocate the fixmap area and poke a hole in the top
165 * of kernel address space to make room for a hypervisor.
166 */
167void reserve_top_address(unsigned long reserve)
168{
169 BUG_ON(fixmaps > 0);
Zachary Amsden7ce0bcf2007-02-13 13:26:21 +0100170 printk(KERN_INFO "Reserving virtual address space above 0x%08x\n",
171 (int)-reserve);
Jeremy Fitzhardinge052e7992006-09-25 23:32:25 -0700172 __FIXADDR_TOP = -reserve - PAGE_SIZE;
173 __VMALLOC_RESERVE += reserve;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}