Module Name:    src
Committed By:   reinoud
Date:           Tue Sep  6 09:37:41 UTC 2011

Modified Files:
        src/sys/arch/usermode/usermode: pmap.c

Log Message:
Implement switch to have a sparse memory file or to fill it beforehand.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/usermode/usermode/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.56 src/sys/arch/usermode/usermode/pmap.c:1.57
--- src/sys/arch/usermode/usermode/pmap.c:1.56	Tue Sep  6 08:44:39 2011
+++ src/sys/arch/usermode/usermode/pmap.c	Tue Sep  6 09:37:41 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.56 2011/09/06 08:44:39 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.57 2011/09/06 09:37:41 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.56 2011/09/06 08:44:39 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.57 2011/09/06 09:37:41 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -104,6 +104,8 @@
 vaddr_t kmem_user_start, kmem_user_end;
 vaddr_t kmem_ext_cur_start, kmem_ext_cur_end;
 
+#define SPARSE_MEMFILE
+
 void
 pmap_bootstrap(void)
 {
@@ -119,7 +121,6 @@
 	vaddr_t va;
 	uintptr_t pg;
 	void *addr;
-	char dummy;
 	int err;
 
 	extern void _init(void);	/* start of kernel               */
@@ -188,7 +189,7 @@
 	aprint_debug("\tkmem_ext_end\t%p\n",    (void *) kmem_ext_end);
 	aprint_debug("\tkmem_user_start\t%p\n", (void *) kmem_user_start);
 	aprint_debug("\tkmem_user_end\t%p\n",   (void *) kmem_user_end);
-	aprint_debug("\n\n\n");
+	aprint_debug("\n\n");
 
 	aprint_debug("Creating memory mapped backend\n");
 
@@ -203,9 +204,32 @@
 
 	/* file_len is the backing store length, nothing to do with placement */
 	file_len = 1024 * MEMSIZE;
-	wlen = thunk_pwrite(mem_fh, &dummy, 1, file_len - 1);
-	if (wlen != 1)
-		panic("pmap_bootstrap: can't grow file\n");
+
+#ifdef SPARSE_MEMFILE
+	{
+		char dummy;
+
+		wlen = thunk_pwrite(mem_fh, &dummy, 1, file_len - 1);
+		if (wlen != 1)
+			panic("pmap_bootstrap: can't grow file\n");
+	}
+#else
+	{
+		void *block;
+
+		printf("Creating memory file\r");
+		block = thunk_malloc(PAGE_SIZE);
+		if (!block)
+			panic("pmap_bootstrap: can't malloc writeout block");
+
+		for (pg = 0; pg < file_len; pg += PAGE_SIZE) {
+			wlen = thunk_pwrite(mem_fh, block, PAGE_SIZE, pg);
+			if (wlen != PAGE_SIZE)
+				panic("pmap_bootstrap: write fails, disc full?");
+		}
+		thunk_free(block);
+	}
+#endif
 
 	/* protect the current kernel section */
 	/* XXX kernel stack? */

Reply via email to