MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vm_daemon

Function vm_daemon

freebsd/vm/vm_swapout.c:367–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367static void
368vm_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;
407again:
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,

Callers

nothing calls this directly

Calls 13

vm_page_pqbatch_drainFunction · 0.85
swapout_procsFunction · 0.85
qminFunction · 0.85
vmspace_acquire_refFunction · 0.85
vmspace_resident_countFunction · 0.85
vmspace_freeFunction · 0.85
maybe_yieldFunction · 0.85
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50
lim_rlimit_procFunction · 0.50
racct_setFunction · 0.50

Tested by

no test coverage detected