[RFC][PATCH] make all non-file-backed madvise() calls fail
From: Dave Hansen
Date: Fri Apr 01 2005 - 14:54:29 EST
This is related to this bug:
http://bugme.osdl.org/show_bug.cgi?id=2995
The kernel currently only checks that the memory is file-backed if
MADV_WILLNEED is set. It's not entirely clear from the manpage at least
that *all* non-file-backed madvise() calls should fail.
The attached patch returns -EBADF for all non-file-backed madvise()
calls. I'm not suggesting that this is the absolutely right behavior,
but it certainly does what the bug submitter wants.
Comments?
-- Dave
--- mm/madvise.c.orig 2005-04-01 10:40:59.000000000 -0800
+++ mm/madvise.c 2005-04-01 10:56:50.000000000 -0800
@@ -58,13 +58,9 @@
* Schedule all required I/O operations. Do not wait for completion.
*/
static long madvise_willneed(struct vm_area_struct * vma,
- unsigned long start, unsigned long end)
+ unsigned long start, unsigned long end,
+ struct file *file)
{
- struct file *file = vma->vm_file;
-
- if (!file)
- return -EBADF;
-
start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
if (end > vma->vm_end)
end = vma->vm_end;
@@ -115,6 +111,10 @@
unsigned long end, int behavior)
{
long error = -EBADF;
+ struct file *file = vma->vm_file;
+
+ if (!file)
+ goto out;
switch (behavior) {
case MADV_NORMAL:
@@ -124,7 +124,7 @@
break;
case MADV_WILLNEED:
- error = madvise_willneed(vma, start, end);
+ error = madvise_willneed(vma, start, end, file);
break;
case MADV_DONTNEED:
@@ -136,6 +136,7 @@
break;
}
+out:
return error;
}