FreeBSD virtual memory subsystem code
vm_fault.c File Reference
#include <sys/cdefs.h>
#include "opt_ktrace.h"
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mman.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/racct.h>
#include <sys/refcount.h>
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/signalvar.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/vmmeter.h>
#include <sys/vnode.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pageout.h>
#include <vm/vm_kern.h>
#include <vm/vm_pager.h>
#include <vm/vm_extern.h>
#include <vm/vm_reserv.h>
Include dependency graph for vm_fault.c:

Go to the source code of this file.

Data Structures

struct  faultstate
 

Macros

#define PFBAK   4
 
#define PFFOR   4
 
#define VM_FAULT_READ_DEFAULT   (1 + VM_FAULT_READ_AHEAD_INIT)
 
#define VM_FAULT_DONTNEED_MIN   1048576
 
#define UCODE_PAGEFLT   12
 

Enumerations

enum  fault_status {
  FAULT_SUCCESS = 1 , FAULT_FAILURE , FAULT_CONTINUE , FAULT_RESTART ,
  FAULT_OUT_OF_BOUNDS , FAULT_HARD , FAULT_SOFT , FAULT_PROTECTION_FAILURE
}
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void vm_fault_dontneed (const struct faultstate *fs, vm_offset_t vaddr, int ahead)
 
static void vm_fault_prefault (const struct faultstate *fs, vm_offset_t addra, int backward, int forward, bool obj_locked)
 
 SYSCTL_INT (_vm, OID_AUTO, pfault_oom_attempts, CTLFLAG_RWTUN, &vm_pfault_oom_attempts, 0, "Number of page allocation attempts in page fault handler before it " "triggers OOM handling")
 
 SYSCTL_INT (_vm, OID_AUTO, pfault_oom_wait, CTLFLAG_RWTUN, &vm_pfault_oom_wait, 0, "Number of seconds to wait for free pages before retrying " "the page fault handler")
 
static void fault_page_release (vm_page_t *mp)
 
static void fault_page_free (vm_page_t *mp)
 
static void unlock_map (struct faultstate *fs)
 
static void unlock_vp (struct faultstate *fs)
 
static void fault_deallocate (struct faultstate *fs)
 
static void unlock_and_deallocate (struct faultstate *fs)
 
static void vm_fault_dirty (struct faultstate *fs, vm_page_t m)
 
static enum fault_status vm_fault_soft_fast (struct faultstate *fs)
 
static void vm_fault_restore_map_lock (struct faultstate *fs)
 
static void vm_fault_populate_check_page (vm_page_t m)
 
static void vm_fault_populate_cleanup (vm_object_t object, vm_pindex_t first, vm_pindex_t last)
 
static enum fault_status vm_fault_populate (struct faultstate *fs)
 
 SYSCTL_INT (_machdep, OID_AUTO, prot_fault_translation, CTLFLAG_RWTUN, &prot_fault_translation, 0, "Control signal to deliver on protection fault")
 
int vm_fault_trap (vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, int fault_flags, int *signo, int *ucode)
 
static enum fault_status vm_fault_lock_vnode (struct faultstate *fs, bool objlocked)
 
static int vm_fault_readahead (struct faultstate *fs)
 
static int vm_fault_lookup (struct faultstate *fs)
 
static int vm_fault_relookup (struct faultstate *fs)
 
static void vm_fault_cow (struct faultstate *fs)
 
static bool vm_fault_next (struct faultstate *fs)
 
static void vm_fault_zerofill (struct faultstate *fs)
 
static bool vm_fault_allocate_oom (struct faultstate *fs)
 
static enum fault_status vm_fault_allocate (struct faultstate *fs)
 
static enum fault_status vm_fault_getpages (struct faultstate *fs, int *behindp, int *aheadp)
 
static void vm_fault_busy_sleep (struct faultstate *fs)
 
static enum fault_status vm_fault_object (struct faultstate *fs, int *behindp, int *aheadp)
 
int vm_fault (vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, int fault_flags, vm_page_t *m_hold)
 
int vm_fault_quick_hold_pages (vm_map_t map, vm_offset_t addr, vm_size_t len, vm_prot_t prot, vm_page_t *ma, int max_count)
 
void vm_fault_copy_entry (vm_map_t dst_map, vm_map_t src_map, vm_map_entry_t dst_entry, vm_map_entry_t src_entry, vm_ooffset_t *fork_charge)
 
int vm_fault_disable_pagefaults (void)
 
void vm_fault_enable_pagefaults (int save)
 

Variables

static int vm_pfault_oom_attempts = 3
 
static int vm_pfault_oom_wait = 10
 
static int prot_fault_translation
 

Macro Definition Documentation

◆ PFBAK

#define PFBAK   4

Definition at line 114 of file vm_fault.c.

◆ PFFOR

#define PFFOR   4

Definition at line 115 of file vm_fault.c.

◆ UCODE_PAGEFLT

#define UCODE_PAGEFLT   12

Definition at line 634 of file vm_fault.c.

◆ VM_FAULT_DONTNEED_MIN

#define VM_FAULT_DONTNEED_MIN   1048576

Definition at line 119 of file vm_fault.c.

◆ VM_FAULT_READ_DEFAULT

#define VM_FAULT_READ_DEFAULT   (1 + VM_FAULT_READ_AHEAD_INIT)

Definition at line 117 of file vm_fault.c.

Enumeration Type Documentation

◆ fault_status

Enumerator
FAULT_SUCCESS 
FAULT_FAILURE 
FAULT_CONTINUE 
FAULT_RESTART 
FAULT_OUT_OF_BOUNDS 
FAULT_HARD 
FAULT_SOFT 
FAULT_PROTECTION_FAILURE 

Definition at line 161 of file vm_fault.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ fault_deallocate()

static void fault_deallocate ( struct faultstate fs)
static

◆ fault_page_free()

static void fault_page_free ( vm_page_t *  mp)
inlinestatic

Definition at line 208 of file vm_fault.c.

References VM_OBJECT_ASSERT_WLOCKED, vm_page_free(), vm_page_wired(), and vm_page_xunbusy.

Referenced by fault_deallocate(), vm_fault(), vm_fault_getpages(), and vm_fault_next().

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

◆ fault_page_release()

static void fault_page_release ( vm_page_t *  mp)
inlinestatic

Definition at line 190 of file vm_fault.c.

References vm_page_deactivate(), and vm_page_xunbusy.

Referenced by fault_deallocate(), and vm_fault_busy_sleep().

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

◆ SYSCTL_INT() [1/3]

SYSCTL_INT ( _machdep  ,
OID_AUTO  ,
prot_fault_translation  ,
CTLFLAG_RWTUN  ,
prot_fault_translation,
,
"Control signal to deliver on protection fault"   
)

◆ SYSCTL_INT() [2/3]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
pfault_oom_attempts  ,
CTLFLAG_RWTUN  ,
vm_pfault_oom_attempts,
,
"Number of page allocation attempts in page fault handler before it " "triggers OOM handling"   
)

◆ SYSCTL_INT() [3/3]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
pfault_oom_wait  ,
CTLFLAG_RWTUN  ,
vm_pfault_oom_wait,
,
"Number of seconds to wait for free pages before retrying " "the page fault handler"   
)

◆ unlock_and_deallocate()

static void unlock_and_deallocate ( struct faultstate fs)
static

Definition at line 262 of file vm_fault.c.

References fault_deallocate(), faultstate::object, and VM_OBJECT_WUNLOCK.

Referenced by vm_fault(), vm_fault_allocate(), vm_fault_allocate_oom(), vm_fault_getpages(), vm_fault_lock_vnode(), and vm_fault_object().

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

◆ unlock_map()

static void unlock_map ( struct faultstate fs)
inlinestatic

Definition at line 224 of file vm_fault.c.

References faultstate::entry, faultstate::lookup_still_valid, faultstate::map, and vm_map_lookup_done().

Referenced by fault_deallocate(), vm_fault_busy_sleep(), vm_fault_getpages(), and vm_fault_populate().

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

◆ unlock_vp()

static void unlock_vp ( struct faultstate fs)
static

Definition at line 234 of file vm_fault.c.

References faultstate::vp.

Referenced by fault_deallocate(), vm_fault_lock_vnode(), vm_fault_lookup(), and vm_fault_populate().

Here is the caller graph for this function:

◆ vm_fault()

int vm_fault ( vm_map_t  map,
vm_offset_t  vaddr,
vm_prot_t  fault_type,
int  fault_flags,
vm_page_t *  m_hold 
)

Definition at line 1447 of file vm_fault.c.

References vm_map_entry::eflags, faultstate::entry, FAULT_CONTINUE, fault_deallocate(), FAULT_FAILURE, faultstate::fault_flags, FAULT_HARD, FAULT_OUT_OF_BOUNDS, fault_page_free(), FAULT_PROTECTION_FAILURE, FAULT_RESTART, FAULT_SOFT, FAULT_SUCCESS, faultstate::fault_type, faultstate::first_m, faultstate::first_object, faultstate::first_pindex, KERN_FAILURE, KERN_OUT_OF_BOUNDS, KERN_PROTECTION_FAILURE, KERN_RESOURCE_SHORTAGE, KERN_RESTART, KERN_SUCCESS, faultstate::lookup_still_valid, faultstate::m, faultstate::m_cow, faultstate::m_hold, faultstate::map, MAP_ENTRY_SPLIT_BOUNDARY_MASK, faultstate::nera, vm_map_entry::next_read, faultstate::object, OBJT_VNODE, faultstate::oom_started, PFBAK, PFFOR, faultstate::pindex, vm_map::pmap, pmap_enter(), PMAP_ENTER_WIRED, faultstate::prot, vm_object::type, unlock_and_deallocate(), faultstate::vaddr, vm_fault_allocate(), vm_fault_cow(), vm_fault_dirty(), VM_FAULT_DIRTY, vm_fault_lookup(), vm_fault_next(), VM_FAULT_NOFILL, vm_fault_object(), vm_fault_prefault(), vm_fault_relookup(), vm_fault_soft_fast(), VM_FAULT_WIRE, vm_fault_zerofill(), VM_OBJECT_ASSERT_UNLOCKED, vm_object_pip_add(), vm_object_reference_locked(), VM_OBJECT_RLOCK, VM_OBJECT_RUNLOCK, VM_OBJECT_TRYUPGRADE, VM_OBJECT_WLOCK, VM_OBJECT_WUNLOCK, vm_page_activate(), vm_page_all_valid(), vm_page_assert_xbusied, vm_page_wire(), vm_page_xunbusy, VM_PROT_COPY, VM_PROT_WRITE, faultstate::vp, and faultstate::wired.

Referenced by vm_fault_quick_hold_pages(), vm_fault_trap(), and vm_map_wire_locked().

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

◆ vm_fault_allocate()

◆ vm_fault_allocate_oom()

static bool vm_fault_allocate_oom ( struct faultstate fs)
static

Definition at line 1111 of file vm_fault.c.

References faultstate::oom_start_time, faultstate::oom_started, unlock_and_deallocate(), VM_OOM_MEM_PF, vm_pageout_oom(), vm_pfault_oom_attempts, and vm_pfault_oom_wait.

Referenced by vm_fault_allocate().

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

◆ vm_fault_busy_sleep()

static void vm_fault_busy_sleep ( struct faultstate fs)
static

◆ vm_fault_copy_entry()

◆ vm_fault_cow()

◆ vm_fault_dirty()

static void vm_fault_dirty ( struct faultstate fs,
vm_page_t  m 
)
static

◆ vm_fault_disable_pagefaults()

int vm_fault_disable_pagefaults ( void  )

Definition at line 2170 of file vm_fault.c.

◆ vm_fault_dontneed()

static void vm_fault_dontneed ( const struct faultstate fs,
vm_offset_t  vaddr,
int  ahead 
)
static

◆ vm_fault_enable_pagefaults()

void vm_fault_enable_pagefaults ( int  save)

Definition at line 2177 of file vm_fault.c.

◆ vm_fault_getpages()

◆ vm_fault_lock_vnode()

static enum fault_status vm_fault_lock_vnode ( struct faultstate fs,
bool  objlocked 
)
static

Definition at line 729 of file vm_fault.c.

References FAULT_CONTINUE, fault_deallocate(), FAULT_RESTART, vm_object::handle, faultstate::object, OBJT_VNODE, vm_object::type, unlock_and_deallocate(), unlock_vp(), and faultstate::vp.

Referenced by vm_fault_allocate(), and vm_fault_getpages().

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

◆ vm_fault_lookup()

◆ vm_fault_next()

static bool vm_fault_next ( struct faultstate fs)
static

◆ vm_fault_object()

◆ vm_fault_populate()

◆ vm_fault_populate_check_page()

static void vm_fault_populate_check_page ( vm_page_t  m)
static

Definition at line 409 of file vm_fault.c.

References vm_page_all_valid(), and vm_page_xbusied.

Referenced by vm_fault_populate(), and vm_fault_populate_cleanup().

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

◆ vm_fault_populate_cleanup()

static void vm_fault_populate_cleanup ( vm_object_t  object,
vm_pindex_t  first,
vm_pindex_t  last 
)
static

Definition at line 423 of file vm_fault.c.

References vm_fault_populate_check_page(), VM_OBJECT_ASSERT_WLOCKED, vm_page_deactivate(), vm_page_lookup(), vm_page_next(), and vm_page_xunbusy.

Referenced by vm_fault_populate().

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

◆ vm_fault_prefault()

static void vm_fault_prefault ( const struct faultstate fs,
vm_offset_t  addra,
int  backward,
int  forward,
bool  obj_locked 
)
static

◆ vm_fault_quick_hold_pages()

int vm_fault_quick_hold_pages ( vm_map_t  map,
vm_offset_t  addr,
vm_size_t  len,
vm_prot_t  prot,
vm_page_t *  ma,
int  max_count 
)

◆ vm_fault_readahead()

static int vm_fault_readahead ( struct faultstate fs)
static

◆ vm_fault_relookup()

◆ vm_fault_restore_map_lock()

static void vm_fault_restore_map_lock ( struct faultstate fs)
static

◆ vm_fault_soft_fast()

◆ vm_fault_trap()

int vm_fault_trap ( vm_map_t  map,
vm_offset_t  vaddr,
vm_prot_t  fault_type,
int  fault_flags,
int *  signo,
int *  ucode 
)

◆ vm_fault_zerofill()

static void vm_fault_zerofill ( struct faultstate fs)
static

Definition at line 1077 of file vm_fault.c.

References faultstate::first_m, faultstate::first_object, faultstate::first_pindex, faultstate::m, faultstate::object, PG_ZERO, faultstate::pindex, pmap_zero_page(), vm_object_pip_wakeup(), and vm_page_valid().

Referenced by vm_fault().

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

Variable Documentation

◆ prot_fault_translation

int prot_fault_translation
static

Definition at line 628 of file vm_fault.c.

Referenced by vm_fault_trap().

◆ vm_pfault_oom_attempts

int vm_pfault_oom_attempts = 3
static

Definition at line 177 of file vm_fault.c.

Referenced by vm_fault_allocate_oom().

◆ vm_pfault_oom_wait

int vm_pfault_oom_wait = 10
static

Definition at line 183 of file vm_fault.c.

Referenced by vm_fault_allocate(), and vm_fault_allocate_oom().