diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-29 17:03:14 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-29 17:03:14 -0500 |
commit | c9cfcddfd65735437a4cb8563d6b66a6da8a5ed6 (patch) | |
tree | 618cdf37baafe8b283bcc9923d9dde89d6428fb5 /mm | |
parent | 4168f7a31801bba6acc18662978d24ec850bbbd0 (diff) |
VM: add common helper function to create the page tables
This logic was duplicated four times, for no good reason.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/fremap.c | 24 | ||||
-rw-r--r-- | mm/memory.c | 26 |
2 files changed, 16 insertions, 34 deletions
diff --git a/mm/fremap.c b/mm/fremap.c index f851775e09c2..9f381e58bf44 100644 --- a/mm/fremap.c +++ b/mm/fremap.c | |||
@@ -55,20 +55,10 @@ int install_page(struct mm_struct *mm, struct vm_area_struct *vma, | |||
55 | pgoff_t size; | 55 | pgoff_t size; |
56 | int err = -ENOMEM; | 56 | int err = -ENOMEM; |
57 | pte_t *pte; | 57 | pte_t *pte; |
58 | pmd_t *pmd; | ||
59 | pud_t *pud; | ||
60 | pgd_t *pgd; | ||
61 | pte_t pte_val; | 58 | pte_t pte_val; |
62 | spinlock_t *ptl; | 59 | spinlock_t *ptl; |
63 | 60 | ||
64 | pgd = pgd_offset(mm, addr); | 61 | pte = get_locked_pte(mm, addr, &ptl); |
65 | pud = pud_alloc(mm, pgd, addr); | ||
66 | if (!pud) | ||
67 | goto out; | ||
68 | pmd = pmd_alloc(mm, pud, addr); | ||
69 | if (!pmd) | ||
70 | goto out; | ||
71 | pte = pte_alloc_map_lock(mm, pmd, addr, &ptl); | ||
72 | if (!pte) | 62 | if (!pte) |
73 | goto out; | 63 | goto out; |
74 | 64 | ||
@@ -110,20 +100,10 @@ int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma, | |||
110 | { | 100 | { |
111 | int err = -ENOMEM; | 101 | int err = -ENOMEM; |
112 | pte_t *pte; | 102 | pte_t *pte; |
113 | pmd_t *pmd; | ||
114 | pud_t *pud; | ||
115 | pgd_t *pgd; | ||
116 | pte_t pte_val; | 103 | pte_t pte_val; |
117 | spinlock_t *ptl; | 104 | spinlock_t *ptl; |
118 | 105 | ||
119 | pgd = pgd_offset(mm, addr); | 106 | pte = get_locked_pte(mm, addr, &ptl); |
120 | pud = pud_alloc(mm, pgd, addr); | ||
121 | if (!pud) | ||
122 | goto out; | ||
123 | pmd = pmd_alloc(mm, pud, addr); | ||
124 | if (!pmd) | ||
125 | goto out; | ||
126 | pte = pte_alloc_map_lock(mm, pmd, addr, &ptl); | ||
127 | if (!pte) | 107 | if (!pte) |
128 | goto out; | 108 | goto out; |
129 | 109 | ||
diff --git a/mm/memory.c b/mm/memory.c index 990e7dc666f8..74f95ae0510b 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
@@ -1146,6 +1146,18 @@ int zeromap_page_range(struct vm_area_struct *vma, | |||
1146 | return err; | 1146 | return err; |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl) | ||
1150 | { | ||
1151 | pgd_t * pgd = pgd_offset(mm, addr); | ||
1152 | pud_t * pud = pud_alloc(mm, pgd, addr); | ||
1153 | if (pud) { | ||
1154 | pmd_t * pmd = pmd_alloc(mm, pgd, addr); | ||
1155 | if (pmd) | ||
1156 | return pte_alloc_map_lock(mm, pmd, addr, ptl); | ||
1157 | } | ||
1158 | return NULL; | ||
1159 | } | ||
1160 | |||
1149 | /* | 1161 | /* |
1150 | * This is the old fallback for page remapping. | 1162 | * This is the old fallback for page remapping. |
1151 | * | 1163 | * |
@@ -1156,10 +1168,7 @@ int zeromap_page_range(struct vm_area_struct *vma, | |||
1156 | static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *page, pgprot_t prot) | 1168 | static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *page, pgprot_t prot) |
1157 | { | 1169 | { |
1158 | int retval; | 1170 | int retval; |
1159 | pgd_t * pgd; | 1171 | pte_t *pte; |
1160 | pud_t * pud; | ||
1161 | pmd_t * pmd; | ||
1162 | pte_t * pte; | ||
1163 | spinlock_t *ptl; | 1172 | spinlock_t *ptl; |
1164 | 1173 | ||
1165 | retval = -EINVAL; | 1174 | retval = -EINVAL; |
@@ -1167,14 +1176,7 @@ static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *pa | |||
1167 | goto out; | 1176 | goto out; |
1168 | retval = -ENOMEM; | 1177 | retval = -ENOMEM; |
1169 | flush_dcache_page(page); | 1178 | flush_dcache_page(page); |
1170 | pgd = pgd_offset(mm, addr); | 1179 | pte = get_locked_pte(mm, addr, &ptl); |
1171 | pud = pud_alloc(mm, pgd, addr); | ||
1172 | if (!pud) | ||
1173 | goto out; | ||
1174 | pmd = pmd_alloc(mm, pud, addr); | ||
1175 | if (!pmd) | ||
1176 | goto out; | ||
1177 | pte = pte_alloc_map_lock(mm, pmd, addr, &ptl); | ||
1178 | if (!pte) | 1180 | if (!pte) |
1179 | goto out; | 1181 | goto out; |
1180 | retval = -EBUSY; | 1182 | retval = -EBUSY; |