diff options
author | Hugh Dickins <hughd@google.com> | 2012-05-29 18:06:40 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-29 19:22:22 -0400 |
commit | 3f31d07571eeea18a7d34db9af21d2285b807a17 (patch) | |
tree | 04350a376ef0cbe32cf2ff11067d4a0a920fd093 /mm/madvise.c | |
parent | 83e4fa9c16e4af7122e31be3eca5d57881d236fe (diff) |
mm/fs: route MADV_REMOVE to FALLOC_FL_PUNCH_HOLE
Now tmpfs supports hole-punching via fallocate(), switch madvise_remove()
to use do_fallocate() instead of vmtruncate_range(): which extends
madvise(,,MADV_REMOVE) support from tmpfs to ext4, ocfs2 and xfs.
There is one more user of vmtruncate_range() in our tree,
staging/android's ashmem_shrink(): convert it to use do_fallocate() too
(but if its unpinned areas are already unmapped - I don't know - then it
would do better to use shmem_truncate_range() directly).
Based-on-patch-by: Cong Wang <amwang@redhat.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Colin Cross <ccross@android.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linux-foundation.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Andreas Dilger <adilger@dilger.ca>
Cc: Mark Fasheh <mfasheh@suse.de>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Ben Myers <bpm@sgi.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/madvise.c')
-rw-r--r-- | mm/madvise.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/mm/madvise.c b/mm/madvise.c index 1ccbba5b6674..deff1b64a08c 100644 --- a/mm/madvise.c +++ b/mm/madvise.c | |||
@@ -11,8 +11,10 @@ | |||
11 | #include <linux/mempolicy.h> | 11 | #include <linux/mempolicy.h> |
12 | #include <linux/page-isolation.h> | 12 | #include <linux/page-isolation.h> |
13 | #include <linux/hugetlb.h> | 13 | #include <linux/hugetlb.h> |
14 | #include <linux/falloc.h> | ||
14 | #include <linux/sched.h> | 15 | #include <linux/sched.h> |
15 | #include <linux/ksm.h> | 16 | #include <linux/ksm.h> |
17 | #include <linux/fs.h> | ||
16 | 18 | ||
17 | /* | 19 | /* |
18 | * Any behaviour which results in changes to the vma->vm_flags needs to | 20 | * 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, | |||
200 | struct vm_area_struct **prev, | 202 | struct vm_area_struct **prev, |
201 | unsigned long start, unsigned long end) | 203 | unsigned long start, unsigned long end) |
202 | { | 204 | { |
203 | struct address_space *mapping; | 205 | loff_t offset; |
204 | loff_t offset, endoff; | ||
205 | int error; | 206 | int error; |
206 | 207 | ||
207 | *prev = NULL; /* tell sys_madvise we drop mmap_sem */ | 208 | *prev = NULL; /* tell sys_madvise we drop mmap_sem */ |
@@ -217,16 +218,14 @@ static long madvise_remove(struct vm_area_struct *vma, | |||
217 | if ((vma->vm_flags & (VM_SHARED|VM_WRITE)) != (VM_SHARED|VM_WRITE)) | 218 | if ((vma->vm_flags & (VM_SHARED|VM_WRITE)) != (VM_SHARED|VM_WRITE)) |
218 | return -EACCES; | 219 | return -EACCES; |
219 | 220 | ||
220 | mapping = vma->vm_file->f_mapping; | ||
221 | |||
222 | offset = (loff_t)(start - vma->vm_start) | 221 | offset = (loff_t)(start - vma->vm_start) |
223 | + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); | 222 | + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); |
224 | endoff = (loff_t)(end - vma->vm_start - 1) | ||
225 | + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); | ||
226 | 223 | ||
227 | /* vmtruncate_range needs to take i_mutex */ | 224 | /* filesystem's fallocate may need to take i_mutex */ |
228 | up_read(¤t->mm->mmap_sem); | 225 | up_read(¤t->mm->mmap_sem); |
229 | error = vmtruncate_range(mapping->host, offset, endoff); | 226 | error = do_fallocate(vma->vm_file, |
227 | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, | ||
228 | offset, end - start); | ||
230 | down_read(¤t->mm->mmap_sem); | 229 | down_read(¤t->mm->mmap_sem); |
231 | return error; | 230 | return error; |
232 | } | 231 | } |