8 #include <linux/mman.h>
11 #include <linux/mempolicy.h>
14 #include <linux/falloc.h>
15 #include <linux/sched.h>
25 static int madvise_need_mmap_write(
int behavior)
44 unsigned long start,
unsigned long end,
int behavior)
49 unsigned long new_flags = vma->
vm_flags;
53 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
56 new_flags = (new_flags & ~VM_RAND_READ) | VM_SEQ_READ;
59 new_flags = (new_flags & ~VM_SEQ_READ) | VM_RAND_READ;
62 new_flags |= VM_DONTCOPY;
69 new_flags &= ~VM_DONTCOPY;
72 new_flags |= VM_DONTDUMP;
75 if (new_flags & VM_SPECIAL) {
79 new_flags &= ~VM_DONTDUMP;
83 error =
ksm_madvise(vma, start, end, behavior, &new_flags);
139 unsigned long start,
unsigned long end)
146 if (file->
f_mapping->a_ops->get_xip_mem) {
182 unsigned long start,
unsigned long end)
185 if (vma->
vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
189 struct zap_details details = {
190 .nonlinear_vma = vma,
208 unsigned long start,
unsigned long end)
216 if (vma->
vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB))
225 if ((vma->
vm_flags & (VM_SHARED|VM_WRITE)) != (VM_SHARED|VM_WRITE))
228 offset = (loff_t)(start - vma->
vm_start)
241 offset, end - start);
247 #ifdef CONFIG_MEMORY_FAILURE
251 static int madvise_hwpoison(
int bhv,
unsigned long start,
unsigned long end)
281 unsigned long start,
unsigned long end,
int behavior)
285 return madvise_remove(vma, prev, start, end);
287 return madvise_willneed(vma, prev, start, end);
289 return madvise_dontneed(vma, prev, start, end);
291 return madvise_behavior(vma, prev, start, end, behavior);
296 madvise_behavior_valid(
int behavior)
311 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
370 int unmapped_error = 0;
375 #ifdef CONFIG_MEMORY_FAILURE
377 return madvise_hwpoison(behavior, start, start+len_in);
379 if (!madvise_behavior_valid(behavior))
382 write = madvise_need_mmap_write(behavior);
433 error = madvise_vma(vma, &prev, start, tmp, behavior);
437 if (prev && start < prev->
vm_end)
439 error = unmapped_error;