ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-ppc64 / pgalloc.h
1 #ifndef _PPC64_PGALLOC_H
2 #define _PPC64_PGALLOC_H
3
4 #include <linux/mm.h>
5 #include <linux/slab.h>
6 #include <linux/cpumask.h>
7 #include <linux/percpu.h>
8 #include <asm/processor.h>
9 #include <asm/tlb.h>
10
11 extern kmem_cache_t *zero_cache;
12
13 /*
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version
17  * 2 of the License, or (at your option) any later version.
18  */
19
20 static inline pgd_t *
21 pgd_alloc(struct mm_struct *mm)
22 {
23         return kmem_cache_alloc(zero_cache, GFP_KERNEL);
24 }
25
26 static inline void
27 pgd_free(pgd_t *pgd)
28 {
29         kmem_cache_free(zero_cache, pgd);
30 }
31
32 #define pgd_populate(MM, PGD, PMD)      pgd_set(PGD, PMD)
33
34 static inline pmd_t *
35 pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
36 {
37         return kmem_cache_alloc(zero_cache, GFP_KERNEL|__GFP_REPEAT);
38 }
39
40 static inline void
41 pmd_free(pmd_t *pmd)
42 {
43         kmem_cache_free(zero_cache, pmd);
44 }
45
46 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, pte)
47 #define pmd_populate(mm, pmd, pte_page) \
48         pmd_populate_kernel(mm, pmd, page_address(pte_page))
49
50 static inline pte_t *
51 pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
52 {
53         return kmem_cache_alloc(zero_cache, GFP_KERNEL|__GFP_REPEAT);
54 }
55
56 static inline struct page *
57 pte_alloc_one(struct mm_struct *mm, unsigned long address)
58 {
59         pte_t *pte = pte_alloc_one_kernel(mm, address);
60
61         if (pte)
62                 return virt_to_page(pte);
63
64         return NULL;
65 }
66                 
67 static inline void pte_free_kernel(pte_t *pte)
68 {
69         kmem_cache_free(zero_cache, pte);
70 }
71
72 #define pte_free(pte_page)      pte_free_kernel(page_address(pte_page))
73
74 struct pte_freelist_batch
75 {
76         struct rcu_head rcu;
77         unsigned int    index;
78         struct page *   pages[0];
79 };
80
81 #define PTE_FREELIST_SIZE       ((PAGE_SIZE - sizeof(struct pte_freelist_batch)) / \
82                                   sizeof(struct page *))
83
84 extern void pte_free_now(struct page *ptepage);
85 extern void pte_free_submit(struct pte_freelist_batch *batch);
86
87 DECLARE_PER_CPU(struct pte_freelist_batch *, pte_freelist_cur);
88
89 static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *ptepage)
90 {
91         /* This is safe as we are holding page_table_lock */
92         cpumask_t local_cpumask = cpumask_of_cpu(smp_processor_id());
93         struct pte_freelist_batch **batchp = &__get_cpu_var(pte_freelist_cur);
94
95         if (atomic_read(&tlb->mm->mm_users) < 2 ||
96             cpus_equal(tlb->mm->cpu_vm_mask, local_cpumask)) {
97                 pte_free(ptepage);
98                 return;
99         }
100
101         if (*batchp == NULL) {
102                 *batchp = (struct pte_freelist_batch *)__get_free_page(GFP_ATOMIC);
103                 if (*batchp == NULL) {
104                         pte_free_now(ptepage);
105                         return;
106                 }
107                 (*batchp)->index = 0;
108         }
109         (*batchp)->pages[(*batchp)->index++] = ptepage;
110         if ((*batchp)->index == PTE_FREELIST_SIZE) {
111                 pte_free_submit(*batchp);
112                 *batchp = NULL;
113         }
114 }
115
116 #define __pmd_free_tlb(tlb, pmd)        __pte_free_tlb(tlb, virt_to_page(pmd))
117
118 #define check_pgt_cache()       do { } while (0)
119
120 #endif /* _PPC64_PGALLOC_H */