Skip to contentSkip to conversation

make all non-file-backed madvise() calls fail

RFC PATCH New Dave Hansen 1 participant 1 message Apr 1, 2005 Memory management

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 make all non-file-backed madvise() calls fail

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

madvise.c renamed from madvise.c.orig +8 -7
@@ -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;
 }