diff options
author | Hugh Dickins <hugh.dickins@tiscali.co.uk> | 2009-09-21 20:03:32 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-22 10:17:40 -0400 |
commit | 6e919717c82c5773ac671816c8392c70d261685f (patch) | |
tree | 76e22da3ba5000e4ea408315723cc67f3e4b6352 /mm/mlock.c | |
parent | 58fa879e1e640a1856f736b418984ebeccee1c95 (diff) |
mm: m(un)lock avoid ZERO_PAGE
I'm still reluctant to clutter __get_user_pages() with another flag, just
to avoid touching ZERO_PAGE count in mlock(); though we can add that later
if it shows up as an issue in practice.
But when mlocking, we can test page->mapping slightly earlier, to avoid
the potentially bouncy rescheduling of lock_page on ZERO_PAGE - mlock
didn't lock_page in olden ZERO_PAGE days, so we might have regressed.
And when munlocking, it turns out that FOLL_DUMP coincidentally does
what's needed to avoid all updates to ZERO_PAGE, so use that here also.
Plus add comment suggested by KAMEZAWA Hiroyuki.
Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Rik van Riel <riel@redhat.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Nick Piggin <npiggin@suse.de>
Acked-by: Mel Gorman <mel@csn.ul.ie>
Cc: Minchan Kim <minchan.kim@gmail.com>
Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mlock.c')
-rw-r--r-- | mm/mlock.c | 49 |
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); |