VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-ia64 / pgalloc.h
1 #ifndef _ASM_IA64_PGALLOC_H
2 #define _ASM_IA64_PGALLOC_H
3
4 /*
5  * This file contains the functions and defines necessary to allocate
6  * page tables.
7  *
8  * This hopefully works with any (fixed) ia-64 page-size, as defined
9  * in <asm/page.h> (currently 8192).
10  *
11  * Copyright (C) 1998-2001 Hewlett-Packard Co
12  *      David Mosberger-Tang <davidm@hpl.hp.com>
13  * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
14  */
15
16 #include <linux/config.h>
17
18 #include <linux/compiler.h>
19 #include <linux/mm.h>
20 #include <linux/page-flags.h>
21 #include <linux/threads.h>
22
23 #include <asm/mmu_context.h>
24 #include <asm/processor.h>
25
26 /*
27  * Very stupidly, we used to get new pgd's and pmd's, init their contents
28  * to point to the NULL versions of the next level page table, later on
29  * completely re-init them the same way, then free them up.  This wasted
30  * a lot of work and caused unnecessary memory traffic.  How broken...
31  * We fix this by caching them.
32  */
33 #define pgd_quicklist           (local_cpu_data->pgd_quick)
34 #define pmd_quicklist           (local_cpu_data->pmd_quick)
35 #define pgtable_cache_size      (local_cpu_data->pgtable_cache_sz)
36
37 static inline pgd_t*
38 pgd_alloc_one_fast (struct mm_struct *mm)
39 {
40         unsigned long *ret = NULL;
41
42         preempt_disable();
43
44         ret = pgd_quicklist;
45         if (likely(ret != NULL)) {
46                 pgd_quicklist = (unsigned long *)(*ret);
47                 ret[0] = 0;
48                 --pgtable_cache_size;
49         } else
50                 ret = NULL;
51
52         preempt_enable();
53
54         return (pgd_t *) ret;
55 }
56
57 static inline pgd_t*
58 pgd_alloc (struct mm_struct *mm)
59 {
60         /* the VM system never calls pgd_alloc_one_fast(), so we do it here. */
61         pgd_t *pgd = pgd_alloc_one_fast(mm);
62
63         if (unlikely(pgd == NULL)) {
64                 pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
65                 if (likely(pgd != NULL))
66                         clear_page(pgd);
67         }
68         return pgd;
69 }
70
71 static inline void
72 pgd_free (pgd_t *pgd)
73 {
74         preempt_disable();
75         *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
76         pgd_quicklist = (unsigned long *) pgd;
77         ++pgtable_cache_size;
78         preempt_enable();
79 }
80
81 static inline void
82 pgd_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd)
83 {
84         pgd_val(*pgd_entry) = __pa(pmd);
85 }
86
87
88 static inline pmd_t*
89 pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
90 {
91         unsigned long *ret = NULL;
92
93         preempt_disable();
94
95         ret = (unsigned long *)pmd_quicklist;
96         if (likely(ret != NULL)) {
97                 pmd_quicklist = (unsigned long *)(*ret);
98                 ret[0] = 0;
99                 --pgtable_cache_size;
100         }
101
102         preempt_enable();
103
104         return (pmd_t *)ret;
105 }
106
107 static inline pmd_t*
108 pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
109 {
110         pmd_t *pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
111
112         if (likely(pmd != NULL))
113                 clear_page(pmd);
114         return pmd;
115 }
116
117 static inline void
118 pmd_free (pmd_t *pmd)
119 {
120         preempt_disable();
121         *(unsigned long *)pmd = (unsigned long) pmd_quicklist;
122         pmd_quicklist = (unsigned long *) pmd;
123         ++pgtable_cache_size;
124         preempt_enable();
125 }
126
127 #define __pmd_free_tlb(tlb, pmd)        pmd_free(pmd)
128
129 static inline void
130 pmd_populate (struct mm_struct *mm, pmd_t *pmd_entry, struct page *pte)
131 {
132         pmd_val(*pmd_entry) = page_to_phys(pte);
133 }
134
135 static inline void
136 pmd_populate_kernel (struct mm_struct *mm, pmd_t *pmd_entry, pte_t *pte)
137 {
138         pmd_val(*pmd_entry) = __pa(pte);
139 }
140
141 static inline struct page *
142 pte_alloc_one (struct mm_struct *mm, unsigned long addr)
143 {
144         struct page *pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
145
146         if (likely(pte != NULL))
147                 clear_page(page_address(pte));
148         return pte;
149 }
150
151 static inline pte_t *
152 pte_alloc_one_kernel (struct mm_struct *mm, unsigned long addr)
153 {
154         pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
155
156         if (likely(pte != NULL))
157                 clear_page(pte);
158         return pte;
159 }
160
161 static inline void
162 pte_free (struct page *pte)
163 {
164         __free_page(pte);
165 }
166
167 static inline void
168 pte_free_kernel (pte_t *pte)
169 {
170         free_page((unsigned long) pte);
171 }
172
173 #define __pte_free_tlb(tlb, pte)        tlb_remove_page((tlb), (pte))
174
175 extern void check_pgt_cache (void);
176
177 #endif /* _ASM_IA64_PGALLOC_H */