aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/mlock.c')
-rw-r--r--mm/mlock.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/mm/mlock.c b/mm/mlock.c
index 22041aa9f5c1..bd6f0e466f6c 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -198,17 +198,26 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
198 for (i = 0; i < ret; i++) { 198 for (i = 0; i < ret; i++) {
199 struct page *page = pages[i]; 199 struct page *page = pages[i];
200 200
201 lock_page(page); 201 if (page->mapping) {
202 /* 202 /*
203 * Because we lock page here and migration is blocked 203 * That preliminary check is mainly to avoid
204 * by the elevated reference, we need only check for 204 * the pointless overhead of lock_page on the
205 * file-cache page truncation. This page->mapping 205 * ZERO_PAGE: which might bounce very badly if
206 * check also neatly skips over the ZERO_PAGE(), 206 * there is contention. However, we're still
207 * though if that's common we'd prefer not to lock it. 207 * dirtying its cacheline with get/put_page:
208 */ 208 * we'll add another __get_user_pages flag to
209 if (page->mapping) 209 * avoid it if that case turns out to matter.
210 mlock_vma_page(page); 210 */
211 unlock_page(page); 211 lock_page(page);
212 /*
213 * Because we lock page here and migration is
214 * blocked by the elevated reference, we need
215 * only check for file-cache page truncation.
216 */
217 if (page->mapping)
218 mlock_vma_page(page);
219 unlock_page(page);
220 }
212 put_page(page); /* ref from get_user_pages() */ 221 put_page(page); /* ref from get_user_pages() */
213 } 222 }
214 223
@@ -309,9 +318,23 @@ void munlock_vma_pages_range(struct vm_area_struct *vma,
309 vma->vm_flags &= ~VM_LOCKED; 318 vma->vm_flags &= ~VM_LOCKED;
310 319
311 for (addr = start; addr < end; addr += PAGE_SIZE) { 320 for (addr = start; addr < end; addr += PAGE_SIZE) {
312 struct page *page = follow_page(vma, addr, FOLL_GET); 321 struct page *page;
313 if (page) { 322 /*
323 * Although FOLL_DUMP is intended for get_dump_page(),
324 * it just so happens that its special treatment of the
325 * ZERO_PAGE (returning an error instead of doing get_page)
326 * suits munlock very well (and if somehow an abnormal page
327 * has sneaked into the range, we won't oops here: great).
328 */
329 page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
330 if (page && !IS_ERR(page)) {
314 lock_page(page); 331 lock_page(page);
332 /*
333 * Like in __mlock_vma_pages_range(),
334 * because we lock page here and migration is
335 * blocked by the elevated reference, we need
336 * only check for file-cache page truncation.
337 */
315 if (page->mapping) 338 if (page->mapping)
316 munlock_vma_page(page); 339 munlock_vma_page(page);
317 unlock_page(page); 340 unlock_page(page);