pgtable.c 1.3 KB

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