Deleted Added
full compact
60c60
< __FBSDID("$FreeBSD: head/sys/vm/vm_glue.c 170307 2007-06-05 00:00:57Z jeff $");
---
> __FBSDID("$FreeBSD: head/sys/vm/vm_glue.c 172207 2007-09-17 05:31:39Z jeff $");
115c115,116
< static void swapout(struct proc *);
---
> static int swapout(struct proc *);
> static void swapclear(struct proc *);
604c605
< if ((p->p_sflag & PS_INMEM) == 0)
---
> if ((p->p_flag & P_INMEM) == 0)
614,616c615,620
< if (p->p_sflag & PS_SWAPPINGIN)
< msleep(&p->p_sflag, &p->p_mtx, PVM, "faultin", 0);
< else if ((p->p_sflag & PS_INMEM) == 0) {
---
> if (p->p_flag & P_SWAPPINGIN) {
> while (p->p_flag & P_SWAPPINGIN)
> msleep(&p->p_flag, &p->p_mtx, PVM, "faultin", 0);
> return;
> }
> if ((p->p_flag & P_INMEM) == 0) {
622,624c626
< PROC_SLOCK(p);
< p->p_sflag |= PS_SWAPPINGIN;
< PROC_SUNLOCK(p);
---
> p->p_flag |= P_SWAPPINGIN;
626a629,633
> /*
> * We hold no lock here because the list of threads
> * can not change while all threads in the process are
> * swapped out.
> */
629d635
<
632,640c638,639
< p->p_sflag &= ~PS_SWAPPINGIN;
< p->p_sflag |= PS_INMEM;
< FOREACH_THREAD_IN_PROC(p, td) {
< thread_lock(td);
< TD_CLR_SWAPPED(td);
< if (TD_CAN_RUN(td))
< setrunnable(td);
< thread_unlock(td);
< }
---
> swapclear(p);
> p->p_swtime = 0;
643c642
< wakeup(&p->p_sflag);
---
> wakeup(&p->p_flag);
687c686,688
< if (p->p_sflag & (PS_INMEM | PS_SWAPPINGOUT | PS_SWAPPINGIN)) {
---
> PROC_LOCK(p);
> if (p->p_flag & (P_SWAPPINGOUT | P_SWAPPINGIN | P_INMEM)) {
> PROC_UNLOCK(p);
700c701
< if ((p->p_sflag & PS_SWAPINREQ) == 0) {
---
> if ((td->td_flags & TDF_SWAPINREQ) == 0)
702,703d702
< }
<
717a717
> PROC_UNLOCK(p);
741c741
< if (p->p_sflag & (PS_INMEM | PS_SWAPPINGOUT | PS_SWAPPINGIN)) {
---
> if (p->p_flag & (P_INMEM | P_SWAPPINGOUT | P_SWAPPINGIN)) {
749,752d748
< PROC_SLOCK(p);
< p->p_sflag &= ~PS_SWAPINREQ;
< PROC_SUNLOCK(p);
<
759,761d754
< PROC_SLOCK(p);
< p->p_swtime = 0;
< PROC_SUNLOCK(p);
807c800
< * procs and unwire their u-areas. We try to always "swap" at least one
---
> * procs and swap out their stacks. We try to always "swap" at least one
832,834c825
< PROC_SLOCK(p);
< if (p->p_state == PRS_NEW) {
< PROC_SUNLOCK(p);
---
> if (p->p_state == PRS_NEW)
836,838d826
< }
< PROC_SUNLOCK(p);
<
847d834
<
877c864
< if ((p->p_sflag & (PS_INMEM|PS_SWAPPINGOUT|PS_SWAPPINGIN)) != PS_INMEM)
---
> if ((p->p_flag & (P_INMEM|P_SWAPPINGOUT|P_SWAPPINGIN)) != P_INMEM)
893c880,882
< if (PRI_IS_REALTIME(td->td_pri_class))
---
> thread_lock(td);
> if (PRI_IS_REALTIME(td->td_pri_class)) {
> thread_unlock(td);
894a884
> }
900c890,891
< if (td->td_slptime < swap_idle_threshold1)
---
> if (td->td_slptime < swap_idle_threshold1) {
> thread_unlock(td);
901a893
> }
913c905,906
< !thread_safetoswapout(td))
---
> !thread_safetoswapout(td)) {
> thread_unlock(td);
914a908
> }
923c917,918
< (td->td_slptime < swap_idle_threshold2)))
---
> (td->td_slptime < swap_idle_threshold2))) {
> thread_unlock(td);
924a920
> }
927a924
> thread_unlock(td);
938,939c935,936
< swapout(p);
< didswap++;
---
> if (swapout(p) == 0)
> didswap++;
966a964,985
> swapclear(p)
> struct proc *p;
> {
> struct thread *td;
>
> PROC_LOCK_ASSERT(p, MA_OWNED);
> PROC_SLOCK_ASSERT(p, MA_OWNED);
>
> FOREACH_THREAD_IN_PROC(p, td) {
> thread_lock(td);
> td->td_flags |= TDF_INMEM;
> td->td_flags &= ~TDF_SWAPINREQ;
> TD_CLR_SWAPPED(td);
> if (TD_CAN_RUN(td))
> setrunnable(td);
> thread_unlock(td);
> }
> p->p_flag &= ~(P_SWAPPINGIN|P_SWAPPINGOUT);
> p->p_flag |= P_INMEM;
> }
>
> static int
973c992
< mtx_assert(&p->p_slock, MA_OWNED | MA_NOTRECURSED);
---
> PROC_SLOCK_ASSERT(p, MA_OWNED | MA_NOTRECURSED);
983c1002
< KASSERT((p->p_sflag & (PS_INMEM|PS_SWAPPINGOUT|PS_SWAPPINGIN)) == PS_INMEM,
---
> KASSERT((p->p_flag & (P_INMEM|P_SWAPPINGOUT|P_SWAPPINGIN)) == P_INMEM,
986d1004
< #if defined(INVARIANTS)
988,999d1005
< * Make sure that all threads are safe to be swapped out.
< *
< * Alternatively, we could swap out only safe threads.
< */
< FOREACH_THREAD_IN_PROC(p, td) {
< KASSERT(thread_safetoswapout(td),
< ("swapout: there is a thread not safe for swapout"));
< }
< #endif /* INVARIANTS */
< td = FIRST_THREAD_IN_PROC(p);
< ++td->td_ru.ru_nswap;
< /*
1003,1006c1009,1013
<
< p->p_sflag &= ~PS_INMEM;
< p->p_sflag |= PS_SWAPPINGOUT;
< PROC_UNLOCK(p);
---
> /*
> * Check and mark all threads before we proceed.
> */
> p->p_flag &= ~P_INMEM;
> p->p_flag |= P_SWAPPINGOUT;
1008a1016,1021
> if (!thread_safetoswapout(td)) {
> thread_unlock(td);
> swapclear(p);
> return (EBUSY);
> }
> td->td_flags &= ~TDF_INMEM;
1011a1025,1026
> td = FIRST_THREAD_IN_PROC(p);
> ++td->td_ru.ru_nswap;
1012a1028
> PROC_UNLOCK(p);
1013a1030,1034
> /*
> * This list is stable because all threads are now prevented from
> * running. The list is only modified in the context of a running
> * thread in this process.
> */
1017a1039
> p->p_flag &= ~P_SWAPPINGOUT;
1019d1040
< p->p_sflag &= ~PS_SWAPPINGOUT;
1020a1042
> return (0);