FreeBSD virtual memory subsystem code
|
#include <sys/cdefs.h>
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/malloc.h>
#include <sys/sysctl.h>
#include <sys/vmem.h>
#include <sys/vmmeter.h>
#include <vm/vm.h>
#include <vm/uma.h>
#include <vm/vm_param.h>
#include <vm/vm_page.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_kern.h>
#include <vm/vm_extern.h>
#include <vm/uma_int.h>
#include <vm/memguard.h>
Go to the source code of this file.
Macros | |
#define | MG_GUARD_AROUND 0x001 |
#define | MG_GUARD_ALLLARGE 0x002 |
#define | MG_GUARD_NOFREE 0x004 |
Functions | |
__FBSDID ("$FreeBSD$") | |
static | SYSCTL_NODE (_vm, OID_AUTO, memguard, CTLFLAG_RW|CTLFLAG_MPSAFE, NULL, "MemGuard data") |
SYSCTL_UINT (_vm_memguard, OID_AUTO, divisor, CTLFLAG_RDTUN|CTLFLAG_NOFETCH, &vm_memguard_divisor, 0, "(kmem_size/memguard_divisor) == memguard submap size") | |
TUNABLE_STR ("vm.memguard.desc", vm_memguard_desc, sizeof(vm_memguard_desc)) | |
static int | memguard_sysctl_desc (SYSCTL_HANDLER_ARGS) |
SYSCTL_PROC (_vm_memguard, OID_AUTO, desc, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_MPSAFE, 0, 0, memguard_sysctl_desc, "A", "Short description of memory type to monitor") | |
static int | memguard_sysctl_mapused (SYSCTL_HANDLER_ARGS) |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, mapsize, CTLFLAG_RD, &memguard_mapsize, 0, "MemGuard private arena size") | |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, phys_limit, CTLFLAG_RD, &memguard_physlimit, 0, "Limit on MemGuard memory consumption") | |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, wasted, CTLFLAG_RD, &memguard_wasted, 0, "Excess memory used through page promotion") | |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, numalloc, CTLFLAG_RD, &memguard_succ, 0, "Count of successful MemGuard allocations") | |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, fail_kva, CTLFLAG_RD, &memguard_fail_kva, 0, "MemGuard failures due to lack of KVA") | |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, fail_pgs, CTLFLAG_RD, &memguard_fail_pgs, 0, "MemGuard failures due to lack of pages") | |
SYSCTL_INT (_vm_memguard, OID_AUTO, options, CTLFLAG_RWTUN, &memguard_options, 0, "MemGuard options:\n" "\t0x001 - add guard pages around each allocation\n" "\t0x002 - always use MemGuard for allocations over a page\n" "\t0x004 - guard uma(9) zones with UMA_ZONE_NOFREE flag") | |
SYSCTL_UINT (_vm_memguard, OID_AUTO, minsize, CTLFLAG_RW, &memguard_minsize, 0, "Minimum size for page promotion") | |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, minsize_reject, CTLFLAG_RD, &memguard_minsize_reject, 0, "# times rejected for size") | |
SYSCTL_UINT (_vm_memguard, OID_AUTO, frequency, CTLFLAG_RWTUN, &memguard_frequency, 0, "Times in 100000 that MemGuard will randomly run") | |
SYSCTL_ULONG (_vm_memguard, OID_AUTO, frequency_hits, CTLFLAG_RD, &memguard_frequency_hits, 0, "# times MemGuard randomly chose") | |
unsigned long | memguard_fudge (unsigned long km_size, const struct vm_map *parent_map) |
void | memguard_init (vmem_t *parent) |
static void | memguard_sysinit (void) |
SYSINIT (memguard, SI_SUB_KLD, SI_ORDER_ANY, memguard_sysinit, NULL) | |
static u_long * | v2sizep (vm_offset_t va) |
static u_long * | v2sizev (vm_offset_t va) |
void * | memguard_alloc (unsigned long req_size, int flags) |
int | is_memguard_addr (void *addr) |
void | memguard_free (void *ptr) |
void * | memguard_realloc (void *addr, unsigned long size, struct malloc_type *mtp, int flags) |
static int | memguard_cmp (unsigned long size) |
int | memguard_cmp_mtp (struct malloc_type *mtp, unsigned long size) |
int | memguard_cmp_zone (uma_zone_t zone) |
unsigned long | memguard_get_req_size (const void *addr) |
Variables | |
static u_int | vm_memguard_divisor |
static char | vm_memguard_desc [128] = "" |
static struct malloc_type * | vm_memguard_mtype = NULL |
static vm_offset_t | memguard_base |
static vm_size_t | memguard_mapsize |
static vm_size_t | memguard_physlimit |
static u_long | memguard_wasted |
static u_long | memguard_succ |
static u_long | memguard_fail_kva |
static u_long | memguard_fail_pgs |
static int | memguard_options = MG_GUARD_AROUND |
static u_int | memguard_minsize |
static u_long | memguard_minsize_reject |
static u_int | memguard_frequency |
static u_long | memguard_frequency_hits |
#define MG_GUARD_ALLLARGE 0x002 |
Definition at line 137 of file memguard.c.
#define MG_GUARD_AROUND 0x001 |
Definition at line 136 of file memguard.c.
#define MG_GUARD_NOFREE 0x004 |
Definition at line 138 of file memguard.c.
__FBSDID | ( | "$FreeBSD$" | ) |
int is_memguard_addr | ( | void * | addr | ) |
Definition at line 364 of file memguard.c.
References vm_page::a, memguard_base, and memguard_mapsize.
Referenced by mtrash_ctor(), mtrash_dtor(), mtrash_init(), trash_ctor(), and trash_dtor().
void * memguard_alloc | ( | unsigned long | req_size, |
int | flags | ||
) |
Definition at line 290 of file memguard.c.
References vm_page::flags, KERN_SUCCESS, kernel_object, kmem_back(), memguard_arena, memguard_fail_kva, memguard_fail_pgs, memguard_options, memguard_physlimit, memguard_succ, memguard_wasted, MG_GUARD_AROUND, v2sizep(), and v2sizev().
Referenced by memguard_realloc().
|
static |
Definition at line 440 of file memguard.c.
References memguard_frequency, memguard_frequency_hits, memguard_minsize, memguard_minsize_reject, memguard_options, and MG_GUARD_ALLLARGE.
Referenced by memguard_cmp_mtp(), and memguard_cmp_zone().
int memguard_cmp_mtp | ( | struct malloc_type * | mtp, |
unsigned long | size | ||
) |
Definition at line 459 of file memguard.c.
References memguard_cmp(), vm_memguard_desc, and vm_memguard_mtype.
int memguard_cmp_zone | ( | uma_zone_t | zone | ) |
Definition at line 490 of file memguard.c.
References memguard_cmp(), memguard_options, MG_GUARD_NOFREE, UMA_ZONE_NOFREE, vm_memguard_desc, and vm_page::zone.
void memguard_free | ( | void * | ptr | ) |
Definition at line 375 of file memguard.c.
References kernel_object, kmem_unback(), memguard_arena, memguard_wasted, v2sizep(), and v2sizev().
Referenced by memguard_realloc().
unsigned long memguard_fudge | ( | unsigned long | km_size, |
const struct vm_map * | parent_map | ||
) |
Definition at line 166 of file memguard.c.
References memguard_mapsize, memguard_physlimit, vm_cnt, vm_map_max(), vm_map_min(), and vm_memguard_divisor.
unsigned long memguard_get_req_size | ( | const void * | addr | ) |
Definition at line 508 of file memguard.c.
References v2sizep().
void memguard_init | ( | vmem_t * | parent | ) |
Definition at line 209 of file memguard.c.
References memguard_arena, memguard_base, and memguard_mapsize.
void * memguard_realloc | ( | void * | addr, |
unsigned long | size, | ||
struct malloc_type * | mtp, | ||
int | flags | ||
) |
Definition at line 418 of file memguard.c.
References vm_page::flags, memguard_alloc(), memguard_free(), and v2sizep().
|
static |
Definition at line 85 of file memguard.c.
References vm_memguard_desc, and vm_memguard_mtype.
|
static |
Definition at line 107 of file memguard.c.
References memguard_arena.
Referenced by memguard_sysinit().
|
static |
Definition at line 228 of file memguard.c.
References memguard_base, memguard_mapsize, and memguard_sysctl_mapused().
SYSCTL_INT | ( | _vm_memguard | , |
OID_AUTO | , | ||
options | , | ||
CTLFLAG_RWTUN | , | ||
& | memguard_options, | ||
0 | , | ||
"MemGuard options:\n" "\t0x001 - add guard pages around each allocation\n" "\t0x002 - always use MemGuard for allocations over a page\n" "\t0x004 - guard uma(9) zones with UMA_ZONE_NOFREE flag" | |||
) |
|
static |
SYSCTL_PROC | ( | _vm_memguard | , |
OID_AUTO | , | ||
desc | , | ||
CTLTYPE_STRING|CTLFLAG_RW| | CTLFLAG_MPSAFE, | ||
0 | , | ||
0 | , | ||
memguard_sysctl_desc | , | ||
"A" | , | ||
"Short description of memory type to monitor" | |||
) |
SYSCTL_UINT | ( | _vm_memguard | , |
OID_AUTO | , | ||
divisor | , | ||
CTLFLAG_RDTUN| | CTLFLAG_NOFETCH, | ||
& | vm_memguard_divisor, | ||
0 | |||
) |
SYSCTL_UINT | ( | _vm_memguard | , |
OID_AUTO | , | ||
frequency | , | ||
CTLFLAG_RWTUN | , | ||
& | memguard_frequency, | ||
0 | , | ||
"Times in 100000 that MemGuard will randomly run" | |||
) |
SYSCTL_UINT | ( | _vm_memguard | , |
OID_AUTO | , | ||
minsize | , | ||
CTLFLAG_RW | , | ||
& | memguard_minsize, | ||
0 | , | ||
"Minimum size for page promotion" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
fail_kva | , | ||
CTLFLAG_RD | , | ||
& | memguard_fail_kva, | ||
0 | , | ||
"MemGuard failures due to lack of KVA" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
fail_pgs | , | ||
CTLFLAG_RD | , | ||
& | memguard_fail_pgs, | ||
0 | , | ||
"MemGuard failures due to lack of pages" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
frequency_hits | , | ||
CTLFLAG_RD | , | ||
& | memguard_frequency_hits, | ||
0 | , | ||
"# times MemGuard randomly chose" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
mapsize | , | ||
CTLFLAG_RD | , | ||
& | memguard_mapsize, | ||
0 | , | ||
"MemGuard private arena size" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
minsize_reject | , | ||
CTLFLAG_RD | , | ||
& | memguard_minsize_reject, | ||
0 | , | ||
"# times rejected for size" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
numalloc | , | ||
CTLFLAG_RD | , | ||
& | memguard_succ, | ||
0 | , | ||
"Count of successful MemGuard allocations" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
phys_limit | , | ||
CTLFLAG_RD | , | ||
& | memguard_physlimit, | ||
0 | , | ||
"Limit on MemGuard memory consumption" | |||
) |
SYSCTL_ULONG | ( | _vm_memguard | , |
OID_AUTO | , | ||
wasted | , | ||
CTLFLAG_RD | , | ||
& | memguard_wasted, | ||
0 | , | ||
"Excess memory used through page promotion" | |||
) |
SYSINIT | ( | memguard | , |
SI_SUB_KLD | , | ||
SI_ORDER_ANY | , | ||
memguard_sysinit | , | ||
NULL | |||
) |
TUNABLE_STR | ( | "vm.memguard.desc" | , |
vm_memguard_desc | , | ||
sizeof(vm_memguard_desc) | |||
) |
|
static |
Definition at line 256 of file memguard.c.
References vm_page::p, PHYS_TO_VM_PAGE(), PQ_NONE, and vm_page_wired().
Referenced by memguard_alloc(), memguard_free(), memguard_get_req_size(), and memguard_realloc().
|
static |
Definition at line 271 of file memguard.c.
References vm_page::p, PHYS_TO_VM_PAGE(), PQ_NONE, and vm_page_wired().
Referenced by memguard_alloc(), and memguard_free().
|
static |
Definition at line 115 of file memguard.c.
Referenced by is_memguard_addr(), memguard_init(), and memguard_sysinit().
|
static |
Definition at line 120 of file memguard.c.
Referenced by memguard_alloc().
|
static |
Definition at line 121 of file memguard.c.
Referenced by memguard_alloc().
|
static |
Definition at line 154 of file memguard.c.
Referenced by memguard_cmp().
|
static |
Definition at line 155 of file memguard.c.
Referenced by memguard_cmp().
|
static |
Definition at line 116 of file memguard.c.
Referenced by is_memguard_addr(), memguard_fudge(), memguard_init(), and memguard_sysinit().
|
static |
Definition at line 147 of file memguard.c.
Referenced by memguard_cmp().
|
static |
Definition at line 148 of file memguard.c.
Referenced by memguard_cmp().
|
static |
Definition at line 139 of file memguard.c.
Referenced by memguard_alloc(), memguard_cmp(), and memguard_cmp_zone().
|
static |
Definition at line 117 of file memguard.c.
Referenced by memguard_alloc(), and memguard_fudge().
|
static |
Definition at line 119 of file memguard.c.
Referenced by memguard_alloc().
|
static |
Definition at line 118 of file memguard.c.
Referenced by memguard_alloc(), and memguard_free().
|
static |
Definition at line 81 of file memguard.c.
Referenced by memguard_cmp_mtp(), memguard_cmp_zone(), and memguard_sysctl_desc().
|
static |
Definition at line 73 of file memguard.c.
Referenced by memguard_fudge().
|
static |
Definition at line 82 of file memguard.c.
Referenced by memguard_cmp_mtp(), and memguard_sysctl_desc().