FreeBSD virtual memory subsystem code
vm_swapout.c File Reference
#include <sys/cdefs.h>
#include "opt_kstack_pages.h"
#include "opt_kstack_max_pages.h"
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/limits.h>
#include <sys/kernel.h>
#include <sys/eventhandler.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/kthread.h>
#include <sys/ktr.h>
#include <sys/mount.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/refcount.h>
#include <sys/sched.h>
#include <sys/sdt.h>
#include <sys/signalvar.h>
#include <sys/smp.h>
#include <sys/time.h>
#include <sys/vnode.h>
#include <sys/vmmeter.h>
#include <sys/rwlock.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/vm_kern.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_map.h>
#include <vm/vm_pageout.h>
#include <vm/vm_pager.h>
#include <vm/vm_phys.h>
#include <vm/swap_pager.h>
#include <vm/vm_extern.h>
#include <vm/uma.h>
Include dependency graph for vm_swapout.c:

Go to the source code of this file.

Macros

#define VM_SWAP_NORMAL   1
 
#define VM_SWAP_IDLE   2
 
#define SWAPIN_INTERVAL   (MAXSLP * hz / 2)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void vm_daemon (void)
 
 SYSINIT (vmdaemon, SI_SUB_KTHREAD_VM, SI_ORDER_FIRST, kproc_start, &vm_kp)
 
 SYSCTL_INT (_vm, VM_SWAPPING_ENABLED, swap_enabled, CTLFLAG_RW, &vm_swap_enabled, 0, "Enable entire process swapout")
 
 SYSCTL_INT (_vm, OID_AUTO, swap_idle_enabled, CTLFLAG_RW, &vm_swap_idle_enabled, 0, "Allow swapout on idle criteria")
 
 SYSCTL_INT (_vm, OID_AUTO, swap_idle_threshold1, CTLFLAG_RW, &swap_idle_threshold1, 0, "Guaranteed swapped in time for a process")
 
 SYSCTL_INT (_vm, OID_AUTO, swap_idle_threshold2, CTLFLAG_RW, &swap_idle_threshold2, 0, "Time before a process will be swapped out")
 
 SYSCTL_INT (_vm, OID_AUTO, vmdaemon_timeout, CTLFLAG_RW, &vm_daemon_timeout, 0, "Time between vmdaemon runs")
 
 MTX_SYSINIT (vm_daemon, &vm_daemon_mtx, "vm daemon", MTX_DEF)
 
static void swapclear (struct proc *)
 
static int swapout (struct proc *)
 
static void vm_swapout_map_deactivate_pages (vm_map_t, long)
 
static void vm_swapout_object_deactivate (pmap_t, vm_object_t, long)
 
static void swapout_procs (int action)
 
static void vm_req_vmdaemon (int req)
 
static void vm_thread_swapout (struct thread *td)
 
static void vm_swapout_object_deactivate_page (pmap_t pmap, vm_page_t m, bool unmap)
 
void vm_swapout_run (void)
 
void vm_swapout_run_idle (void)
 
static void vm_thread_swapin (struct thread *td, int oom_alloc)
 
void faultin (struct proc *p)
 
static struct proc * swapper_selector (bool wkilled_only)
 
static bool swapper_wkilled_only (void)
 
void swapper (void)
 

Variables

static struct proc * vmproc
 
static struct kproc_desc vm_kp
 
static int vm_swap_enabled = 1
 
static int vm_swap_idle_enabled = 0
 
static int swap_idle_threshold1 = 2
 
static int swap_idle_threshold2 = 10
 
static int vm_daemon_timeout = 0
 
static int vm_pageout_req_swapout
 
static int vm_daemon_needed
 
static struct mtx vm_daemon_mtx
 
static int swapped_cnt
 
static int swap_inprogress
 
static int last_swapin
 

Macro Definition Documentation

◆ SWAPIN_INTERVAL

#define SWAPIN_INTERVAL   (MAXSLP * hz / 2)

Definition at line 727 of file vm_swapout.c.

◆ VM_SWAP_IDLE

#define VM_SWAP_IDLE   2

Definition at line 333 of file vm_swapout.c.

◆ VM_SWAP_NORMAL

#define VM_SWAP_NORMAL   1

Definition at line 332 of file vm_swapout.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ faultin()

void faultin ( struct proc *  p)

Definition at line 595 of file vm_swapout.c.

References last_swapin, swap_inprogress, swapclear(), swapped_cnt, VM_ALLOC_NORMAL, VM_ALLOC_SYSTEM, and vm_thread_swapin().

Referenced by swapper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MTX_SYSINIT()

MTX_SYSINIT ( vm_daemon  ,
vm_daemon_mtx,
"vm daemon"  ,
MTX_DEF   
)

◆ swapclear()

static void swapclear ( struct proc *  p)
static

Definition at line 870 of file vm_swapout.c.

Referenced by faultin(), and swapout().

Here is the caller graph for this function:

◆ swapout()

static int swapout ( struct proc *  p)
static

Definition at line 900 of file vm_swapout.c.

References swapclear(), vm_thread_swapout(), and vmspace_resident_count().

Referenced by swapout_procs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swapout_procs()

static void swapout_procs ( int  action)
static

Definition at line 784 of file vm_swapout.c.

References swap_idle_threshold1, swap_idle_threshold2, swapout(), swapped_cnt, VM_SWAP_IDLE, and VM_SWAP_NORMAL.

Referenced by vm_daemon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swapper()

void swapper ( void  )

Definition at line 745 of file vm_swapout.c.

◆ swapper_selector()

static struct proc * swapper_selector ( bool  wkilled_only)
static

Definition at line 662 of file vm_swapout.c.

References swapped_cnt.

Referenced by swapper().

Here is the caller graph for this function:

◆ swapper_wkilled_only()

static bool swapper_wkilled_only ( void  )
static

Definition at line 737 of file vm_swapout.c.

References all_domains, last_swapin, swap_inprogress, and SWAPIN_INTERVAL.

Referenced by swapper().

Here is the caller graph for this function:

◆ SYSCTL_INT() [1/5]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
swap_idle_enabled  ,
CTLFLAG_RW  ,
vm_swap_idle_enabled,
,
"Allow swapout on idle criteria"   
)

◆ SYSCTL_INT() [2/5]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
swap_idle_threshold1  ,
CTLFLAG_RW  ,
swap_idle_threshold1,
,
"Guaranteed swapped in time for a process"   
)

◆ SYSCTL_INT() [3/5]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
swap_idle_threshold2  ,
CTLFLAG_RW  ,
swap_idle_threshold2,
,
"Time before a process will be swapped out"   
)

◆ SYSCTL_INT() [4/5]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
vmdaemon_timeout  ,
CTLFLAG_RW  ,
vm_daemon_timeout,
,
"Time between vmdaemon runs"   
)

◆ SYSCTL_INT() [5/5]

SYSCTL_INT ( _vm  ,
VM_SWAPPING_ENABLED  ,
swap_enabled  ,
CTLFLAG_RW  ,
vm_swap_enabled,
,
"Enable entire process swapout  
)

◆ SYSINIT()

SYSINIT ( vmdaemon  ,
SI_SUB_KTHREAD_VM  ,
SI_ORDER_FIRST  ,
kproc_start  ,
vm_kp 
)

◆ vm_daemon()

◆ vm_req_vmdaemon()

static void vm_req_vmdaemon ( int  req)
static

Definition at line 359 of file vm_swapout.c.

References vm_daemon_mtx, vm_daemon_needed, and vm_pageout_req_swapout.

Referenced by vm_swapout_run(), and vm_swapout_run_idle().

Here is the caller graph for this function:

◆ vm_swapout_map_deactivate_pages()

◆ vm_swapout_object_deactivate()

static void vm_swapout_object_deactivate ( pmap_t  pmap,
vm_object_t  first_object,
long  desired 
)
static

◆ vm_swapout_object_deactivate_page()

static void vm_swapout_object_deactivate_page ( pmap_t  pmap,
vm_page_t  m,
bool  unmap 
)
static

Definition at line 180 of file vm_swapout.c.

References pmap_is_referenced(), pmap_page_exists_quick(), vm_page_active(), vm_page_deactivate(), vm_page_try_remove_all(), vm_page_tryxbusy(), vm_page_wired(), and vm_page_xunbusy.

Referenced by vm_swapout_object_deactivate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vm_swapout_run()

void vm_swapout_run ( void  )

Definition at line 336 of file vm_swapout.c.

◆ vm_swapout_run_idle()

void vm_swapout_run_idle ( void  )

Definition at line 348 of file vm_swapout.c.

◆ vm_thread_swapin()

static void vm_thread_swapin ( struct thread *  td,
int  oom_alloc 
)
static

Definition at line 559 of file vm_swapout.c.

References KSTACK_MAX_PAGES, kstack_object, pmap_qenter(), vm_object_pip_add(), vm_object_pip_wakeup(), VM_OBJECT_WLOCK, VM_OBJECT_WUNLOCK, vm_page_all_valid(), vm_page_assert_xbusied, vm_pager_get_pages(), vm_pager_has_page(), VM_PAGER_OK, and vm_thread_stack_back().

Referenced by faultin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vm_thread_swapout()

static void vm_thread_swapout ( struct thread *  td)
static

Definition at line 531 of file vm_swapout.c.

References kstack_object, pmap_qremove(), PQ_LAUNDRY, VM_OBJECT_WLOCK, VM_OBJECT_WUNLOCK, vm_page_dirty(), vm_page_lookup(), vm_page_unwire(), and vm_page_xunbusy_unchecked.

Referenced by swapout().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ last_swapin

int last_swapin
static

Definition at line 169 of file vm_swapout.c.

Referenced by faultin(), and swapper_wkilled_only().

◆ swap_idle_threshold1

int swap_idle_threshold1 = 2
static

Definition at line 142 of file vm_swapout.c.

Referenced by swapout_procs().

◆ swap_idle_threshold2

int swap_idle_threshold2 = 10
static

Definition at line 151 of file vm_swapout.c.

Referenced by swapout_procs().

◆ swap_inprogress

int swap_inprogress
static

Definition at line 168 of file vm_swapout.c.

Referenced by faultin(), and swapper_wkilled_only().

◆ swapped_cnt

int swapped_cnt
static

Definition at line 167 of file vm_swapout.c.

Referenced by faultin(), swapout_procs(), and swapper_selector().

◆ vm_daemon_mtx

struct mtx vm_daemon_mtx
static

Definition at line 163 of file vm_swapout.c.

Referenced by vm_daemon(), and vm_req_vmdaemon().

◆ vm_daemon_needed

int vm_daemon_needed
static

Definition at line 162 of file vm_swapout.c.

Referenced by vm_daemon(), and vm_req_vmdaemon().

◆ vm_daemon_timeout

int vm_daemon_timeout = 0
static

Definition at line 156 of file vm_swapout.c.

Referenced by vm_daemon().

◆ vm_kp

struct kproc_desc vm_kp
static
Initial value:
= {
"vmdaemon",
}
static struct proc * vmproc
Definition: vm_swapout.c:120
static void vm_daemon(void)
Definition: vm_swapout.c:373

Definition at line 122 of file vm_swapout.c.

◆ vm_pageout_req_swapout

int vm_pageout_req_swapout
static

Definition at line 161 of file vm_swapout.c.

Referenced by vm_daemon(), and vm_req_vmdaemon().

◆ vm_swap_enabled

int vm_swap_enabled = 1
static

Definition at line 129 of file vm_swapout.c.

Referenced by vm_swapout_run().

◆ vm_swap_idle_enabled

int vm_swap_idle_enabled = 0
static

Definition at line 130 of file vm_swapout.c.

Referenced by vm_swapout_run_idle().

◆ vmproc

struct proc* vmproc
static

Definition at line 120 of file vm_swapout.c.