| 365 | } |
| 366 | |
| 367 | static void |
| 368 | vm_daemon(void) |
| 369 | { |
| 370 | struct rlimit rsslim; |
| 371 | struct proc *p; |
| 372 | struct thread *td; |
| 373 | struct vmspace *vm; |
| 374 | int breakout, swapout_flags, tryagain, attempts; |
| 375 | #ifdef RACCT |
| 376 | uint64_t rsize, ravailable; |
| 377 | #endif |
| 378 | |
| 379 | while (TRUE) { |
| 380 | mtx_lock(&vm_daemon_mtx); |
| 381 | msleep(&vm_daemon_needed, &vm_daemon_mtx, PPAUSE, "psleep", |
| 382 | #ifdef RACCT |
| 383 | racct_enable ? hz : 0 |
| 384 | #else |
| 385 | 0 |
| 386 | #endif |
| 387 | ); |
| 388 | swapout_flags = vm_pageout_req_swapout; |
| 389 | vm_pageout_req_swapout = 0; |
| 390 | mtx_unlock(&vm_daemon_mtx); |
| 391 | if (swapout_flags != 0) { |
| 392 | /* |
| 393 | * Drain the per-CPU page queue batches as a deadlock |
| 394 | * avoidance measure. |
| 395 | */ |
| 396 | if ((swapout_flags & VM_SWAP_NORMAL) != 0) |
| 397 | vm_page_pqbatch_drain(); |
| 398 | swapout_procs(swapout_flags); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * scan the processes for exceeding their rlimits or if |
| 403 | * process is swapped out -- deactivate pages |
| 404 | */ |
| 405 | tryagain = 0; |
| 406 | attempts = 0; |
| 407 | again: |
| 408 | attempts++; |
| 409 | sx_slock(&allproc_lock); |
| 410 | FOREACH_PROC_IN_SYSTEM(p) { |
| 411 | vm_pindex_t limit, size; |
| 412 | |
| 413 | /* |
| 414 | * if this is a system process or if we have already |
| 415 | * looked at this process, skip it. |
| 416 | */ |
| 417 | PROC_LOCK(p); |
| 418 | if (p->p_state != PRS_NORMAL || |
| 419 | p->p_flag & (P_INEXEC | P_SYSTEM | P_WEXIT)) { |
| 420 | PROC_UNLOCK(p); |
| 421 | continue; |
| 422 | } |
| 423 | /* |
| 424 | * if the process is in a non-running type state, |
nothing calls this directly
no test coverage detected