FreeBSD virtual memory subsystem code
vm_pageout.c File Reference
#include <sys/cdefs.h>
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/blockcount.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/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_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/vm_pagequeue.h>
#include <vm/swap_pager.h>
#include <vm/vm_extern.h>
#include <vm/uma.h>
Include dependency graph for vm_pageout.c:

Go to the source code of this file.

Data Structures

struct  scan_state
 

Macros

#define VM_LAUNDER_RATE   10
 
#define VM_INACT_SCAN_RATE   10
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void vm_pageout (void)
 
static void vm_pageout_init (void)
 
static int vm_pageout_clean (vm_page_t m, int *numpagedout)
 
static int vm_pageout_cluster (vm_page_t m)
 
static void vm_pageout_mightbe_oom (struct vm_domain *vmd, int page_shortage, int starting_page_shortage)
 
 SYSINIT (pagedaemon_init, SI_SUB_KTHREAD_PAGE, SI_ORDER_FIRST, vm_pageout_init, NULL)
 
 SYSINIT (pagedaemon, SI_SUB_KTHREAD_PAGE, SI_ORDER_SECOND, kproc_start, &page_kp)
 
 SDT_PROVIDER_DEFINE (vm)
 
 SDT_PROBE_DEFINE (vm,,, vm__lowmem_scan)
 
 SYSCTL_INT (_vm, OID_AUTO, panic_on_oom, CTLFLAG_RWTUN, &vm_panic_on_oom, 0, "Panic on the given number of out-of-memory errors instead of " "killing the largest process")
 
 SYSCTL_INT (_vm, OID_AUTO, pageout_update_period, CTLFLAG_RWTUN, &vm_pageout_update_period, 0, "Maximum active LRU update period")
 
 SYSCTL_INT (_vm, OID_AUTO, pageout_cpus_per_thread, CTLFLAG_RDTUN, &pageout_cpus_per_thread, 0, "Number of CPUs per pagedaemon worker thread")
 
 SYSCTL_INT (_vm, OID_AUTO, lowmem_period, CTLFLAG_RWTUN, &lowmem_period, 0, "Low memory callback period")
 
 SYSCTL_INT (_vm, OID_AUTO, disable_swapspace_pageouts, CTLFLAG_RWTUN, &disable_swap_pageouts, 0, "Disallow swapout of dirty pages")
 
 SYSCTL_INT (_vm, OID_AUTO, pageout_lock_miss, CTLFLAG_RD, &pageout_lock_miss, 0, "vget() lock misses during pageout")
 
 SYSCTL_INT (_vm, OID_AUTO, pageout_oom_seq, CTLFLAG_RWTUN, &vm_pageout_oom_seq, 0, "back-to-back calls to oom detector to start OOM")
 
 SYSCTL_INT (_vm, OID_AUTO, act_scan_laundry_weight, CTLFLAG_RWTUN, &act_scan_laundry_weight, 0, "weight given to clean vs. dirty pages in active queue scans")
 
 SYSCTL_UINT (_vm, OID_AUTO, background_launder_rate, CTLFLAG_RWTUN, &vm_background_launder_rate, 0, "background laundering rate, in kilobytes per second")
 
 SYSCTL_UINT (_vm, OID_AUTO, background_launder_max, CTLFLAG_RWTUN, &vm_background_launder_max, 0, "background laundering cap, in kilobytes")
 
 SYSCTL_ULONG (_vm, OID_AUTO, max_user_wired, CTLFLAG_RW, &vm_page_max_user_wired, 0, "system-wide limit to user-wired page count")
 
static u_int isqrt (u_int num)
 
static int vm_pageout_launder (struct vm_domain *vmd, int launder, bool in_shortfall)
 
static void vm_pageout_laundry_worker (void *arg)
 
static void vm_pageout_init_scan (struct scan_state *ss, struct vm_pagequeue *pq, vm_page_t marker, vm_page_t after, int maxscan)
 
static void vm_pageout_end_scan (struct scan_state *ss)
 
static __always_inline void vm_pageout_collect_batch (struct scan_state *ss, const bool dequeue)
 
static __always_inline vm_page_t vm_pageout_next (struct scan_state *ss, const bool dequeue)
 
static __always_inline bool vm_pageout_defer (vm_page_t m, const uint8_t queue, const bool enqueued)
 
int vm_pageout_flush (vm_page_t *mc, int count, int flags, int mreq, int *prunlen, boolean_t *eio)
 
static void vm_pageout_swapon (void *arg __unused, struct swdevt *sp __unused)
 
static void vm_pageout_swapoff (void *arg __unused, struct swdevt *sp __unused)
 
static int vm_pageout_active_target (struct vm_domain *vmd)
 
static void vm_pageout_scan_active (struct vm_domain *vmd, int page_shortage)
 
static int vm_pageout_reinsert_inactive_page (struct vm_pagequeue *pq, vm_page_t marker, vm_page_t m)
 
static void vm_pageout_reinsert_inactive (struct scan_state *ss, struct vm_batchqueue *bq, vm_page_t m)
 
static void vm_pageout_scan_inactive (struct vm_domain *vmd, int page_shortage)
 
static int vm_pageout_inactive_dispatch (struct vm_domain *vmd, int shortage)
 
static int vm_pageout_inactive (struct vm_domain *vmd, int shortage, int *addl_shortage)
 
static long vm_pageout_oom_pagecount (struct vmspace *vmspace)
 
 SYSCTL_INT (_vm, OID_AUTO, oom_pf_secs, CTLFLAG_RWTUN, &vm_oom_pf_secs, 0, "")
 
void vm_pageout_oom (int shortage)
 
static bool vm_pageout_lowmem (void)
 
static void vm_pageout_worker (void *arg)
 
static void vm_pageout_helper (void *arg)
 
static int get_pageout_threads_per_domain (const struct vm_domain *vmd)
 
static void vm_pageout_init_domain (int domain)
 
void pagedaemon_wakeup (int domain)
 

Variables

struct proc * pageproc
 
static struct kproc_desc page_kp
 
static int swapdev_enabled
 
int vm_pageout_page_count = 32
 
static int vm_panic_on_oom = 0
 
static int vm_pageout_update_period
 
static int pageout_cpus_per_thread = 16
 
static int lowmem_period = 10
 
static int disable_swap_pageouts
 
static int pageout_lock_miss
 
static int vm_pageout_oom_seq = 12
 
static int act_scan_laundry_weight = 3
 
static u_int vm_background_launder_rate = 4096
 
static u_int vm_background_launder_max = 20 * 1024
 
u_long vm_page_max_user_wired
 
static int vm_pageout_oom_vote
 
static int vm_oom_ratelim_last
 
static int vm_oom_pf_secs = 10
 
static struct mtx vm_oom_ratelim_mtx
 

Macro Definition Documentation

◆ VM_INACT_SCAN_RATE

#define VM_INACT_SCAN_RATE   10

Definition at line 149 of file vm_pageout.c.

◆ VM_LAUNDER_RATE

#define VM_LAUNDER_RATE   10

Definition at line 148 of file vm_pageout.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ get_pageout_threads_per_domain()

static int get_pageout_threads_per_domain ( const struct vm_domain vmd)
static

Definition at line 2214 of file vm_pageout.c.

References pageout_cpus_per_thread, VM_DOMAIN_EMPTY, vm_ndomains, and vm_domain::vmd_domain.

Referenced by vm_pageout_init_domain().

Here is the caller graph for this function:

◆ isqrt()

static u_int isqrt ( u_int  num)
static

Definition at line 965 of file vm_pageout.c.

Referenced by vm_pageout_laundry_worker().

Here is the caller graph for this function:

◆ pagedaemon_wakeup()

void pagedaemon_wakeup ( int  domain)

Definition at line 2407 of file vm_pageout.c.

References pageproc, VM_DOMAIN, vm_domain_pageout_assert_unlocked, vm_domain_pageout_lock, vm_domain_pageout_unlock, and vm_domain::vmd_pageout_wanted.

Referenced by _vm_domain_allocate().

Here is the caller graph for this function:

◆ SDT_PROBE_DEFINE()

SDT_PROBE_DEFINE ( vm  ,
vm__lowmem_scan   
)

◆ SDT_PROVIDER_DEFINE()

SDT_PROVIDER_DEFINE ( vm  )

◆ SYSCTL_INT() [1/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
act_scan_laundry_weight  ,
CTLFLAG_RWTUN  ,
act_scan_laundry_weight,
,
"weight given to clean vs. dirty pages in active queue scans"   
)

◆ SYSCTL_INT() [2/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
disable_swapspace_pageouts  ,
CTLFLAG_RWTUN  ,
disable_swap_pageouts,
,
"Disallow swapout of dirty pages"   
)

◆ SYSCTL_INT() [3/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
lowmem_period  ,
CTLFLAG_RWTUN  ,
lowmem_period,
,
"Low memory callback period"   
)

◆ SYSCTL_INT() [4/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
oom_pf_secs  ,
CTLFLAG_RWTUN  ,
vm_oom_pf_secs,
,
""   
)

◆ SYSCTL_INT() [5/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
pageout_cpus_per_thread  ,
CTLFLAG_RDTUN  ,
pageout_cpus_per_thread,
,
"Number of CPUs per pagedaemon worker thread"   
)

◆ SYSCTL_INT() [6/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
pageout_lock_miss  ,
CTLFLAG_RD  ,
pageout_lock_miss,
,
"vget() lock misses during pageout"   
)

◆ SYSCTL_INT() [7/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
pageout_oom_seq  ,
CTLFLAG_RWTUN  ,
vm_pageout_oom_seq,
,
"back-to-back calls to oom detector to start OOM"   
)

◆ SYSCTL_INT() [8/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
pageout_update_period  ,
CTLFLAG_RWTUN  ,
vm_pageout_update_period,
,
"Maximum active LRU update period"   
)

◆ SYSCTL_INT() [9/9]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
panic_on_oom  ,
CTLFLAG_RWTUN  ,
vm_panic_on_oom,
,
"Panic on the given number of out-of-memory errors instead of " "killing the largest process"   
)

◆ SYSCTL_UINT() [1/2]

SYSCTL_UINT ( _vm  ,
OID_AUTO  ,
background_launder_max  ,
CTLFLAG_RWTUN  ,
vm_background_launder_max,
,
"background laundering  cap,
in kilobytes"   
)

◆ SYSCTL_UINT() [2/2]

SYSCTL_UINT ( _vm  ,
OID_AUTO  ,
background_launder_rate  ,
CTLFLAG_RWTUN  ,
vm_background_launder_rate,
,
"background laundering  rate,
in kilobytes per second"   
)

◆ SYSCTL_ULONG()

SYSCTL_ULONG ( _vm  ,
OID_AUTO  ,
max_user_wired  ,
CTLFLAG_RW  ,
vm_page_max_user_wired,
,
"system-wide limit to user-wired page count"   
)

◆ SYSINIT() [1/2]

SYSINIT ( pagedaemon  ,
SI_SUB_KTHREAD_PAGE  ,
SI_ORDER_SECOND  ,
kproc_start  ,
page_kp 
)

◆ SYSINIT() [2/2]

SYSINIT ( pagedaemon_init  ,
SI_SUB_KTHREAD_PAGE  ,
SI_ORDER_FIRST  ,
vm_pageout_init  ,
NULL   
)

◆ vm_pageout()

static void vm_pageout ( void  )
static

◆ vm_pageout_active_target()

static int vm_pageout_active_target ( struct vm_domain vmd)
static

Definition at line 1155 of file vm_pageout.c.

References act_scan_laundry_weight, vm_pagequeue::pq_cnt, PQ_INACTIVE, PQ_LAUNDRY, vm_paging_target(), vm_domain::vmd_inactive_target, and vm_domain::vmd_pagequeues.

Referenced by vm_pageout_worker().

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

◆ vm_pageout_clean()

static int vm_pageout_clean ( vm_page_t  m,
int *  numpagedout 
)
static

◆ vm_pageout_cluster()

static int vm_pageout_cluster ( vm_page_t  m)
static

◆ vm_pageout_collect_batch()

static __always_inline void vm_pageout_collect_batch ( struct scan_state ss,
const bool  dequeue 
)
static

◆ vm_pageout_defer()

static __always_inline bool vm_pageout_defer ( vm_page_t  m,
const uint8_t  queue,
const bool  enqueued 
)
static

Definition at line 331 of file vm_pageout.c.

References vm_page_astate::flags, PGA_ENQUEUED, PGA_QUEUE_OP_MASK, vm_page_astate::queue, vm_page_astate_load(), and vm_page_pqbatch_submit().

Referenced by vm_pageout_launder(), vm_pageout_scan_active(), and vm_pageout_scan_inactive().

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

◆ vm_pageout_end_scan()

static void vm_pageout_end_scan ( struct scan_state ss)
static

Definition at line 246 of file vm_pageout.c.

References scan_state::marker, PGA_ENQUEUED, scan_state::pq, vm_pagequeue::pq_pdpages, vm_pagequeue::pq_pl, scan_state::scanned, vm_page_aflag_clear(), and vm_pagequeue_assert_locked.

Referenced by vm_pageout_launder(), vm_pageout_scan_active(), and vm_pageout_scan_inactive().

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

◆ vm_pageout_flush()

int vm_pageout_flush ( vm_page_t *  mc,
int  count,
int  flags,
int  mreq,
int *  prunlen,
boolean_t *  eio 
)

◆ vm_pageout_helper()

static void vm_pageout_helper ( void *  arg)
static

Definition at line 2187 of file vm_pageout.c.

References VM_DOMAIN, vm_domain_pageout_lock, vm_domain_pageout_lockptr, vm_domain_pageout_unlock, vm_pageout_scan_inactive(), vm_domain::vmd_inactive_running, vm_domain::vmd_inactive_shortage, and vm_domain::vmd_inactive_starting.

Referenced by vm_pageout().

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

◆ vm_pageout_inactive()

static int vm_pageout_inactive ( struct vm_domain vmd,
int  shortage,
int *  addl_shortage 
)
static

◆ vm_pageout_inactive_dispatch()

static int vm_pageout_inactive_dispatch ( struct vm_domain vmd,
int  shortage 
)
static

◆ vm_pageout_init()

◆ vm_pageout_init_domain()

◆ vm_pageout_init_scan()

static void vm_pageout_init_scan ( struct scan_state ss,
struct vm_pagequeue pq,
vm_page_t  marker,
vm_page_t  after,
int  maxscan 
)
static

◆ vm_pageout_launder()

◆ vm_pageout_laundry_worker()

◆ vm_pageout_lowmem()

static bool vm_pageout_lowmem ( void  )
static

Definition at line 2049 of file vm_pageout.c.

References lowmem_period, uma_reclaim(), UMA_RECLAIM_TRIM, uma_reclaim_wakeup(), and VM_LOW_PAGES.

Referenced by vm_pageout_worker().

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

◆ vm_pageout_mightbe_oom()

static void vm_pageout_mightbe_oom ( struct vm_domain vmd,
int  page_shortage,
int  starting_page_shortage 
)
static

Definition at line 1794 of file vm_pageout.c.

References vm_ndomains, VM_OOM_MEM, vm_pageout_oom(), vm_pageout_oom_seq, vm_pageout_oom_vote, vm_domain::vmd_oom, and vm_domain::vmd_oom_seq.

Referenced by vm_pageout_inactive().

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

◆ vm_pageout_next()

static __always_inline vm_page_t vm_pageout_next ( struct scan_state ss,
const bool  dequeue 
)
static

Definition at line 318 of file vm_pageout.c.

References scan_state::bq, vm_batchqueue::bq_cnt, vm_batchqueue_pop(), and vm_pageout_collect_batch().

Referenced by vm_pageout_launder(), vm_pageout_scan_active(), and vm_pageout_scan_inactive().

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

◆ vm_pageout_oom()

void vm_pageout_oom ( int  shortage)

◆ vm_pageout_oom_pagecount()

◆ vm_pageout_reinsert_inactive()

static void vm_pageout_reinsert_inactive ( struct scan_state ss,
struct vm_batchqueue bq,
vm_page_t  m 
)
static

Definition at line 1399 of file vm_pageout.c.

References scan_state::marker, scan_state::pq, vm_batchqueue_init(), vm_batchqueue_insert(), vm_batchqueue_pop(), vm_pageout_reinsert_inactive_page(), vm_pagequeue_cnt_add(), vm_pagequeue_lock, and vm_pagequeue_unlock.

Referenced by vm_pageout_scan_inactive().

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

◆ vm_pageout_reinsert_inactive_page()

static int vm_pageout_reinsert_inactive_page ( struct vm_pagequeue pq,
vm_page_t  marker,
vm_page_t  m 
)
static

Definition at line 1377 of file vm_pageout.c.

References vm_page_astate::flags, PGA_ENQUEUED, PQ_INACTIVE, vm_page_astate::queue, vm_page_aflag_set(), vm_page_astate_load(), and vm_pagequeue_assert_locked.

Referenced by vm_pageout_reinsert_inactive().

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

◆ vm_pageout_scan_active()

◆ vm_pageout_scan_inactive()

◆ vm_pageout_swapoff()

static void vm_pageout_swapoff ( void *arg  __unused,
struct swdevt *sp  __unused 
)
static

Definition at line 588 of file vm_pageout.c.

References swap_pager_nswapdev(), and swapdev_enabled.

Referenced by vm_pageout_laundry_worker().

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

◆ vm_pageout_swapon()

static void vm_pageout_swapon ( void *arg  __unused,
struct swdevt *sp  __unused 
)
static

Definition at line 581 of file vm_pageout.c.

References swapdev_enabled.

Referenced by vm_pageout_laundry_worker().

Here is the caller graph for this function:

◆ vm_pageout_worker()

static void vm_pageout_worker ( void *  arg)
static

Variable Documentation

◆ act_scan_laundry_weight

int act_scan_laundry_weight = 3
static

Definition at line 189 of file vm_pageout.c.

Referenced by vm_pageout_active_target(), and vm_pageout_scan_active().

◆ disable_swap_pageouts

int disable_swap_pageouts
static

Definition at line 174 of file vm_pageout.c.

Referenced by vm_pageout_launder().

◆ lowmem_period

int lowmem_period = 10
static

Definition at line 170 of file vm_pageout.c.

Referenced by vm_pageout_lowmem().

◆ page_kp

struct kproc_desc page_kp
static
Initial value:
= {
"pagedaemon",
}
static void vm_pageout(void)
Definition: vm_pageout.c:2354
struct proc * pageproc
Definition: vm_pageout.c:134

Definition at line 136 of file vm_pageout.c.

◆ pageout_cpus_per_thread

int pageout_cpus_per_thread = 16
static

Definition at line 165 of file vm_pageout.c.

Referenced by get_pageout_threads_per_domain().

◆ pageout_lock_miss

int pageout_lock_miss
static

Definition at line 179 of file vm_pageout.c.

Referenced by vm_pageout_launder().

◆ pageproc

◆ swapdev_enabled

int swapdev_enabled
static

◆ vm_background_launder_max

u_int vm_background_launder_max = 20 * 1024
static

Definition at line 199 of file vm_pageout.c.

Referenced by vm_pageout_laundry_worker().

◆ vm_background_launder_rate

u_int vm_background_launder_rate = 4096
static

Definition at line 194 of file vm_pageout.c.

Referenced by vm_pageout_laundry_worker().

◆ vm_oom_pf_secs

int vm_oom_pf_secs = 10
static

Definition at line 1897 of file vm_pageout.c.

Referenced by vm_pageout_oom().

◆ vm_oom_ratelim_last

int vm_oom_ratelim_last
static

Definition at line 1896 of file vm_pageout.c.

Referenced by vm_pageout_oom().

◆ vm_oom_ratelim_mtx

struct mtx vm_oom_ratelim_mtx
static

Definition at line 1900 of file vm_pageout.c.

Referenced by vm_pageout(), and vm_pageout_oom().

◆ vm_page_max_user_wired

u_long vm_page_max_user_wired

Definition at line 204 of file vm_pageout.c.

Referenced by kern_mlock(), vm_pageout_init(), and vslock().

◆ vm_pageout_oom_seq

int vm_pageout_oom_seq = 12
static

Definition at line 184 of file vm_pageout.c.

Referenced by vm_pageout_mightbe_oom().

◆ vm_pageout_oom_vote

int vm_pageout_oom_vote
static

Definition at line 1786 of file vm_pageout.c.

Referenced by vm_pageout_mightbe_oom().

◆ vm_pageout_page_count

int vm_pageout_page_count = 32

◆ vm_pageout_update_period

int vm_pageout_update_period
static

Definition at line 160 of file vm_pageout.c.

Referenced by vm_pageout_init(), and vm_pageout_scan_active().

◆ vm_panic_on_oom

int vm_panic_on_oom = 0
static

Definition at line 154 of file vm_pageout.c.

Referenced by vm_pageout_oom().