aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memory.c
diff options
context:
space:
mode:
authorMichel Lespinasse <walken@google.com>2011-01-13 18:46:14 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 20:32:36 -0500
commit53a7706d5ed8f1a53ba062b318773160cc476dde (patch)
treea1990d90d5af3686b7a83b2bbc2ae6463971efc5 /mm/memory.c
parent5fdb2002131cd4e210b9638a4fc932ec7be491d1 (diff)
mlock: do not hold mmap_sem for extended periods of time
__get_user_pages gets a new 'nonblocking' parameter to signal that the caller is prepared to re-acquire mmap_sem and retry the operation if needed. This is used to split off long operations if they are going to block on a disk transfer, or when we detect contention on the mmap_sem. [akpm@linux-foundation.org: remove ref to rwsem_is_contended()] Signed-off-by: Michel Lespinasse <walken@google.com> Cc: Hugh Dickins <hughd@google.com> Cc: Rik van Riel <riel@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Nick Piggin <npiggin@kernel.dk> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memory.c')
-rw-r--r--mm/memory.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/mm/memory.c b/mm/memory.c
index 15e1f19a3b10..1bbe9a22429c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1363,7 +1363,8 @@ no_page_table:
1363 1363
1364int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 1364int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1365 unsigned long start, int nr_pages, unsigned int gup_flags, 1365 unsigned long start, int nr_pages, unsigned int gup_flags,
1366 struct page **pages, struct vm_area_struct **vmas) 1366 struct page **pages, struct vm_area_struct **vmas,
1367 int *nonblocking)
1367{ 1368{
1368 int i; 1369 int i;
1369 unsigned long vm_flags; 1370 unsigned long vm_flags;
@@ -1463,10 +1464,15 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1463 cond_resched(); 1464 cond_resched();
1464 while (!(page = follow_page(vma, start, foll_flags))) { 1465 while (!(page = follow_page(vma, start, foll_flags))) {
1465 int ret; 1466 int ret;
1467 unsigned int fault_flags = 0;
1468
1469 if (foll_flags & FOLL_WRITE)
1470 fault_flags |= FAULT_FLAG_WRITE;
1471 if (nonblocking)
1472 fault_flags |= FAULT_FLAG_ALLOW_RETRY;
1466 1473
1467 ret = handle_mm_fault(mm, vma, start, 1474 ret = handle_mm_fault(mm, vma, start,
1468 (foll_flags & FOLL_WRITE) ? 1475 fault_flags);
1469 FAULT_FLAG_WRITE : 0);
1470 1476
1471 if (ret & VM_FAULT_ERROR) { 1477 if (ret & VM_FAULT_ERROR) {
1472 if (ret & VM_FAULT_OOM) 1478 if (ret & VM_FAULT_OOM)
@@ -1482,6 +1488,11 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1482 else 1488 else
1483 tsk->min_flt++; 1489 tsk->min_flt++;
1484 1490
1491 if (ret & VM_FAULT_RETRY) {
1492 *nonblocking = 0;
1493 return i;
1494 }
1495
1485 /* 1496 /*
1486 * The VM_FAULT_WRITE bit tells us that 1497 * The VM_FAULT_WRITE bit tells us that
1487 * do_wp_page has broken COW when necessary, 1498 * do_wp_page has broken COW when necessary,
@@ -1581,7 +1592,8 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1581 if (force) 1592 if (force)
1582 flags |= FOLL_FORCE; 1593 flags |= FOLL_FORCE;
1583 1594
1584 return __get_user_pages(tsk, mm, start, nr_pages, flags, pages, vmas); 1595 return __get_user_pages(tsk, mm, start, nr_pages, flags, pages, vmas,
1596 NULL);
1585} 1597}
1586EXPORT_SYMBOL(get_user_pages); 1598EXPORT_SYMBOL(get_user_pages);
1587 1599
@@ -1606,7 +1618,8 @@ struct page *get_dump_page(unsigned long addr)
1606 struct page *page; 1618 struct page *page;
1607 1619
1608 if (__get_user_pages(current, current->mm, addr, 1, 1620 if (__get_user_pages(current, current->mm, addr, 1,
1609 FOLL_FORCE | FOLL_DUMP | FOLL_GET, &page, &vma) < 1) 1621 FOLL_FORCE | FOLL_DUMP | FOLL_GET, &page, &vma,
1622 NULL) < 1)
1610 return NULL; 1623 return NULL;
1611 flush_cache_page(vma, addr, page_to_pfn(page)); 1624 flush_cache_page(vma, addr, page_to_pfn(page));
1612 return page; 1625 return page;