Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/sys/uvm Pull up following revision(s) (requested by chs i...
details: https://anonhg.NetBSD.org/src/rev/347b58eb8b3f
branches: netbsd-8
changeset: 450679:347b58eb8b3f
user: martin <martin%NetBSD.org@localhost>
date: Mon Apr 22 08:12:06 2019 +0000
description:
Pull up following revision(s) (requested by chs in ticket #1238):
sys/uvm/uvm_pdaemon.c: revision 1.110
Draining pools from the pagedaemon thread can deadlock, because draining
a pool can involve taking a lock which can be held by a thread which is
blocked waiting for memory. Avoid this by moving the pool-draining work
to a separate worker thread.
diffstat:
sys/uvm/uvm_pdaemon.c | 86 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 71 insertions(+), 15 deletions(-)
diffs (150 lines):
diff -r ecd06ac58698 -r 347b58eb8b3f sys/uvm/uvm_pdaemon.c
--- a/sys/uvm/uvm_pdaemon.c Mon Apr 22 08:08:45 2019 +0000
+++ b/sys/uvm/uvm_pdaemon.c Mon Apr 22 08:12:06 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_pdaemon.c,v 1.108.22.1 2017/11/02 21:29:53 snj Exp $ */
+/* $NetBSD: uvm_pdaemon.c,v 1.108.22.2 2019/04/22 08:12:06 martin Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.108.22.1 2017/11/02 21:29:53 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.108.22.2 2019/04/22 08:12:06 martin Exp $");
#include "opt_uvmhist.h"
#include "opt_readahead.h"
@@ -79,6 +79,7 @@
#include <sys/buf.h>
#include <sys/module.h>
#include <sys/atomic.h>
+#include <sys/kthread.h>
#include <uvm/uvm.h>
#include <uvm/uvm_pdpolicy.h>
@@ -105,9 +106,16 @@
static void uvmpd_scan(void);
static void uvmpd_scan_queue(void);
static void uvmpd_tune(void);
+static void uvmpd_pool_drain_thread(void *);
+static void uvmpd_pool_drain_wakeup(void);
static unsigned int uvm_pagedaemon_waiters;
+/* State for the pool drainer thread */
+static kmutex_t uvmpd_pool_drain_lock;
+static kcondvar_t uvmpd_pool_drain_cv;
+static bool uvmpd_pool_drain_run = false;
+
/*
* XXX hack to avoid hangs when large processes fork.
*/
@@ -229,14 +237,21 @@
void
uvm_pageout(void *arg)
{
- int bufcnt, npages = 0;
+ int npages = 0;
int extrapages = 0;
- struct pool *pp;
UVMHIST_FUNC("uvm_pageout"); UVMHIST_CALLED(pdhist);
UVMHIST_LOG(pdhist,"<starting uvm pagedaemon>", 0, 0, 0, 0);
+ mutex_init(&uvmpd_pool_drain_lock, MUTEX_DEFAULT, IPL_VM);
+ cv_init(&uvmpd_pool_drain_cv, "pooldrain");
+
+ /* Create the pool drainer kernel thread. */
+ if (kthread_create(PRI_VM, KTHREAD_MPSAFE, NULL,
+ uvmpd_pool_drain_thread, NULL, NULL, "pooldrain"))
+ panic("fork pooldrain");
+
/*
* ensure correct priority and set paging parameters...
*/
@@ -288,9 +303,6 @@
* system only when entire pool page is empty.
*/
mutex_spin_enter(&uvm_fpageqlock);
- bufcnt = uvmexp.freetarg - uvmexp.free;
- if (bufcnt < 0)
- bufcnt = 0;
UVMHIST_LOG(pdhist," free/ftarg=%jd/%jd",
uvmexp.free, uvmexp.freetarg, 0,0);
@@ -331,16 +343,10 @@
continue;
/*
- * kill unused metadata buffers.
+ * kick the pool drainer thread.
*/
- mutex_enter(&bufcache_lock);
- buf_drain(bufcnt << PAGE_SHIFT);
- mutex_exit(&bufcache_lock);
- /*
- * drain the pools.
- */
- pool_drain(&pp);
+ uvmpd_pool_drain_wakeup();
}
/*NOTREACHED*/
}
@@ -1022,3 +1028,53 @@
uvmpdpol_estimatepageable(active, inactive);
}
+
+/*
+ * Use a separate thread for draining pools.
+ * This work can't done from the main pagedaemon thread because
+ * some pool allocators need to take vm_map locks.
+ */
+
+static void
+uvmpd_pool_drain_thread(void *arg)
+{
+ int bufcnt;
+
+ for (;;) {
+ mutex_enter(&uvmpd_pool_drain_lock);
+ if (!uvmpd_pool_drain_run) {
+ cv_wait(&uvmpd_pool_drain_cv, &uvmpd_pool_drain_lock);
+ }
+ uvmpd_pool_drain_run = false;
+ mutex_exit(&uvmpd_pool_drain_lock);
+
+ /*
+ * kill unused metadata buffers.
+ */
+ mutex_spin_enter(&uvm_fpageqlock);
+ bufcnt = uvmexp.freetarg - uvmexp.free;
+ mutex_spin_exit(&uvm_fpageqlock);
+ if (bufcnt < 0)
+ bufcnt = 0;
+
+ mutex_enter(&bufcache_lock);
+ buf_drain(bufcnt << PAGE_SHIFT);
+ mutex_exit(&bufcache_lock);
+
+ /*
+ * drain a pool.
+ */
+ pool_drain(NULL);
+ }
+ /*NOTREACHED*/
+}
+
+static void
+uvmpd_pool_drain_wakeup(void)
+{
+
+ mutex_enter(&uvmpd_pool_drain_lock);
+ uvmpd_pool_drain_run = true;
+ cv_signal(&uvmpd_pool_drain_cv);
+ mutex_exit(&uvmpd_pool_drain_lock);
+}
Home |
Main Index |
Thread Index |
Old Index