linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [rfc][patch] mm: madvise(WILLNEED) for anonymous memory
@ 2007-12-20 13:05 Peter Zijlstra
  2007-12-20 14:09 ` Hugh Dickins
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Zijlstra @ 2007-12-20 13:05 UTC (permalink / raw)
  To: linux-kernel, linux-mm; +Cc: hugh, Nick Piggin, riel, Lennart Poettering

Hi,

Lennart asked for madvise(WILLNEED) to work on anonymous pages, he plans
to use this to pre-fault pages. He currently uses: mlock/munlock for
this purpose.

[ compile tested only ]

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
diff --git a/mm/madvise.c b/mm/madvise.c
index 93ee375..eff60ce 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -100,6 +100,24 @@ out:
 	return error;
 }
 
+static long madvice_willneed_anon(struct vm_area_struct *vma,
+				  struct vm_area_struct **prev,
+				  unsigned long start, unsigned long end)
+{
+	int ret, len;
+
+	*prev = vma;
+	if (end > vma->vm_end)
+		end = vma->vm_end;
+
+	len = end - start;
+	ret = get_user_pages(current, current->mm, start, len,
+			0, 0, NULL, NULL);
+	if (ret < 0)
+		return ret;
+	return ret == len ? 0 : -1;
+}
+
 /*
  * Schedule all required I/O operations.  Do not wait for completion.
  */
@@ -110,7 +128,7 @@ static long madvise_willneed(struct vm_area_struct * vma,
 	struct file *file = vma->vm_file;
 
 	if (!file)
-		return -EBADF;
+		return madvice_willneed_anon(vma, prev, start, end);
 
 	if (file->f_mapping->a_ops->get_xip_page) {
 		/* no bad return value, but ignore advice */


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-12-20 17:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-20 13:05 [rfc][patch] mm: madvise(WILLNEED) for anonymous memory Peter Zijlstra
2007-12-20 14:09 ` Hugh Dickins
2007-12-20 14:47   ` Peter Zijlstra
2007-12-20 14:56     ` Peter Zijlstra
2007-12-20 15:18       ` Peter Zijlstra
2007-12-20 15:23         ` Peter Zijlstra
2007-12-20 15:26     ` Hugh Dickins
2007-12-20 16:53       ` Peter Zijlstra
2007-12-20 17:11         ` Matt Mackall
2007-12-20 17:15           ` Peter Zijlstra
2007-12-20 16:29   ` Lennart Poettering

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