block: add ability to flag write back caching on a device
[cascardo/linux.git] / mm / memory.c
index 81dca00..93897f2 100644 (file)
@@ -1102,6 +1102,12 @@ again:
 
                        if (!PageAnon(page)) {
                                if (pte_dirty(ptent)) {
+                                       /*
+                                        * oom_reaper cannot tear down dirty
+                                        * pages
+                                        */
+                                       if (unlikely(details && details->ignore_dirty))
+                                               continue;
                                        force_flush = 1;
                                        set_page_dirty(page);
                                }
@@ -1120,8 +1126,8 @@ again:
                        }
                        continue;
                }
-               /* If details->check_mapping, we leave swap entries. */
-               if (unlikely(details))
+               /* only check swap_entries if explicitly asked for in details */
+               if (unlikely(details && !details->check_swap_entries))
                        continue;
 
                entry = pte_to_swp_entry(ptent);
@@ -1226,7 +1232,7 @@ static inline unsigned long zap_pud_range(struct mmu_gather *tlb,
        return addr;
 }
 
-static void unmap_page_range(struct mmu_gather *tlb,
+void unmap_page_range(struct mmu_gather *tlb,
                             struct vm_area_struct *vma,
                             unsigned long addr, unsigned long end,
                             struct zap_details *details)
@@ -1234,9 +1240,6 @@ static void unmap_page_range(struct mmu_gather *tlb,
        pgd_t *pgd;
        unsigned long next;
 
-       if (details && !details->check_mapping)
-               details = NULL;
-
        BUG_ON(addr >= end);
        tlb_start_vma(tlb, vma);
        pgd = pgd_offset(vma->vm_mm, addr);
@@ -2051,7 +2054,7 @@ static inline int wp_page_reuse(struct mm_struct *mm,
                VM_BUG_ON_PAGE(PageAnon(page), page);
                mapping = page->mapping;
                unlock_page(page);
-               page_cache_release(page);
+               put_page(page);
 
                if ((dirtied || page_mkwrite) && mapping) {
                        /*
@@ -2185,7 +2188,7 @@ static int wp_page_copy(struct mm_struct *mm, struct vm_area_struct *vma,
        }
 
        if (new_page)
-               page_cache_release(new_page);
+               put_page(new_page);
 
        pte_unmap_unlock(page_table, ptl);
        mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
@@ -2200,14 +2203,14 @@ static int wp_page_copy(struct mm_struct *mm, struct vm_area_struct *vma,
                                munlock_vma_page(old_page);
                        unlock_page(old_page);
                }
-               page_cache_release(old_page);
+               put_page(old_page);
        }
        return page_copied ? VM_FAULT_WRITE : 0;
 oom_free_new:
-       page_cache_release(new_page);
+       put_page(new_page);
 oom:
        if (old_page)
-               page_cache_release(old_page);
+               put_page(old_page);
        return VM_FAULT_OOM;
 }
 
@@ -2255,7 +2258,7 @@ static int wp_page_shared(struct mm_struct *mm, struct vm_area_struct *vma,
 {
        int page_mkwrite = 0;
 
-       page_cache_get(old_page);
+       get_page(old_page);
 
        if (vma->vm_ops && vma->vm_ops->page_mkwrite) {
                int tmp;
@@ -2264,7 +2267,7 @@ static int wp_page_shared(struct mm_struct *mm, struct vm_area_struct *vma,
                tmp = do_page_mkwrite(vma, old_page, address);
                if (unlikely(!tmp || (tmp &
                                      (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
-                       page_cache_release(old_page);
+                       put_page(old_page);
                        return tmp;
                }
                /*
@@ -2278,7 +2281,7 @@ static int wp_page_shared(struct mm_struct *mm, struct vm_area_struct *vma,
                if (!pte_same(*page_table, orig_pte)) {
                        unlock_page(old_page);
                        pte_unmap_unlock(page_table, ptl);
-                       page_cache_release(old_page);
+                       put_page(old_page);
                        return 0;
                }
                page_mkwrite = 1;
@@ -2338,7 +2341,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
         */
        if (PageAnon(old_page) && !PageKsm(old_page)) {
                if (!trylock_page(old_page)) {
-                       page_cache_get(old_page);
+                       get_page(old_page);
                        pte_unmap_unlock(page_table, ptl);
                        lock_page(old_page);
                        page_table = pte_offset_map_lock(mm, pmd, address,
@@ -2346,10 +2349,10 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
                        if (!pte_same(*page_table, orig_pte)) {
                                unlock_page(old_page);
                                pte_unmap_unlock(page_table, ptl);
-                               page_cache_release(old_page);
+                               put_page(old_page);
                                return 0;
                        }
-                       page_cache_release(old_page);
+                       put_page(old_page);
                }
                if (reuse_swap_page(old_page)) {
                        /*
@@ -2372,7 +2375,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
        /*
         * Ok, we need to copy. Oh, well..
         */
-       page_cache_get(old_page);
+       get_page(old_page);
 
        pte_unmap_unlock(page_table, ptl);
        return wp_page_copy(mm, vma, address, page_table, pmd,
@@ -2397,7 +2400,6 @@ static inline void unmap_mapping_range_tree(struct rb_root *root,
 
                vba = vma->vm_pgoff;
                vea = vba + vma_pages(vma) - 1;
-               /* Assume for now that PAGE_CACHE_SHIFT == PAGE_SHIFT */
                zba = details->first_index;
                if (zba < vba)
                        zba = vba;
@@ -2432,7 +2434,7 @@ static inline void unmap_mapping_range_tree(struct rb_root *root,
 void unmap_mapping_range(struct address_space *mapping,
                loff_t const holebegin, loff_t const holelen, int even_cows)
 {
-       struct zap_details details;
+       struct zap_details details = { };
        pgoff_t hba = holebegin >> PAGE_SHIFT;
        pgoff_t hlen = (holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
@@ -2616,7 +2618,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
                 * parallel locked swapcache.
                 */
                unlock_page(swapcache);
-               page_cache_release(swapcache);
+               put_page(swapcache);
        }
 
        if (flags & FAULT_FLAG_WRITE) {
@@ -2638,10 +2640,10 @@ out_nomap:
 out_page:
        unlock_page(page);
 out_release:
-       page_cache_release(page);
+       put_page(page);
        if (page != swapcache) {
                unlock_page(swapcache);
-               page_cache_release(swapcache);
+               put_page(swapcache);
        }
        return ret;
 }
@@ -2749,7 +2751,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
        if (userfaultfd_missing(vma)) {
                pte_unmap_unlock(page_table, ptl);
                mem_cgroup_cancel_charge(page, memcg, false);
-               page_cache_release(page);
+               put_page(page);
                return handle_userfault(vma, address, flags,
                                        VM_UFFD_MISSING);
        }
@@ -2768,10 +2770,10 @@ unlock:
        return 0;
 release:
        mem_cgroup_cancel_charge(page, memcg, false);
-       page_cache_release(page);
+       put_page(page);
        goto unlock;
 oom_free_page:
-       page_cache_release(page);
+       put_page(page);
 oom:
        return VM_FAULT_OOM;
 }
@@ -2804,7 +2806,7 @@ static int __do_fault(struct vm_area_struct *vma, unsigned long address,
        if (unlikely(PageHWPoison(vmf.page))) {
                if (ret & VM_FAULT_LOCKED)
                        unlock_page(vmf.page);
-               page_cache_release(vmf.page);
+               put_page(vmf.page);
                return VM_FAULT_HWPOISON;
        }
 
@@ -2993,7 +2995,7 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
        if (unlikely(!pte_same(*pte, orig_pte))) {
                pte_unmap_unlock(pte, ptl);
                unlock_page(fault_page);
-               page_cache_release(fault_page);
+               put_page(fault_page);
                return ret;
        }
        do_set_pte(vma, address, fault_page, pte, false, false);
@@ -3021,7 +3023,7 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
                return VM_FAULT_OOM;
 
        if (mem_cgroup_try_charge(new_page, mm, GFP_KERNEL, &memcg, false)) {
-               page_cache_release(new_page);
+               put_page(new_page);
                return VM_FAULT_OOM;
        }
 
@@ -3038,7 +3040,7 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
                pte_unmap_unlock(pte, ptl);
                if (fault_page) {
                        unlock_page(fault_page);
-                       page_cache_release(fault_page);
+                       put_page(fault_page);
                } else {
                        /*
                         * The fault handler has no page to lock, so it holds
@@ -3054,7 +3056,7 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
        pte_unmap_unlock(pte, ptl);
        if (fault_page) {
                unlock_page(fault_page);
-               page_cache_release(fault_page);
+               put_page(fault_page);
        } else {
                /*
                 * The fault handler has no page to lock, so it holds
@@ -3065,7 +3067,7 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
        return ret;
 uncharge_out:
        mem_cgroup_cancel_charge(new_page, memcg, false);
-       page_cache_release(new_page);
+       put_page(new_page);
        return ret;
 }
 
@@ -3093,7 +3095,7 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
                tmp = do_page_mkwrite(vma, fault_page, address);
                if (unlikely(!tmp ||
                                (tmp & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
-                       page_cache_release(fault_page);
+                       put_page(fault_page);
                        return tmp;
                }
        }
@@ -3102,7 +3104,7 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
        if (unlikely(!pte_same(*pte, orig_pte))) {
                pte_unmap_unlock(pte, ptl);
                unlock_page(fault_page);
-               page_cache_release(fault_page);
+               put_page(fault_page);
                return ret;
        }
        do_set_pte(vma, address, fault_page, pte, true, false);
@@ -3733,7 +3735,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
                                                    buf, maddr + offset, bytes);
                        }
                        kunmap(page);
-                       page_cache_release(page);
+                       put_page(page);
                }
                len -= bytes;
                buf += bytes;