1 #ifndef _X86_64_PGALLOC_H
2 #define _X86_64_PGALLOC_H
5 #include <linux/threads.h>
7 #include <linux/quicklist.h>
9 #define QUICK_PGD 0 /* We preserve special mappings over free */
10 #define QUICK_PT 1 /* Other page table pages that are zero on free */
12 #define pmd_populate_kernel(mm, pmd, pte) \
13 set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
14 #define pud_populate(mm, pud, pmd) \
15 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)))
16 #define pgd_populate(mm, pgd, pud) \
17 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)))
19 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
21 set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
24 static inline void pmd_free(pmd_t *pmd)
26 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
27 quicklist_free(QUICK_PT, NULL, pmd);
30 static inline pmd_t *pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
32 return (pmd_t *)quicklist_alloc(QUICK_PT, GFP_KERNEL|__GFP_REPEAT, NULL);
35 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
37 return (pud_t *)quicklist_alloc(QUICK_PT, GFP_KERNEL|__GFP_REPEAT, NULL);
40 static inline void pud_free (pud_t *pud)
42 BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
43 quicklist_free(QUICK_PT, NULL, pud);
46 static inline void pgd_list_add(pgd_t *pgd)
48 struct page *page = virt_to_page(pgd);
51 list_add(&page->lru, &pgd_list);
52 spin_unlock(&pgd_lock);
55 static inline void pgd_list_del(pgd_t *pgd)
57 struct page *page = virt_to_page(pgd);
61 spin_unlock(&pgd_lock);
64 static inline void pgd_ctor(void *x)
68 struct page *page = virt_to_page(pgd);
71 * Copy kernel pointers in from init.
73 boundary = pgd_index(__PAGE_OFFSET);
74 memcpy(pgd + boundary,
75 init_level4_pgt + boundary,
76 (PTRS_PER_PGD - boundary) * sizeof(pgd_t));
79 list_add(&page->lru, &pgd_list);
80 spin_unlock(&pgd_lock);
83 static inline void pgd_dtor(void *x)
86 struct page *page = virt_to_page(pgd);
90 spin_unlock(&pgd_lock);
93 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
95 pgd_t *pgd = (pgd_t *)quicklist_alloc(QUICK_PGD,
96 GFP_KERNEL|__GFP_REPEAT, pgd_ctor);
100 static inline void pgd_free(pgd_t *pgd)
102 BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
103 quicklist_free(QUICK_PGD, pgd_dtor, pgd);
106 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
108 return (pte_t *)quicklist_alloc(QUICK_PT, GFP_KERNEL|__GFP_REPEAT, NULL);
111 static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
113 void *p = (void *)quicklist_alloc(QUICK_PT, GFP_KERNEL|__GFP_REPEAT, NULL);
117 return virt_to_page(p);
120 /* Should really implement gc for free page table pages. This could be
121 done with a reference count in struct page. */
123 static inline void pte_free_kernel(pte_t *pte)
125 BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
126 quicklist_free(QUICK_PT, NULL, pte);
129 static inline void pte_free(struct page *pte)
131 quicklist_free_page(QUICK_PT, NULL, pte);
134 #define __pte_free_tlb(tlb,pte) quicklist_free_page(QUICK_PT, NULL,(pte))
136 #define __pmd_free_tlb(tlb,x) quicklist_free(QUICK_PT, NULL, (x))
137 #define __pud_free_tlb(tlb,x) quicklist_free(QUICK_PT, NULL, (x))
139 static inline void check_pgt_cache(void)
141 quicklist_trim(QUICK_PGD, pgd_dtor, 25, 16);
142 quicklist_trim(QUICK_PT, NULL, 25, 16);
144 #endif /* _X86_64_PGALLOC_H */