]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - mm/madvise.c
mm: thp: make deferred split shrinker memcg aware
[linux.git] / mm / madvise.c
index afe2b015ea58a3a9be6356b97775aa3674bc1234..88babcc384b9d4362b929d1771921dda30a80b67 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/userfaultfd_k.h>
 #include <linux/hugetlb.h>
 #include <linux/falloc.h>
+#include <linux/fadvise.h>
 #include <linux/sched.h>
 #include <linux/ksm.h>
 #include <linux/fs.h>
@@ -266,6 +267,7 @@ static long madvise_willneed(struct vm_area_struct *vma,
                             unsigned long start, unsigned long end)
 {
        struct file *file = vma->vm_file;
+       loff_t offset;
 
        *prev = vma;
 #ifdef CONFIG_SWAP
@@ -290,12 +292,20 @@ static long madvise_willneed(struct vm_area_struct *vma,
                return 0;
        }
 
-       start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
-       if (end > vma->vm_end)
-               end = vma->vm_end;
-       end = ((end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
-
-       force_page_cache_readahead(file->f_mapping, file, start, end - start);
+       /*
+        * Filesystem's fadvise may need to take various locks.  We need to
+        * explicitly grab a reference because the vma (and hence the
+        * vma's reference to the file) can go away as soon as we drop
+        * mmap_sem.
+        */
+       *prev = NULL;   /* tell sys_madvise we drop mmap_sem */
+       get_file(file);
+       up_read(&current->mm->mmap_sem);
+       offset = (loff_t)(start - vma->vm_start)
+                       + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
+       vfs_fadvise(file, offset, end - start, POSIX_FADV_WILLNEED);
+       fput(file);
+       down_read(&current->mm->mmap_sem);
        return 0;
 }