summaryrefslogtreecommitdiffstats
path: root/sys/vm/vm_glue.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2008-08-05 20:02:31 +0000
committerjhb <jhb@FreeBSD.org>2008-08-05 20:02:31 +0000
commit8af56fb6875120edaae014a4cc547f5e14609a12 (patch)
tree80c45ebfc07976bf62d8de55267fa69fa52fdc1d /sys/vm/vm_glue.c
parentbe95b0fe3c10d07ed8c0887e7695a358ee6a2e17 (diff)
downloadFreeBSD-src-8af56fb6875120edaae014a4cc547f5e14609a12.zip
FreeBSD-src-8af56fb6875120edaae014a4cc547f5e14609a12.tar.gz
If a thread that is swapped out is made runnable, then the setrunnable()
routine wakes up proc0 so that proc0 can swap the thread back in. Historically, this has been done by waking up proc0 directly from setrunnable() itself via a wakeup(). When waking up a sleeping thread that was swapped out (the usual case when waking proc0 since only sleeping threads are eligible to be swapped out), this resulted in a bit of recursion (e.g. wakeup() -> setrunnable() -> wakeup()). With sleep queues having separate locks in 6.x and later, this caused a spin lock LOR (sleepq lock -> sched_lock/thread lock -> sleepq lock). An attempt was made to fix this in 7.0 by making the proc0 wakeup use the ithread mechanism for doing the wakeup. However, this required grabbing proc0's thread lock to perform the wakeup. If proc0 was asleep elsewhere in the kernel (e.g. waiting for disk I/O), then this degenerated into the same LOR since the thread lock would be some other sleepq lock. Fix this by deferring the wakeup of the swapper until after the sleepq lock held by the upper layer has been locked. The setrunnable() routine now returns a boolean value to indicate whether or not proc0 needs to be woken up. The end result is that consumers of the sleepq API such as *sleep/wakeup, condition variables, sx locks, and lockmgr, have to wakeup proc0 if they get a non-zero return value from sleepq_abort(), sleepq_broadcast(), or sleepq_signal(). Discussed with: jeff Glanced at by: sam Tested by: Jurgen Weber jurgen - ish com au MFC after: 2 weeks
Diffstat (limited to 'sys/vm/vm_glue.c')
-rw-r--r--sys/vm/vm_glue.c53
1 files changed, 15 insertions, 38 deletions
diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c
index 462c460..d6ec2ba 100644
--- a/sys/vm/vm_glue.c
+++ b/sys/vm/vm_glue.c
@@ -116,10 +116,6 @@ static int swapout(struct proc *);
static void swapclear(struct proc *);
#endif
-
-static volatile int proc0_rescan;
-
-
/*
* MPSAFE
*
@@ -683,9 +679,6 @@ scheduler(dummy)
loop:
if (vm_page_count_min()) {
VM_WAIT;
- thread_lock(&thread0);
- proc0_rescan = 0;
- thread_unlock(&thread0);
goto loop;
}
@@ -732,13 +725,7 @@ loop:
* Nothing to do, back to sleep.
*/
if ((p = pp) == NULL) {
- thread_lock(&thread0);
- if (!proc0_rescan) {
- TD_SET_IWAIT(&thread0);
- mi_switch(SW_VOL | SWT_IWAIT, NULL);
- }
- proc0_rescan = 0;
- thread_unlock(&thread0);
+ tsleep(&proc0, PVM, "sched", maxslp * hz / 2);
goto loop;
}
PROC_LOCK(p);
@@ -750,9 +737,6 @@ loop:
*/
if (p->p_flag & (P_INMEM | P_SWAPPINGOUT | P_SWAPPINGIN)) {
PROC_UNLOCK(p);
- thread_lock(&thread0);
- proc0_rescan = 0;
- thread_unlock(&thread0);
goto loop;
}
@@ -762,31 +746,15 @@ loop:
*/
faultin(p);
PROC_UNLOCK(p);
- thread_lock(&thread0);
- proc0_rescan = 0;
- thread_unlock(&thread0);
goto loop;
}
-void kick_proc0(void)
+void
+kick_proc0(void)
{
- struct thread *td = &thread0;
-
- /* XXX This will probably cause a LOR in some cases */
- thread_lock(td);
- if (TD_AWAITING_INTR(td)) {
- CTR2(KTR_INTR, "%s: sched_add %d", __func__, 0);
- TD_CLR_IWAIT(td);
- sched_add(td, SRQ_INTR);
- } else {
- proc0_rescan = 1;
- CTR2(KTR_INTR, "%s: state %d",
- __func__, td->td_state);
- }
- thread_unlock(td);
-
-}
+ wakeup(&proc0);
+}
#ifndef NO_SWAPPING
@@ -980,7 +948,16 @@ swapclear(p)
td->td_flags &= ~TDF_SWAPINREQ;
TD_CLR_SWAPPED(td);
if (TD_CAN_RUN(td))
- setrunnable(td);
+ if (setrunnable(td)) {
+#ifdef INVARIANTS
+ /*
+ * XXX: We just cleared TDI_SWAPPED
+ * above and set TDF_INMEM, so this
+ * should never happen.
+ */
+ panic("not waking up swapper");
+#endif
+ }
thread_unlock(td);
}
p->p_flag &= ~(P_SWAPPINGIN|P_SWAPPINGOUT);
OpenPOWER on IntegriCloud