Module Name:    src
Committed By:   pooka
Date:           Tue Sep  7 07:47:36 UTC 2010

Modified Files:
        src/sys/rump/librump/rumpkern: vm.c

Log Message:
Improve page allocator performance by using pool_cache for the
structure itself and allocating the backing page directly from the
hypervisor.

* initial write to a large tmpfs file is almost 2x faster
* truncating the file to 0 length after write is over 50% faster
* rewrite of the file is just slightly faster (indicating that
  kmem does a good job with caching, as expected)


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/rump/librump/rumpkern/vm.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/rump/librump/rumpkern/vm.c
diff -u src/sys/rump/librump/rumpkern/vm.c:1.89 src/sys/rump/librump/rumpkern/vm.c:1.90
--- src/sys/rump/librump/rumpkern/vm.c:1.89	Tue Sep  7 06:06:54 2010
+++ src/sys/rump/librump/rumpkern/vm.c	Tue Sep  7 07:47:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm.c,v 1.89 2010/09/07 06:06:54 pooka Exp $	*/
+/*	$NetBSD: vm.c,v 1.90 2010/09/07 07:47:36 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.89 2010/09/07 06:06:54 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.90 2010/09/07 07:47:36 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -115,6 +115,26 @@
  * vm pages 
  */
 
+static int
+pgctor(void *arg, void *obj, int flags)
+{
+	struct vm_page *pg = obj;
+
+	memset(pg, 0, sizeof(*pg));
+	pg->uanon = rump_hypermalloc(PAGE_SIZE, PAGE_SIZE, true, "pgalloc");
+	return 0;
+}
+
+static void
+pgdtor(void *arg, void *obj)
+{
+	struct vm_page *pg = obj;
+
+	rump_hyperfree(pg->uanon, PAGE_SIZE);
+}
+
+static struct pool_cache pagecache;
+
 /* called with the object locked */
 struct vm_page *
 uvm_pagealloc_strat(struct uvm_object *uobj, voff_t off, struct vm_anon *anon,
@@ -122,14 +142,14 @@
 {
 	struct vm_page *pg;
 
-	pg = kmem_zalloc(sizeof(struct vm_page), KM_SLEEP);
+	pg = pool_cache_get(&pagecache, PR_WAITOK);
 	pg->offset = off;
 	pg->uobject = uobj;
 
-	pg->uanon = (void *)kmem_alloc(PAGE_SIZE, KM_SLEEP);
-	if (flags & UVM_PGA_ZERO)
-		memset(pg->uanon, 0, PAGE_SIZE);
 	pg->flags = PG_CLEAN|PG_BUSY|PG_FAKE;
+	if (flags & UVM_PGA_ZERO) {
+		uvm_pagezero(pg);
+	}
 
 	TAILQ_INSERT_TAIL(&uobj->memq, pg, listq.queue);
 	rb_tree_insert_node(&uobj->rb_tree, &pg->rb_node);
@@ -155,8 +175,7 @@
 	uobj->uo_npages--;
 	rb_tree_remove_node(&uobj->rb_tree, &pg->rb_node);
 	TAILQ_REMOVE(&uobj->memq, pg, listq.queue);
-	kmem_free((void *)pg->uanon, PAGE_SIZE);
-	kmem_free(pg, sizeof(*pg));
+	pool_cache_put(&pagecache, pg);
 }
 
 void
@@ -207,6 +226,9 @@
 	callback_head_init(&kernel_map_store.vmk_reclaim_callback, IPL_VM);
 	kmem_map->pmap = pmap_kernel();
 	callback_head_init(&kmem_map_store.vmk_reclaim_callback, IPL_VM);
+
+	pool_cache_bootstrap(&pagecache, sizeof(struct vm_page), 0, 0, 0,
+	    "page$", NULL, IPL_NONE, pgctor, pgdtor, NULL);
 }
 
 void

Reply via email to