Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/kern_malloc.c
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | SYSCTL_INT(_debug_malloc, OID_AUTO, failure_count, CTLFLAG_RD, | ||||
&malloc_failure_count, 0, "Number of imposed M_NOWAIT malloc failures"); | &malloc_failure_count, 0, "Number of imposed M_NOWAIT malloc failures"); | ||||
#endif | #endif | ||||
static int | static int | ||||
sysctl_kmem_map_size(SYSCTL_HANDLER_ARGS) | sysctl_kmem_map_size(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
u_long size; | u_long size; | ||||
size = vmem_size(kmem_arena, VMEM_ALLOC); | size = uma_size(); | ||||
return (sysctl_handle_long(oidp, &size, 0, req)); | return (sysctl_handle_long(oidp, &size, 0, req)); | ||||
} | } | ||||
static int | static int | ||||
sysctl_kmem_map_free(SYSCTL_HANDLER_ARGS) | sysctl_kmem_map_free(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
u_long size; | u_long size, limit; | ||||
size = vmem_size(kmem_arena, VMEM_FREE); | /* The sysctl is unsigned, implement as a saturation value. */ | ||||
size = uma_size(); | |||||
limit = uma_limit(); | |||||
if (size > limit) | |||||
size = 0; | |||||
else | |||||
size = limit - size; | |||||
return (sysctl_handle_long(oidp, &size, 0, req)); | return (sysctl_handle_long(oidp, &size, 0, req)); | ||||
} | } | ||||
/* | /* | ||||
* malloc(9) uma zone separation -- sub-page buffer overruns in one | * malloc(9) uma zone separation -- sub-page buffer overruns in one | ||||
* malloc type will affect only a subset of other malloc types. | * malloc type will affect only a subset of other malloc types. | ||||
*/ | */ | ||||
#if MALLOC_DEBUG_MAXZONES > 1 | #if MALLOC_DEBUG_MAXZONES > 1 | ||||
▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
void *mem; | void *mem; | ||||
if ((mem = realloc(addr, size, mtp, flags)) == NULL) | if ((mem = realloc(addr, size, mtp, flags)) == NULL) | ||||
free(addr, mtp); | free(addr, mtp); | ||||
return (mem); | return (mem); | ||||
} | } | ||||
/* | |||||
* Wake the uma reclamation pagedaemon thread when we exhaust KVA. It | |||||
* will call the lowmem handler and uma_reclaim() callbacks in a | |||||
* context that is safe. | |||||
*/ | |||||
static void | |||||
kmem_reclaim(vmem_t *vm, int flags) | |||||
{ | |||||
uma_reclaim_wakeup(); | |||||
pagedaemon_wakeup(); | |||||
} | |||||
#ifndef __sparc64__ | #ifndef __sparc64__ | ||||
CTASSERT(VM_KMEM_SIZE_SCALE >= 1); | CTASSERT(VM_KMEM_SIZE_SCALE >= 1); | ||||
#endif | #endif | ||||
/* | /* | ||||
* Initialize the kernel memory (kmem) arena. | * Initialize the kernel memory (kmem) arena. | ||||
*/ | */ | ||||
void | void | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if (vm_kmem_size / 2 / PAGE_SIZE > mem_size) | ||||
vm_kmem_size = 2 * mem_size * PAGE_SIZE; | vm_kmem_size = 2 * mem_size * PAGE_SIZE; | ||||
vm_kmem_size = round_page(vm_kmem_size); | vm_kmem_size = round_page(vm_kmem_size); | ||||
#ifdef DEBUG_MEMGUARD | #ifdef DEBUG_MEMGUARD | ||||
tmp = memguard_fudge(vm_kmem_size, kernel_map); | tmp = memguard_fudge(vm_kmem_size, kernel_map); | ||||
#else | #else | ||||
tmp = vm_kmem_size; | tmp = vm_kmem_size; | ||||
#endif | #endif | ||||
vmem_init(kmem_arena, "kmem arena", kva_alloc(tmp), tmp, PAGE_SIZE, | uma_set_limit(tmp); | ||||
0, 0); | |||||
vmem_set_reclaim(kmem_arena, kmem_reclaim); | |||||
#ifdef DEBUG_MEMGUARD | #ifdef DEBUG_MEMGUARD | ||||
/* | /* | ||||
* Initialize MemGuard if support compiled in. MemGuard is a | * Initialize MemGuard if support compiled in. MemGuard is a | ||||
* replacement allocator used for detecting tamper-after-free | * replacement allocator used for detecting tamper-after-free | ||||
* scenarios as they occur. It is only used for debugging. | * scenarios as they occur. It is only used for debugging. | ||||
*/ | */ | ||||
memguard_init(kmem_arena); | memguard_init(kernel_arena); | ||||
#endif | #endif | ||||
} | } | ||||
/* | /* | ||||
* Initialize the kernel memory allocator | * Initialize the kernel memory allocator | ||||
*/ | */ | ||||
/* ARGSUSED*/ | /* ARGSUSED*/ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 337 Lines • Show Last 20 Lines |