@@ -786,25 +786,14 @@ static int madvise_free_single_vma(struct mmu_gather *tlb,
struct vm_area_struct *vma,
unsigned long start_addr, unsigned long end_addr)
{
- struct mm_struct *mm = vma->vm_mm;
- struct mmu_notifier_range range;
-
/* MADV_FREE works for only anon vma at the moment */
if (!vma_is_anonymous(vma))
return -EINVAL;
- mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm,
- start_addr, end_addr);
-
- lru_add_drain();
- update_hiwater_rss(mm);
-
- mmu_notifier_invalidate_range_start(&range);
tlb_start_vma(&tlb, vma);
- walk_page_range(vma->vm_mm, range.start, range.end,
+ walk_page_range(vma->vm_mm, start_addr, end_addr,
&madvise_free_walk_ops, tlb);
tlb_end_vma(tlb, vma);
- mmu_notifier_invalidate_range_end(&range);
return 0;
}
@@ -832,18 +821,7 @@ static long madvise_dontneed_single_vma(struct mmu_gather *tlb,
struct vm_area_struct *vma,
unsigned long start, unsigned long end)
{
- struct mm_struct *mm = vma->vm_mm;
- struct mmu_notifier_range range;
-
- mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, start,
- end);
-
- lru_add_drain();
- update_hiwater_rss(mm);
-
- mmu_notifier_invalidate_range_start(&range);
unmap_single_vma(tlb, vma, start, end, NULL);
- mmu_notifier_invalidate_range_end(&range);
return 0;
}
@@ -855,7 +833,9 @@ static long madvise_dontneed_free(struct mmu_gather *tlb,
int behavior)
{
struct mm_struct *mm = vma->vm_mm;
+ struct mmu_notifier_range range;
unsigned long end = *pend;
+ long ret;
*prev = vma;
if (!can_madv_lru_vma(vma))
@@ -901,10 +881,20 @@ static long madvise_dontneed_free(struct mmu_gather *tlb,
VM_WARN_ON(start >= end);
}
+ mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, start,
+ end);
+
+ lru_add_drain();
+ update_hiwater_rss(mm);
+ mmu_notifier_invalidate_range_start(&range);
+
if (behavior == MADV_DONTNEED)
- return madvise_dontneed_single_vma(tlb, vma, start, end);
+ ret = madvise_dontneed_single_vma(tlb, vma, start, end);
else /* behavior == MADV_FREE */
- return madvise_free_single_vma(tlb, vma, start, end);
+ ret = madvise_free_single_vma(tlb, vma, start, end);
+
+ mmu_notifier_invalidate_range_end(&range);
+ return ret;
}
static long madvise_populate(struct vm_area_struct *vma,