Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/vm_swapout.c
Show First 20 Lines • Show All 723 Lines • ▼ Show 20 Lines | |||||
* there are no sleeping or stopped processes, the longest-resident | * there are no sleeping or stopped processes, the longest-resident | ||||
* process is swapped out. | * process is swapped out. | ||||
*/ | */ | ||||
static void | static void | ||||
swapout_procs(int action) | swapout_procs(int action) | ||||
{ | { | ||||
struct proc *p; | struct proc *p; | ||||
struct thread *td; | struct thread *td; | ||||
struct vmspace *vm; | |||||
int minslptime, slptime; | int minslptime, slptime; | ||||
bool didswap; | bool didswap; | ||||
minslptime = 100000; | minslptime = 100000; | ||||
didswap = false; | didswap = false; | ||||
retry: | retry: | ||||
sx_slock(&allproc_lock); | sx_slock(&allproc_lock); | ||||
FOREACH_PROC_IN_SYSTEM(p) { | FOREACH_PROC_IN_SYSTEM(p) { | ||||
Show All 17 Lines | FOREACH_PROC_IN_SYSTEM(p) { | ||||
if ((p->p_flag & (P_SYSTEM | P_WEXIT)) != 0) { | if ((p->p_flag & (P_SYSTEM | P_WEXIT)) != 0) { | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
continue; | continue; | ||||
} | } | ||||
_PHOLD_LITE(p); | _PHOLD_LITE(p); | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
sx_sunlock(&allproc_lock); | sx_sunlock(&allproc_lock); | ||||
/* | |||||
* Do not swapout a process that | |||||
* is waiting for VM data | |||||
* structures as there is a possible | |||||
* deadlock. Test this first as | |||||
* this may block. | |||||
* | |||||
* Lock the map until swapout | |||||
* finishes, or a thread of this | |||||
* process may attempt to alter | |||||
* the map. | |||||
*/ | |||||
vm = vmspace_acquire_ref(p); | |||||
if (vm == NULL) | |||||
goto nextproc2; | |||||
if (!vm_map_trylock(&vm->vm_map)) | |||||
goto nextproc1; | |||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
if (p->p_lock != 1 || (p->p_flag & (P_STOPPED_SINGLE | | if (p->p_lock != 1 || (p->p_flag & (P_STOPPED_SINGLE | | ||||
P_TRACED | P_SYSTEM)) != 0) | P_TRACED | P_SYSTEM)) != 0) | ||||
goto nextproc; | goto nextproc; | ||||
/* | /* | ||||
* Only aiod changes vmspace. However, it will be | * Only aiod changes vmspace. However, it will be | ||||
* skipped because of the if statement above checking | * skipped because of the if statement above checking | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | case PRS_NORMAL: | ||||
*/ | */ | ||||
if ((action & VM_SWAP_NORMAL) != 0 || | if ((action & VM_SWAP_NORMAL) != 0 || | ||||
((action & VM_SWAP_IDLE) != 0 && | ((action & VM_SWAP_IDLE) != 0 && | ||||
minslptime > swap_idle_threshold2)) { | minslptime > swap_idle_threshold2)) { | ||||
_PRELE(p); | _PRELE(p); | ||||
if (swapout(p) == 0) | if (swapout(p) == 0) | ||||
didswap = true; | didswap = true; | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
vm_map_unlock(&vm->vm_map); | |||||
vmspace_free(vm); | |||||
goto retry; | goto retry; | ||||
} | } | ||||
} | } | ||||
nextproc: | nextproc: | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
vm_map_unlock(&vm->vm_map); | |||||
nextproc1: | |||||
vmspace_free(vm); | |||||
nextproc2: | |||||
sx_slock(&allproc_lock); | sx_slock(&allproc_lock); | ||||
PRELE(p); | PRELE(p); | ||||
} | } | ||||
sx_sunlock(&allproc_lock); | sx_sunlock(&allproc_lock); | ||||
/* | /* | ||||
* If we swapped something out, and another process needed memory, | * If we swapped something out, and another process needed memory, | ||||
* then wakeup the sched process. | * then wakeup the sched process. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |