]> Pileus Git - ~andy/linux/blobdiff - mm/mlock.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[~andy/linux] / mm / mlock.c
index 516b2c2ddd5a55b244a89af33eeb3b6f3b88d410..bd34b3a10852c3d3ac3b1808653721a6114549c2 100644 (file)
@@ -110,7 +110,15 @@ void munlock_vma_page(struct page *page)
        if (TestClearPageMlocked(page)) {
                dec_zone_page_state(page, NR_MLOCK);
                if (!isolate_lru_page(page)) {
-                       int ret = try_to_munlock(page);
+                       int ret = SWAP_AGAIN;
+
+                       /*
+                        * Optimization: if the page was mapped just once,
+                        * that's our mapping and we don't need to check all the
+                        * other vmas.
+                        */
+                       if (page_mapcount(page) > 1)
+                               ret = try_to_munlock(page);
                        /*
                         * did try_to_unlock() succeed or punt?
                         */
@@ -307,13 +315,13 @@ void munlock_vma_pages_range(struct vm_area_struct *vma,
  * For vmas that pass the filters, merge/split as appropriate.
  */
 static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev,
-       unsigned long start, unsigned long end, unsigned int newflags)
+       unsigned long start, unsigned long end, vm_flags_t newflags)
 {
        struct mm_struct *mm = vma->vm_mm;
        pgoff_t pgoff;
        int nr_pages;
        int ret = 0;
-       int lock = newflags & VM_LOCKED;
+       int lock = !!(newflags & VM_LOCKED);
 
        if (newflags == vma->vm_flags || (vma->vm_flags & VM_SPECIAL) ||
            is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm))
@@ -385,7 +393,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
                prev = vma;
 
        for (nstart = start ; ; ) {
-               unsigned int newflags;
+               vm_flags_t newflags;
 
                /* Here we know that  vma->vm_start <= nstart < vma->vm_end. */
 
@@ -524,7 +532,7 @@ static int do_mlockall(int flags)
                goto out;
 
        for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
-               unsigned int newflags;
+               vm_flags_t newflags;
 
                newflags = vma->vm_flags | VM_LOCKED;
                if (!(flags & MCL_CURRENT))
@@ -549,7 +557,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
        if (!can_do_mlock())
                goto out;
 
-       lru_add_drain_all();    /* flush pagevec */
+       if (flags & MCL_CURRENT)
+               lru_add_drain_all();    /* flush pagevec */
 
        down_write(&current->mm->mmap_sem);