Module Name:    src
Committed By:   haad
Date:           Mon Aug 10 23:17:29 UTC 2009

Modified Files:
        src/sys/uvm: uvm_extern.h uvm_page.c uvm_pdaemon.c

Log Message:
Add uvm_reclaim_hooks support for reclaiming kernel KVA space and memory.
This is used only by zfs where uvm_reclaim hook is added from arc cache.

Oked a...@.


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/sys/uvm/uvm_extern.h
cvs rdiff -u -r1.145 -r1.146 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.97 -r1.98 src/sys/uvm/uvm_pdaemon.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/uvm/uvm_extern.h
diff -u src/sys/uvm/uvm_extern.h:1.157 src/sys/uvm/uvm_extern.h:1.158
--- src/sys/uvm/uvm_extern.h:1.157	Wed Aug  5 14:11:32 2009
+++ src/sys/uvm/uvm_extern.h	Mon Aug 10 23:17:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_extern.h,v 1.157 2009/08/05 14:11:32 pooka Exp $	*/
+/*	$NetBSD: uvm_extern.h,v 1.158 2009/08/10 23:17:29 haad Exp $	*/
 
 /*
  *
@@ -534,6 +534,19 @@
 #define	UVM_COREDUMP_STACK	0x01	/* region is user stack */
 
 /*
+ * Structure containig uvm reclaim hooks, uvm_reclaim_list is guarded by
+ * uvm_reclaim_lock.
+ */
+struct uvm_reclaim_hook {
+	void (*uvm_reclaim_hook)(void);
+	SLIST_ENTRY(uvm_reclaim_hook) uvm_reclaim_next;
+};
+
+void    uvm_reclaim_init(void);
+void 	uvm_reclaim_hook_add(struct uvm_reclaim_hook *);
+void    uvm_reclaim_hook_del(struct uvm_reclaim_hook *);
+
+/*
  * the various kernel maps, owned by MD code
  */
 extern struct vm_map *kernel_map;

Index: src/sys/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.145 src/sys/uvm/uvm_page.c:1.146
--- src/sys/uvm/uvm_page.c:1.145	Thu Mar 12 12:55:16 2009
+++ src/sys/uvm/uvm_page.c	Mon Aug 10 23:17:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.145 2009/03/12 12:55:16 abs Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.146 2009/08/10 23:17:29 haad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.145 2009/03/12 12:55:16 abs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.146 2009/08/10 23:17:29 haad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -116,6 +116,9 @@
  */
 int vm_page_reserve_kernel = 5;
 
+/* Physical memory size */
+uintptr_t physmem;
+
 /*
  * local variables
  */
@@ -349,6 +352,7 @@
 	 */
 
 	curcpu()->ci_data.cpu_uvm = &uvm.cpus[0];
+	uvm_reclaim_init();
 	uvmpdpol_init();
 	mutex_init(&uvm_pageqlock, MUTEX_DRIVER, IPL_NONE);
 	mutex_init(&uvm_fpageqlock, MUTEX_DRIVER, IPL_VM);

Index: src/sys/uvm/uvm_pdaemon.c
diff -u src/sys/uvm/uvm_pdaemon.c:1.97 src/sys/uvm/uvm_pdaemon.c:1.98
--- src/sys/uvm/uvm_pdaemon.c:1.97	Sat Dec 13 11:26:57 2008
+++ src/sys/uvm/uvm_pdaemon.c	Mon Aug 10 23:17:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_pdaemon.c,v 1.97 2008/12/13 11:26:57 ad Exp $	*/
+/*	$NetBSD: uvm_pdaemon.c,v 1.98 2009/08/10 23:17:29 haad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.97 2008/12/13 11:26:57 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.98 2009/08/10 23:17:29 haad Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_readahead.h"
@@ -114,6 +114,11 @@
  */
 u_int uvm_extrapages;
 
+static kmutex_t uvm_reclaim_lock;
+
+SLIST_HEAD(uvm_reclaim_hooks, uvm_reclaim_hook) uvm_reclaim_list;
+
+
 /*
  * uvm_wait: wait (sleep) for the page daemon to free some pages
  *
@@ -233,6 +238,8 @@
 	int extrapages = 0;
 	struct pool *pp;
 	uint64_t where;
+	struct uvm_reclaim_hook *hook;
+	
 	UVMHIST_FUNC("uvm_pageout"); UVMHIST_CALLED(pdhist);
 
 	UVMHIST_LOG(pdhist,"<starting uvm pagedaemon>", 0, 0, 0, 0);
@@ -340,6 +347,13 @@
 		buf_drain(bufcnt << PAGE_SHIFT);
 		mutex_exit(&bufcache_lock);
 
+		mutex_enter(&uvm_reclaim_lock);
+		SLIST_FOREACH(hook, &uvm_reclaim_list, uvm_reclaim_next) {
+			(*hook->uvm_reclaim_hook)();
+		}
+		mutex_exit(&uvm_reclaim_lock);
+		
+		
 		/*
 		 * complete draining the pools.
 		 */
@@ -1039,3 +1053,45 @@
 
 	uvmpdpol_estimatepageable(active, inactive);
 }
+
+void
+uvm_reclaim_init(void)
+{
+	
+	/* Initialize UVM reclaim hooks. */
+	mutex_init(&uvm_reclaim_lock, MUTEX_DEFAULT, IPL_NONE);
+	SLIST_INIT(&uvm_reclaim_list);
+
+}
+
+void
+uvm_reclaim_hook_add(struct uvm_reclaim_hook *hook)
+{
+
+	KASSERT(hook != NULL);
+	
+	mutex_enter(&uvm_reclaim_lock);
+	SLIST_INSERT_HEAD(&uvm_reclaim_list, hook, uvm_reclaim_next);
+	mutex_exit(&uvm_reclaim_lock);
+}
+
+void
+uvm_reclaim_hook_del(struct uvm_reclaim_hook *hook_entry)
+{
+	struct uvm_reclaim_hook *hook;
+
+	KASSERT(hook_entry != NULL);
+	
+	mutex_enter(&uvm_reclaim_lock);
+	SLIST_FOREACH(hook, &uvm_reclaim_list, uvm_reclaim_next) {
+		if (hook != hook_entry) {
+			continue;
+		}
+
+		SLIST_REMOVE(&uvm_reclaim_list, hook, uvm_reclaim_hook,
+		    uvm_reclaim_next);
+		break;
+	}
+
+	mutex_exit(&uvm_reclaim_lock);
+}

Reply via email to