FreeBSD virtual memory subsystem code
swap_pager.c File Reference
#include <sys/cdefs.h>
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/bio.h>
#include <sys/blist.h>
#include <sys/buf.h>
#include <sys/conf.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/eventhandler.h>
#include <sys/fcntl.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/kernel.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/malloc.h>
#include <sys/pctrie.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/racct.h>
#include <sys/resource.h>
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/user.h>
#include <sys/vmmeter.h>
#include <sys/vnode.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/vm_kern.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
#include <vm/vm_pageout.h>
#include <vm/vm_param.h>
#include <vm/swap_pager.h>
#include <vm/vm_extern.h>
#include <vm/uma.h>
#include <geom/geom.h>
Include dependency graph for swap_pager.c:

Go to the source code of this file.

Data Structures

struct  swblk
 
struct  swapon_args
 

Macros

#define MAX_PAGEOUT_CLUSTER   32
 
#define SWB_NPAGES   MAX_PAGEOUT_CLUSTER
 
#define SWAP_META_PAGES   PCTRIE_COUNT
 
#define SWAP_RESERVE_FORCE_ON   (1 << 0)
 
#define SWAP_RESERVE_RLIMIT_ON   (1 << 1)
 
#define SWAP_RESERVE_ALLOW_NONWIRED   (1 << 2)
 
#define NOBJLISTS   8
 
#define NOBJLIST(handle)    (&swap_pager_object_list[((int)(intptr_t)handle >> 4) & (NOBJLISTS-1)])
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_VMPGDATA, "vm_pgdata", "swap pager private data")
 
static TAILQ_HEAD (swdevt)
 
static bool swap_reserve_by_cred_rlimit (u_long pincr, struct ucred *cred, int oc)
 
static void swap_release_by_cred_rlimit (u_long pdecr, struct ucred *cred)
 
static void swap_reserve_force_rlimit (u_long pincr, struct ucred *cred)
 
bool swap_reserve (vm_ooffset_t incr)
 
bool swap_reserve_by_cred (vm_ooffset_t incr, struct ucred *cred)
 
void swap_reserve_force (vm_ooffset_t incr)
 
void swap_release (vm_ooffset_t decr)
 
void swap_release_by_cred (vm_ooffset_t decr, struct ucred *cred)
 
static int sysctl_swap_async_max (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_vm, OID_AUTO, swap_async_max, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, NULL, 0, sysctl_swap_async_max, "I", "Maximum running async swap ops")
 
static int sysctl_swap_fragmentation (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_vm, OID_AUTO, swap_fragmentation, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, sysctl_swap_fragmentation, "A", "Swap Fragmentation Info")
 
static vm_object_t swap_pager_alloc (void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t offset, struct ucred *)
 
static void swap_pager_dealloc (vm_object_t object)
 
static int swap_pager_getpages (vm_object_t, vm_page_t *, int, int *, int *)
 
static int swap_pager_getpages_async (vm_object_t, vm_page_t *, int, int *, int *, pgo_getpages_iodone_t, void *)
 
static void swap_pager_putpages (vm_object_t, vm_page_t *, int, boolean_t, int *)
 
static boolean_t swap_pager_haspage (vm_object_t object, vm_pindex_t pindex, int *before, int *after)
 
static void swap_pager_init (void)
 
static void swap_pager_unswapped (vm_page_t)
 
static void swap_pager_swapoff (struct swdevt *sp)
 
static void swap_pager_update_writecount (vm_object_t object, vm_offset_t start, vm_offset_t end)
 
static void swap_pager_release_writecount (vm_object_t object, vm_offset_t start, vm_offset_t end)
 
static void swap_pager_freespace (vm_object_t object, vm_pindex_t start, vm_size_t size)
 
 SYSCTL_INT (_vm, OID_AUTO, dmmax, CTLFLAG_RD, &nsw_cluster_max, 0, "Maximum size of a swap block in pages")
 
static void swp_sizecheck (void)
 
static void swp_pager_async_iodone (struct buf *bp)
 
static bool swp_pager_swblk_empty (struct swblk *sb, int start, int limit)
 
static void swp_pager_free_empty_swblk (vm_object_t, struct swblk *sb)
 
static int swapongeom (struct vnode *)
 
static int swaponvp (struct thread *, struct vnode *, u_long)
 
static int swapoff_one (struct swdevt *sp, struct ucred *cred, u_int flags)
 
static void swp_pager_freeswapspace (daddr_t blk, daddr_t npages)
 
static daddr_t swp_pager_getswapspace (int *npages)
 
static daddr_t swp_pager_meta_build (vm_object_t, vm_pindex_t, daddr_t)
 
static void swp_pager_meta_free (vm_object_t, vm_pindex_t, vm_pindex_t)
 
static void swp_pager_meta_transfer (vm_object_t src, vm_object_t dst, vm_pindex_t pindex, vm_pindex_t count)
 
static void swp_pager_meta_free_all (vm_object_t)
 
static daddr_t swp_pager_meta_lookup (vm_object_t, vm_pindex_t)
 
static void swp_pager_init_freerange (daddr_t *start, daddr_t *num)
 
static void swp_pager_update_freerange (daddr_t *start, daddr_t *num, daddr_t addr)
 
static void * swblk_trie_alloc (struct pctrie *ptree)
 
static void swblk_trie_free (struct pctrie *ptree, void *node)
 
 PCTRIE_DEFINE (SWAP, swblk, p, swblk_trie_alloc, swblk_trie_free)
 
void swap_pager_swap_init (void)
 
bool swap_pager_init_object (vm_object_t object, void *handle, struct ucred *cred, vm_ooffset_t size, vm_ooffset_t offset)
 
static vm_object_t swap_pager_alloc_init (objtype_t otype, void *handle, struct ucred *cred, vm_ooffset_t size, vm_ooffset_t offset)
 
static bool swp_pager_isondev (daddr_t blk, struct swdevt *sp)
 
static void swp_pager_strategy (struct buf *bp)
 
int swap_pager_reserve (vm_object_t object, vm_pindex_t start, vm_pindex_t size)
 
static bool swp_pager_xfer_source (vm_object_t srcobject, vm_object_t dstobject, vm_pindex_t pindex, daddr_t addr)
 
void swap_pager_copy (vm_object_t srcobject, vm_object_t dstobject, vm_pindex_t offset, int destroysource)
 
static int swap_pager_getpages_locked (vm_object_t object, vm_page_t *ma, int count, int *rbehind, int *rahead)
 
static void swap_pager_putpages (vm_object_t object, vm_page_t *ma, int count, int flags, int *rtvals)
 
int swap_pager_nswapdev (void)
 
static void swp_pager_force_dirty (vm_page_t m)
 
u_long swap_pager_swapped_pages (vm_object_t object)
 
static void swap_pager_swapoff_object (struct swdevt *sp, vm_object_t object)
 
vm_pindex_t swap_pager_find_least (vm_object_t object, vm_pindex_t pindex)
 
int sys_swapon (struct thread *td, struct swapon_args *uap)
 
static void swapon_check_swzone (void)
 
static void swaponsomething (struct vnode *vp, void *id, u_long nblks, sw_strategy_t *strategy, sw_close_t *close, dev_t dev, int flags)
 
static int kern_swapoff (struct thread *td, const char *name, enum uio_seg name_seg, u_int flags)
 
int sys_swapoff (struct thread *td, struct swapoff_args *uap)
 
void swapoff_all (void)
 
void swap_pager_status (int *total, int *used)
 
int swap_dev_info (int name, struct xswdev *xs, char *devname, size_t len)
 
static int sysctl_vm_swap_info (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_INT (_vm, OID_AUTO, nswapdev, CTLFLAG_RD, &nswapdev, 0, "Number of swap devices")
 
 SYSCTL_NODE (_vm, OID_AUTO, swap_info, CTLFLAG_RD|CTLFLAG_MPSAFE, sysctl_vm_swap_info, "Swap statistics by device")
 
long vmspace_swap_count (struct vmspace *vmspace)
 
 DECLARE_GEOM_CLASS (g_swap_class, g_class)
 
static void swapgeom_close_ev (void *arg, int flags)
 
static void swapgeom_acquire (struct g_consumer *cp)
 
static void swapgeom_release (struct g_consumer *cp, struct swdevt *sp)
 
static void swapgeom_done (struct bio *bp2)
 
static void swapgeom_strategy (struct buf *bp, struct swdevt *sp)
 
static void swapgeom_orphan (struct g_consumer *cp)
 
static void swapgeom_close (struct thread *td, struct swdevt *sw)
 
static int swapongeom_locked (struct cdev *dev, struct vnode *vp)
 
static void swapdev_strategy (struct buf *bp, struct swdevt *sp)
 
static void swapdev_close (struct thread *td, struct swdevt *sp)
 

Variables

static struct mtx sw_dev_mtx
 
static int swap_pager_full = 2
 
static int swap_pager_almost_full = 1
 
static struct mtx swbuf_mtx
 
static int nsw_wcount_async
 
static int nsw_wcount_async_max
 
int nsw_cluster_max
 
static struct sx sw_alloc_sx
 
static struct pagerlst swap_pager_object_list [NOBJLISTS]
 
static uma_zone_t swwbuf_zone
 
static uma_zone_t swrbuf_zone
 
static uma_zone_t swblk_zone
 
static uma_zone_t swpctrie_zone
 
const struct pagerops swappagerops
 
static int nswap_lowat = 128
 
static int nswap_hiwat = 512
 
static g_orphan_t swapgeom_orphan
 
static struct g_class g_swap_class
 

Macro Definition Documentation

◆ MAX_PAGEOUT_CLUSTER

#define MAX_PAGEOUT_CLUSTER   32

Definition at line 130 of file swap_pager.c.

◆ NOBJLIST

#define NOBJLIST (   handle)     (&swap_pager_object_list[((int)(intptr_t)handle >> 4) & (NOBJLISTS-1)])

Definition at line 407 of file swap_pager.c.

◆ NOBJLISTS

#define NOBJLISTS   8

Definition at line 405 of file swap_pager.c.

◆ SWAP_META_PAGES

#define SWAP_META_PAGES   PCTRIE_COUNT

Definition at line 137 of file swap_pager.c.

◆ SWAP_RESERVE_ALLOW_NONWIRED

#define SWAP_RESERVE_ALLOW_NONWIRED   (1 << 2)

◆ SWAP_RESERVE_FORCE_ON

#define SWAP_RESERVE_FORCE_ON   (1 << 0)

◆ SWAP_RESERVE_RLIMIT_ON

#define SWAP_RESERVE_RLIMIT_ON   (1 << 1)

◆ SWB_NPAGES

#define SWB_NPAGES   MAX_PAGEOUT_CLUSTER

Definition at line 134 of file swap_pager.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DECLARE_GEOM_CLASS()

DECLARE_GEOM_CLASS ( g_swap_class  ,
g_class   
)

◆ kern_swapoff()

static int kern_swapoff ( struct thread *  td,
const char *  name,
enum uio_seg  name_seg,
u_int  flags 
)
static

Definition at line 2480 of file swap_pager.c.

References sw_dev_mtx, swdevt::sw_vp, and swapoff_one().

Referenced by sys_swapoff().

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

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_VMPGDATA  ,
"vm_pgdata"  ,
"swap pager private data"   
)
static

◆ PCTRIE_DEFINE()

PCTRIE_DEFINE ( SWAP  ,
swblk  ,
,
swblk_trie_alloc  ,
swblk_trie_free   
)

◆ swap_dev_info()

int swap_dev_info ( int  name,
struct xswdev xs,
char *  devname,
size_t  len 
)

◆ swap_pager_alloc()

static vm_object_t swap_pager_alloc ( void *  handle,
vm_ooffset_t  size,
vm_prot_t  prot,
vm_ooffset_t  offset,
struct ucred *  cred 
)
static

Definition at line 719 of file swap_pager.c.

References vm_object::handle, NOBJLIST, OBJT_SWAP, sw_alloc_sx, swap_pager_alloc_init(), and vm_pager_object_lookup().

Here is the call graph for this function:

◆ swap_pager_alloc_init()

static vm_object_t swap_pager_alloc_init ( objtype_t  otype,
void *  handle,
struct ucred *  cred,
vm_ooffset_t  size,
vm_ooffset_t  offset 
)
static

Definition at line 687 of file swap_pager.c.

References OFF_TO_IDX, swap_pager_init_object(), vm_object_allocate(), and vm_object_deallocate().

Referenced by swap_pager_alloc().

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

◆ swap_pager_copy()

void swap_pager_copy ( vm_object_t  srcobject,
vm_object_t  dstobject,
vm_pindex_t  offset,
int  destroysource 
)

◆ swap_pager_dealloc()

static void swap_pager_dealloc ( vm_object_t  object)
static

◆ swap_pager_find_least()

vm_pindex_t swap_pager_find_least ( vm_object_t  object,
vm_pindex_t  pindex 
)

◆ swap_pager_freespace()

static void swap_pager_freespace ( vm_object_t  object,
vm_pindex_t  start,
vm_size_t  size 
)
static

Definition at line 970 of file swap_pager.c.

References swp_pager_meta_free().

Here is the call graph for this function:

◆ swap_pager_getpages()

static int swap_pager_getpages ( vm_object_t  object,
vm_page_t *  ma,
int  count,
int *  rbehind,
int *  rahead 
)
static

Definition at line 1413 of file swap_pager.c.

References swap_pager_getpages_locked(), and VM_OBJECT_WLOCK.

Referenced by swap_pager_getpages_async().

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

◆ swap_pager_getpages_async()

static int swap_pager_getpages_async ( vm_object_t  object,
vm_page_t *  ma,
int  count,
int *  rbehind,
int *  rahead,
pgo_getpages_iodone_t  iodone,
void *  arg 
)
static

Definition at line 1428 of file swap_pager.c.

References swap_pager_getpages(), VM_PAGER_ERROR, VM_PAGER_FAIL, and VM_PAGER_OK.

Here is the call graph for this function:

◆ swap_pager_getpages_locked()

static int swap_pager_getpages_locked ( vm_object_t  object,
vm_page_t *  ma,
int  count,
int *  rbehind,
int *  rahead 
)
static

◆ swap_pager_haspage()

static boolean_t swap_pager_haspage ( vm_object_t  object,
vm_pindex_t  pindex,
int *  before,
int *  after 
)
static

Definition at line 1118 of file swap_pager.c.

References vm_object::flags, OBJ_SWAP, SWB_NPAGES, swp_pager_meta_lookup(), and VM_OBJECT_ASSERT_LOCKED.

Referenced by swap_pager_getpages_locked().

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

◆ swap_pager_init()

static void swap_pager_init ( void  )
static

◆ swap_pager_init_object()

bool swap_pager_init_object ( vm_object_t  object,
void *  handle,
struct ucred *  cred,
vm_ooffset_t  size,
vm_ooffset_t  offset 
)

Definition at line 668 of file swap_pager.c.

References swap_reserve_by_cred().

Referenced by swap_pager_alloc_init().

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

◆ swap_pager_nswapdev()

int swap_pager_nswapdev ( void  )

Definition at line 1774 of file swap_pager.c.

Referenced by vm_pageout_swapoff().

Here is the caller graph for this function:

◆ swap_pager_putpages() [1/2]

◆ swap_pager_putpages() [2/2]

static void swap_pager_putpages ( vm_object_t  ,
vm_page_t *  ,
int  ,
boolean_t  ,
int *   
)
static

◆ swap_pager_release_writecount()

static void swap_pager_release_writecount ( vm_object_t  object,
vm_offset_t  start,
vm_offset_t  end 
)
static

Definition at line 3162 of file swap_pager.c.

References vm_object::flags, OBJ_ANON, VM_OBJECT_WLOCK, and VM_OBJECT_WUNLOCK.

◆ swap_pager_reserve()

int swap_pager_reserve ( vm_object_t  object,
vm_pindex_t  start,
vm_pindex_t  size 
)

◆ swap_pager_status()

void swap_pager_status ( int *  total,
int *  used 
)

Definition at line 2631 of file swap_pager.c.

References swap_pager_avail.

◆ swap_pager_swap_init()

void swap_pager_swap_init ( void  )

Definition at line 596 of file swap_pager.c.

References nsw_wcount_async, nsw_wcount_async_max, pbuf_zsecond_create(), SWAP_META_PAGES, swblk_zone, swbuf_mtx, swpctrie_zone, swrbuf_zone, swwbuf_zone, uma_zcreate(), uma_zone_get_max(), uma_zone_reserve_kva(), and vm_cnt.

Referenced by vm_pageout().

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

◆ swap_pager_swapoff()

static void swap_pager_swapoff ( struct swdevt sp)
static

Definition at line 1924 of file swap_pager.c.

References vm_object::flags, OBJ_DEAD, OBJ_SWAP, swdevt::sw_used, swap_pager_swapoff_object(), vm_object_list, vm_object_list_mtx, VM_OBJECT_WLOCK, and VM_OBJECT_WUNLOCK.

Referenced by swapoff_one().

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

◆ swap_pager_swapoff_object()

◆ swap_pager_swapped_pages()

u_long swap_pager_swapped_pages ( vm_object_t  object)

Definition at line 1790 of file swap_pager.c.

References swblk::d, vm_object::flags, OBJ_SWAP, swblk::p, SWAP_META_PAGES, vm_object::swp, vm_object::swp_blks, vm_object::un_pager, and VM_OBJECT_ASSERT_LOCKED.

Referenced by vm_object_list_handler().

Here is the caller graph for this function:

◆ swap_pager_unswapped()

static void swap_pager_unswapped ( vm_page_t  m)
static

Definition at line 1188 of file swap_pager.c.

References swblk::d, OBJ_SWAP, PGA_SWAP_FREE, PGA_SWAP_SPACE, SWAP_META_PAGES, swp_pager_free_empty_swblk(), swp_pager_freeswapspace(), VM_OBJECT_WOWNED, vm_page_aflag_clear(), vm_page_aflag_set(), and VM_PAGE_OBJECT_BUSY_ASSERT.

Referenced by swp_pager_force_dirty().

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

◆ swap_pager_update_writecount()

static void swap_pager_update_writecount ( vm_object_t  object,
vm_offset_t  start,
vm_offset_t  end 
)
static

Definition at line 3150 of file swap_pager.c.

References vm_object::flags, OBJ_ANON, VM_OBJECT_WLOCK, and VM_OBJECT_WUNLOCK.

◆ swap_release()

void swap_release ( vm_ooffset_t  decr)

Definition at line 346 of file swap_pager.c.

References swap_release_by_cred().

Referenced by kmap_alloc_wait().

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

◆ swap_release_by_cred()

void swap_release_by_cred ( vm_ooffset_t  decr,
struct ucred *  cred 
)

Definition at line 357 of file swap_pager.c.

References swap_release_by_cred_rlimit().

Referenced by swap_release(), vm_map_lookup(), and vm_object_destroy().

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

◆ swap_release_by_cred_rlimit()

static void swap_release_by_cred_rlimit ( u_long  pdecr,
struct ucred *  cred 
)
static

Definition at line 228 of file swap_pager.c.

Referenced by swap_release_by_cred().

Here is the caller graph for this function:

◆ swap_reserve()

bool swap_reserve ( vm_ooffset_t  incr)

Definition at line 255 of file swap_pager.c.

References swap_reserve_by_cred().

Referenced by kmap_alloc_wait(), vm_map_insert(), and vm_map_protect().

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

◆ swap_reserve_by_cred()

bool swap_reserve_by_cred ( vm_ooffset_t  incr,
struct ucred *  cred 
)

Definition at line 262 of file swap_pager.c.

References SWAP_RESERVE_ALLOW_NONWIRED, swap_reserve_by_cred_rlimit(), SWAP_RESERVE_FORCE_ON, and vm_cnt.

Referenced by default_pager_alloc(), swap_pager_init_object(), swap_reserve(), vm_map_lookup(), and vm_object_coalesce().

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

◆ swap_reserve_by_cred_rlimit()

static bool swap_reserve_by_cred_rlimit ( u_long  pincr,
struct ucred *  cred,
int  oc 
)
static

Definition at line 209 of file swap_pager.c.

References SWAP_RESERVE_RLIMIT_ON.

Referenced by swap_reserve_by_cred().

Here is the caller graph for this function:

◆ swap_reserve_force()

void swap_reserve_force ( vm_ooffset_t  incr)

Definition at line 326 of file swap_pager.c.

References swap_reserve_force_rlimit().

Here is the call graph for this function:

◆ swap_reserve_force_rlimit()

static void swap_reserve_force_rlimit ( u_long  pincr,
struct ucred *  cred 
)
static

Definition at line 246 of file swap_pager.c.

Referenced by swap_reserve_force().

Here is the caller graph for this function:

◆ swapdev_close()

static void swapdev_close ( struct thread *  td,
struct swdevt sp 
)
static

Definition at line 3071 of file swap_pager.c.

References swdevt::sw_vp.

Referenced by swaponvp().

Here is the caller graph for this function:

◆ swapdev_strategy()

static void swapdev_strategy ( struct buf *  bp,
struct swdevt sp 
)
static

Definition at line 3046 of file swap_pager.c.

References swdevt::sw_first, and swdevt::sw_id.

Referenced by swaponvp().

Here is the caller graph for this function:

◆ swapgeom_acquire()

static void swapgeom_acquire ( struct g_consumer *  cp)
static

Definition at line 2827 of file swap_pager.c.

References sw_dev_mtx.

Referenced by swapgeom_strategy().

Here is the caller graph for this function:

◆ swapgeom_close()

static void swapgeom_close ( struct thread *  td,
struct swdevt sw 
)
static

Definition at line 2956 of file swap_pager.c.

References sw_dev_mtx, swdevt::sw_id, and swapgeom_close_ev().

Referenced by swapongeom_locked().

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

◆ swapgeom_close_ev()

static void swapgeom_close_ev ( void *  arg,
int  flags 
)
static

Definition at line 2813 of file swap_pager.c.

Referenced by swapgeom_close(), swapgeom_orphan(), and swapgeom_release().

Here is the caller graph for this function:

◆ swapgeom_done()

static void swapgeom_done ( struct bio *  bp2)
static

Definition at line 2852 of file swap_pager.c.

References sw_dev_mtx, and swapgeom_release().

Referenced by swapgeom_strategy().

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

◆ swapgeom_orphan()

static void swapgeom_orphan ( struct g_consumer *  cp)
static

Definition at line 2929 of file swap_pager.c.

References SW_CLOSING, sw_dev_mtx, swdevt::sw_flags, swdevt::sw_id, and swapgeom_close_ev().

Here is the call graph for this function:

◆ swapgeom_release()

static void swapgeom_release ( struct g_consumer *  cp,
struct swdevt sp 
)
static

Definition at line 2840 of file swap_pager.c.

References sw_dev_mtx, swdevt::sw_id, and swapgeom_close_ev().

Referenced by swapgeom_done(), and swapgeom_strategy().

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

◆ swapgeom_strategy()

static void swapgeom_strategy ( struct buf *  bp,
struct swdevt sp 
)
static

Definition at line 2875 of file swap_pager.c.

References sw_dev_mtx, swdevt::sw_first, swdevt::sw_id, swapgeom_acquire(), swapgeom_done(), and swapgeom_release().

Referenced by swapongeom_locked().

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

◆ swapoff_all()

void swapoff_all ( void  )

Definition at line 2601 of file swap_pager.c.

References sw_dev_mtx, swdevt::sw_vp, and swapoff_one().

Here is the call graph for this function:

◆ swapoff_one()

static int swapoff_one ( struct swdevt sp,
struct ucred *  cred,
u_int  flags 
)
static

Definition at line 2535 of file swap_pager.c.

References nswap_lowat, swdevt::sw_blist, swdevt::sw_close, SW_CLOSING, sw_dev_mtx, swdevt::sw_flags, swdevt::sw_id, swdevt::sw_nblks, swdevt::sw_vp, swap_pager_almost_full, swap_pager_avail, swap_pager_full, swap_pager_swapoff(), and vm_free_count().

Referenced by kern_swapoff(), and swapoff_all().

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

◆ swapon_check_swzone()

static void swapon_check_swzone ( void  )
static

Definition at line 2399 of file swap_pager.c.

Referenced by swaponsomething().

Here is the caller graph for this function:

◆ swapongeom()

static int swapongeom ( struct vnode *  vp)
static

Definition at line 3022 of file swap_pager.c.

References swapongeom_locked().

Referenced by sys_swapon().

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

◆ swapongeom_locked()

static int swapongeom_locked ( struct cdev *  dev,
struct vnode *  vp 
)
static

Definition at line 2975 of file swap_pager.c.

References g_swap_class, sw_dev_mtx, swdevt::sw_id, SW_UNMAPPED, swapgeom_close(), swapgeom_strategy(), and swaponsomething().

Referenced by swapongeom().

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

◆ swaponsomething()

static void swaponsomething ( struct vnode *  vp,
void *  id,
u_long  nblks,
sw_strategy_t strategy,
sw_close_t close,
dev_t  dev,
int  flags 
)
static

Definition at line 2413 of file swap_pager.c.

References swdevt::sw_blist, swdevt::sw_close, swdevt::sw_dev, sw_dev_mtx, swdevt::sw_end, swdevt::sw_first, swdevt::sw_flags, swdevt::sw_id, swdevt::sw_nblks, swdevt::sw_strategy, swdevt::sw_used, swdevt::sw_vp, swap_pager_avail, swapon_check_swzone(), and swp_sizecheck().

Referenced by swapongeom_locked(), and swaponvp().

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

◆ swaponvp()

static int swaponvp ( struct thread *  td,
struct vnode *  vp,
u_long  nblks 
)
static

Definition at line 3082 of file swap_pager.c.

References sw_dev_mtx, swdevt::sw_id, swapdev_close(), swapdev_strategy(), and swaponsomething().

Referenced by sys_swapon().

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

◆ swblk_trie_alloc()

static void * swblk_trie_alloc ( struct pctrie *  ptree)
static

Definition at line 514 of file swap_pager.c.

References pageproc, swpctrie_zone, and uma_zalloc().

Here is the call graph for this function:

◆ swblk_trie_free()

static void swblk_trie_free ( struct pctrie *  ptree,
void *  node 
)
static

Definition at line 522 of file swap_pager.c.

References swpctrie_zone, and uma_zfree().

Here is the call graph for this function:

◆ swp_pager_async_iodone()

◆ swp_pager_force_dirty()

static void swp_pager_force_dirty ( vm_page_t  m)
static

Definition at line 1781 of file swap_pager.c.

References swap_pager_unswapped(), vm_page_dirty(), and vm_page_launder().

Referenced by swap_pager_swapoff_object().

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

◆ swp_pager_free_empty_swblk()

static void swp_pager_free_empty_swblk ( vm_object_t  object,
struct swblk sb 
)
static

Definition at line 2016 of file swap_pager.c.

References swblk::p, SWAP_META_PAGES, swblk_zone, vm_object::swp, vm_object::swp_blks, swp_pager_swblk_empty(), uma_zfree(), and vm_object::un_pager.

Referenced by swap_pager_unswapped(), and swp_pager_meta_build().

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

◆ swp_pager_freeswapspace()

static void swp_pager_freeswapspace ( daddr_t  blk,
daddr_t  npages 
)
static

◆ swp_pager_getswapspace()

static daddr_t swp_pager_getswapspace ( int *  npages)
static

Definition at line 812 of file swap_pager.c.

References swdevt::sw_blist, SW_CLOSING, sw_dev_mtx, swdevt::sw_first, swdevt::sw_flags, swdevt::sw_used, swap_pager_almost_full, swap_pager_avail, swap_pager_full, and swp_sizecheck().

Referenced by swap_pager_putpages(), and swap_pager_reserve().

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

◆ swp_pager_init_freerange()

static void swp_pager_init_freerange ( daddr_t *  start,
daddr_t *  num 
)
static

Definition at line 493 of file swap_pager.c.

Referenced by swap_pager_putpages(), swap_pager_reserve(), swp_pager_meta_free_all(), and swp_pager_meta_transfer().

Here is the caller graph for this function:

◆ swp_pager_isondev()

static bool swp_pager_isondev ( daddr_t  blk,
struct swdevt sp 
)
static

Definition at line 861 of file swap_pager.c.

References swdevt::sw_end, and swdevt::sw_first.

Referenced by swap_pager_swapoff_object(), swp_pager_freeswapspace(), and swp_pager_strategy().

Here is the caller graph for this function:

◆ swp_pager_meta_build()

static daddr_t swp_pager_meta_build ( vm_object_t  object,
vm_pindex_t  pindex,
daddr_t  swapblk 
)
static

◆ swp_pager_meta_free()

static void swp_pager_meta_free ( vm_object_t  object,
vm_pindex_t  pindex,
vm_pindex_t  count 
)
static

Definition at line 2215 of file swap_pager.c.

References swp_pager_meta_transfer().

Referenced by swap_pager_freespace(), and swap_pager_reserve().

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

◆ swp_pager_meta_free_all()

static void swp_pager_meta_free_all ( vm_object_t  object)
static

◆ swp_pager_meta_lookup()

static daddr_t swp_pager_meta_lookup ( vm_object_t  object,
vm_pindex_t  pindex 
)
static

◆ swp_pager_meta_transfer()

static void swp_pager_meta_transfer ( vm_object_t  src,
vm_object_t  dst,
vm_pindex_t  pindex,
vm_pindex_t  count 
)
static

◆ swp_pager_strategy()

static void swp_pager_strategy ( struct buf *  bp)
static

Definition at line 868 of file swap_pager.c.

References pmap_qenter(), sw_dev_mtx, swdevt::sw_flags, swdevt::sw_strategy, SW_UNMAPPED, and swp_pager_isondev().

Referenced by swap_pager_getpages_locked(), and swap_pager_putpages().

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

◆ swp_pager_swblk_empty()

static bool swp_pager_swblk_empty ( struct swblk sb,
int  start,
int  limit 
)
static

Definition at line 1998 of file swap_pager.c.

References swblk::d, and SWAP_META_PAGES.

Referenced by swp_pager_free_empty_swblk(), and swp_pager_meta_transfer().

Here is the caller graph for this function:

◆ swp_pager_update_freerange()

static void swp_pager_update_freerange ( daddr_t *  start,
daddr_t *  num,
daddr_t  addr 
)
static

Definition at line 501 of file swap_pager.c.

References swp_pager_freeswapspace().

Referenced by swap_pager_putpages(), swap_pager_reserve(), swp_pager_meta_free_all(), and swp_pager_meta_transfer().

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

◆ swp_pager_xfer_source()

static bool swp_pager_xfer_source ( vm_object_t  srcobject,
vm_object_t  dstobject,
vm_pindex_t  pindex,
daddr_t  addr 
)
static

Definition at line 1015 of file swap_pager.c.

References vm_object::flags, OBJ_SWAP, swp_pager_meta_build(), swp_pager_meta_lookup(), VM_OBJECT_WLOCK, and VM_OBJECT_WUNLOCK.

Referenced by swp_pager_meta_transfer().

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

◆ swp_sizecheck()

static void swp_sizecheck ( void  )
static

Definition at line 542 of file swap_pager.c.

References nswap_hiwat, nswap_lowat, swap_pager_almost_full, swap_pager_avail, and swap_pager_full.

Referenced by swaponsomething(), swp_pager_freeswapspace(), and swp_pager_getswapspace().

Here is the caller graph for this function:

◆ sys_swapoff()

int sys_swapoff ( struct thread *  td,
struct swapoff_args *  uap 
)

Definition at line 2529 of file swap_pager.c.

References kern_swapoff().

Here is the call graph for this function:

◆ sys_swapon()

int sys_swapon ( struct thread *  td,
struct swapon_args uap 
)

Definition at line 2341 of file swap_pager.c.

References swapon_args::name, swapongeom(), swaponvp(), and swblk_zone.

Here is the call graph for this function:

◆ SYSCTL_INT() [1/2]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
dmmax  ,
CTLFLAG_RD  ,
nsw_cluster_max,
,
"Maximum size of a swap block in pages"   
)

◆ SYSCTL_INT() [2/2]

SYSCTL_INT ( _vm  ,
OID_AUTO  ,
nswapdev  ,
CTLFLAG_RD  ,
nswapdev,
,
"Number of swap devices"   
)

◆ SYSCTL_NODE()

SYSCTL_NODE ( _vm  ,
OID_AUTO  ,
swap_info  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
sysctl_vm_swap_info  ,
"Swap statistics by device"   
)

◆ SYSCTL_PROC() [1/2]

SYSCTL_PROC ( _vm  ,
OID_AUTO  ,
swap_async_max  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_swap_async_max  ,
"I"  ,
"Maximum running async swap ops"   
)

◆ SYSCTL_PROC() [2/2]

SYSCTL_PROC ( _vm  ,
OID_AUTO  ,
swap_fragmentation  ,
CTLTYPE_STRING|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_swap_fragmentation  ,
"A"  ,
"Swap Fragmentation Info"   
)

◆ sysctl_swap_async_max()

static int sysctl_swap_async_max ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 3113 of file swap_pager.c.

References nsw_wcount_async, nsw_wcount_async_max, and swbuf_mtx.

◆ sysctl_swap_fragmentation()

static int sysctl_swap_fragmentation ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 931 of file swap_pager.c.

References swdevt::sw_blist, sw_dev_mtx, and swdevt::sw_vp.

◆ sysctl_vm_swap_info()

static int sysctl_vm_swap_info ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 2695 of file swap_pager.c.

References swap_dev_info(), xswdev::xsw_dev, xswdev::xsw_flags, xswdev::xsw_nblks, xswdev::xsw_used, and XSWDEV_VERSION.

Here is the call graph for this function:

◆ TAILQ_HEAD()

static TAILQ_HEAD ( swdevt  )
static

Definition at line 152 of file swap_pager.c.

◆ vmspace_swap_count()

Variable Documentation

◆ g_swap_class

struct g_class g_swap_class
static
Initial value:
= {
.name = "SWAP",
.version = G_VERSION,
.orphan = swapgeom_orphan,
}
static g_orphan_t swapgeom_orphan
Definition: swap_pager.c:2802

Definition at line 2804 of file swap_pager.c.

Referenced by swapongeom_locked().

◆ nsw_cluster_max

int nsw_cluster_max

Definition at line 387 of file swap_pager.c.

Referenced by swap_pager_init(), and swap_pager_putpages().

◆ nsw_wcount_async

int nsw_wcount_async
static

◆ nsw_wcount_async_max

int nsw_wcount_async_max
static

Definition at line 386 of file swap_pager.c.

Referenced by swap_pager_swap_init(), and sysctl_swap_async_max().

◆ nswap_hiwat

int nswap_hiwat = 512
static

Definition at line 462 of file swap_pager.c.

Referenced by swp_sizecheck().

◆ nswap_lowat

int nswap_lowat = 128
static

Definition at line 461 of file swap_pager.c.

Referenced by swapoff_one(), and swp_sizecheck().

◆ sw_alloc_sx

struct sx sw_alloc_sx
static

◆ sw_dev_mtx

◆ swap_pager_almost_full

int swap_pager_almost_full = 1
static

Definition at line 383 of file swap_pager.c.

Referenced by swapoff_one(), swp_pager_getswapspace(), and swp_sizecheck().

◆ swap_pager_full

int swap_pager_full = 2
static

Definition at line 382 of file swap_pager.c.

Referenced by swapoff_one(), swp_pager_getswapspace(), and swp_sizecheck().

◆ swap_pager_object_list

struct pagerlst swap_pager_object_list[NOBJLISTS]
static

Definition at line 410 of file swap_pager.c.

Referenced by swap_pager_init().

◆ swapgeom_orphan

g_orphan_t swapgeom_orphan
static

Definition at line 2802 of file swap_pager.c.

◆ swappagerops

const struct pagerops swappagerops
Initial value:
= {
.pgo_kvme_type = KVME_TYPE_SWAP,
.pgo_init = swap_pager_init,
.pgo_alloc = swap_pager_alloc,
.pgo_dealloc = swap_pager_dealloc,
.pgo_getpages = swap_pager_getpages,
.pgo_getpages_async = swap_pager_getpages_async,
.pgo_putpages = swap_pager_putpages,
.pgo_haspage = swap_pager_haspage,
.pgo_pageunswapped = swap_pager_unswapped,
.pgo_update_writecount = swap_pager_update_writecount,
.pgo_release_writecount = swap_pager_release_writecount,
.pgo_freespace = swap_pager_freespace,
}
static void swap_pager_release_writecount(vm_object_t object, vm_offset_t start, vm_offset_t end)
Definition: swap_pager.c:3162
static void swap_pager_dealloc(vm_object_t object)
Definition: swap_pager.c:760
static vm_object_t swap_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t offset, struct ucred *)
Definition: swap_pager.c:719
static void swap_pager_update_writecount(vm_object_t object, vm_offset_t start, vm_offset_t end)
Definition: swap_pager.c:3150
static int swap_pager_getpages(vm_object_t, vm_page_t *, int, int *, int *)
Definition: swap_pager.c:1413
static void swap_pager_putpages(vm_object_t, vm_page_t *, int, boolean_t, int *)
static boolean_t swap_pager_haspage(vm_object_t object, vm_pindex_t pindex, int *before, int *after)
Definition: swap_pager.c:1118
static void swap_pager_unswapped(vm_page_t)
Definition: swap_pager.c:1188
static void swap_pager_freespace(vm_object_t object, vm_pindex_t start, vm_size_t size)
Definition: swap_pager.c:970
static void swap_pager_init(void)
Definition: swap_pager.c:565
static int swap_pager_getpages_async(vm_object_t, vm_page_t *, int, int *, int *, pgo_getpages_iodone_t, void *)
Definition: swap_pager.c:1428

Definition at line 442 of file swap_pager.c.

Referenced by default_pager_putpages().

◆ swblk_zone

◆ swbuf_mtx

struct mtx swbuf_mtx
static

◆ swpctrie_zone

uma_zone_t swpctrie_zone
static

◆ swrbuf_zone

uma_zone_t swrbuf_zone
static

◆ swwbuf_zone

uma_zone_t swwbuf_zone
static

Definition at line 411 of file swap_pager.c.

Referenced by swap_pager_putpages(), swap_pager_swap_init(), and swp_pager_async_iodone().