Matt Fleming | 2a5eacc | 2009-12-31 12:19:24 +0000 | [diff] [blame] | 1 | #include <linux/mm.h> |
| 2 | |
| 3 | #define PGALLOC_GFP GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO |
| 4 | |
| 5 | static struct kmem_cache *pgd_cachep; |
Paul Mundt | 782bb5a | 2010-01-13 19:11:14 +0900 | [diff] [blame^] | 6 | #if PAGETABLE_LEVELS > 2 |
Matt Fleming | 2a5eacc | 2009-12-31 12:19:24 +0000 | [diff] [blame] | 7 | static struct kmem_cache *pmd_cachep; |
| 8 | #endif |
| 9 | |
| 10 | void pgd_ctor(void *x) |
| 11 | { |
| 12 | pgd_t *pgd = x; |
| 13 | |
| 14 | memcpy(pgd + USER_PTRS_PER_PGD, |
| 15 | swapper_pg_dir + USER_PTRS_PER_PGD, |
| 16 | (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); |
| 17 | } |
| 18 | |
| 19 | void pgtable_cache_init(void) |
| 20 | { |
| 21 | pgd_cachep = kmem_cache_create("pgd_cache", |
| 22 | PTRS_PER_PGD * (1<<PTE_MAGNITUDE), |
| 23 | PAGE_SIZE, SLAB_PANIC, pgd_ctor); |
Paul Mundt | 782bb5a | 2010-01-13 19:11:14 +0900 | [diff] [blame^] | 24 | #if PAGETABLE_LEVELS > 2 |
Matt Fleming | 2a5eacc | 2009-12-31 12:19:24 +0000 | [diff] [blame] | 25 | pmd_cachep = kmem_cache_create("pmd_cache", |
| 26 | PTRS_PER_PMD * (1<<PTE_MAGNITUDE), |
| 27 | PAGE_SIZE, SLAB_PANIC, NULL); |
| 28 | #endif |
| 29 | } |
| 30 | |
| 31 | pgd_t *pgd_alloc(struct mm_struct *mm) |
| 32 | { |
| 33 | return kmem_cache_alloc(pgd_cachep, PGALLOC_GFP); |
| 34 | } |
| 35 | |
| 36 | void pgd_free(struct mm_struct *mm, pgd_t *pgd) |
| 37 | { |
| 38 | kmem_cache_free(pgd_cachep, pgd); |
| 39 | } |
| 40 | |
Paul Mundt | 782bb5a | 2010-01-13 19:11:14 +0900 | [diff] [blame^] | 41 | #if PAGETABLE_LEVELS > 2 |
Matt Fleming | 2a5eacc | 2009-12-31 12:19:24 +0000 | [diff] [blame] | 42 | void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) |
| 43 | { |
| 44 | set_pud(pud, __pud((unsigned long)pmd)); |
| 45 | } |
| 46 | |
| 47 | pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) |
| 48 | { |
| 49 | return kmem_cache_alloc(pmd_cachep, PGALLOC_GFP); |
| 50 | } |
| 51 | |
| 52 | void pmd_free(struct mm_struct *mm, pmd_t *pmd) |
| 53 | { |
| 54 | kmem_cache_free(pmd_cachep, pmd); |
| 55 | } |
Paul Mundt | 782bb5a | 2010-01-13 19:11:14 +0900 | [diff] [blame^] | 56 | #endif /* PAGETABLE_LEVELS > 2 */ |