linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH] make all non-file-backed madvise() calls fail
@ 2005-04-01 19:43 Dave Hansen
  0 siblings, 0 replies; only message in thread
From: Dave Hansen @ 2005-04-01 19:43 UTC (permalink / raw)
  To: linux-mm; +Cc: Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]

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

[-- Attachment #2: madvise-allebadf.patch --]
[-- Type: text/x-patch, Size: 1022 bytes --]

--- 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;
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-04-01 19:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-01 19:43 [RFC][PATCH] make all non-file-backed madvise() calls fail Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox