memcg: move charges to root cgroup if use_hierarchy=0
[pandora-kernel.git] / mm / madvise.c
index 1ccbba5..deff1b6 100644 (file)
 #include <linux/mempolicy.h>
 #include <linux/page-isolation.h>
 #include <linux/hugetlb.h>
+#include <linux/falloc.h>
 #include <linux/sched.h>
 #include <linux/ksm.h>
+#include <linux/fs.h>
 
 /*
  * Any behaviour which results in changes to the vma->vm_flags needs to
@@ -200,8 +202,7 @@ static long madvise_remove(struct vm_area_struct *vma,
                                struct vm_area_struct **prev,
                                unsigned long start, unsigned long end)
 {
-       struct address_space *mapping;
-       loff_t offset, endoff;
+       loff_t offset;
        int error;
 
        *prev = NULL;   /* tell sys_madvise we drop mmap_sem */
@@ -217,16 +218,14 @@ static long madvise_remove(struct vm_area_struct *vma,
        if ((vma->vm_flags & (VM_SHARED|VM_WRITE)) != (VM_SHARED|VM_WRITE))
                return -EACCES;
 
-       mapping = vma->vm_file->f_mapping;
-
        offset = (loff_t)(start - vma->vm_start)
                        + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
-       endoff = (loff_t)(end - vma->vm_start - 1)
-                       + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
 
-       /* vmtruncate_range needs to take i_mutex */
+       /* filesystem's fallocate may need to take i_mutex */
        up_read(&current->mm->mmap_sem);
-       error = vmtruncate_range(mapping->host, offset, endoff);
+       error = do_fallocate(vma->vm_file,
+                               FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+                               offset, end - start);
        down_read(&current->mm->mmap_sem);
        return error;
 }