Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_malloc.c
Show First 20 Lines • Show All 470 Lines • ▼ Show 20 Lines | if ((malloc_nowait_count % malloc_failure_rate) == 0) { | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
if (flags & M_WAITOK) | if (flags & M_WAITOK) | ||||
KASSERT(curthread->td_intr_nesting_level == 0, | KASSERT(curthread->td_intr_nesting_level == 0, | ||||
("malloc(M_WAITOK) in interrupt context")); | ("malloc(M_WAITOK) in interrupt context")); | ||||
KASSERT(curthread->td_critnest == 0, | |||||
markj: The changes to malloc and free are redundant since these functions are built on top of UMA. So… | |||||
Done Inline ActionsI added these here to promote consistency. It appears that large malloc/frees don't go through uma_zalloc_arg()/uma_zalloc_free(). I also added the checks to uma_zalloc_arg/uma_zalloc_free because other code may call them directly. jtl: I added these here to promote consistency. It appears that large malloc/frees don't go through… | |||||
markjUnsubmitted Done Inline ActionsAh, indeed. In that case this seems fine to me. markj: Ah, indeed. In that case this seems fine to me. | |||||
("malloc: called with spinlock or critical section held")); | |||||
#ifdef DEBUG_MEMGUARD | #ifdef DEBUG_MEMGUARD | ||||
if (memguard_cmp_mtp(mtp, size)) { | if (memguard_cmp_mtp(mtp, size)) { | ||||
va = memguard_alloc(size, flags); | va = memguard_alloc(size, flags); | ||||
if (va != NULL) | if (va != NULL) | ||||
return (va); | return (va); | ||||
/* This is unfortunate but should not be fatal. */ | /* This is unfortunate but should not be fatal. */ | ||||
} | } | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
void | void | ||||
free(void *addr, struct malloc_type *mtp) | free(void *addr, struct malloc_type *mtp) | ||||
{ | { | ||||
uma_slab_t slab; | uma_slab_t slab; | ||||
u_long size; | u_long size; | ||||
KASSERT(mtp->ks_magic == M_MAGIC, ("free: bad malloc type magic")); | KASSERT(mtp->ks_magic == M_MAGIC, ("free: bad malloc type magic")); | ||||
KASSERT(curthread->td_critnest == 0, | |||||
("free: called with spinlock or critical section held")); | |||||
/* free(NULL, ...) does nothing */ | /* free(NULL, ...) does nothing */ | ||||
if (addr == NULL) | if (addr == NULL) | ||||
return; | return; | ||||
#ifdef DEBUG_MEMGUARD | #ifdef DEBUG_MEMGUARD | ||||
if (is_memguard_addr(addr)) { | if (is_memguard_addr(addr)) { | ||||
memguard_free(addr); | memguard_free(addr); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
realloc(void *addr, unsigned long size, struct malloc_type *mtp, int flags) | realloc(void *addr, unsigned long size, struct malloc_type *mtp, int flags) | ||||
{ | { | ||||
uma_slab_t slab; | uma_slab_t slab; | ||||
unsigned long alloc; | unsigned long alloc; | ||||
void *newaddr; | void *newaddr; | ||||
KASSERT(mtp->ks_magic == M_MAGIC, | KASSERT(mtp->ks_magic == M_MAGIC, | ||||
("realloc: bad malloc type magic")); | ("realloc: bad malloc type magic")); | ||||
KASSERT(curthread->td_critnest == 0, | |||||
("realloc: called with spinlock or critical section held")); | |||||
/* realloc(NULL, ...) is equivalent to malloc(...) */ | /* realloc(NULL, ...) is equivalent to malloc(...) */ | ||||
if (addr == NULL) | if (addr == NULL) | ||||
return (malloc(size, mtp, flags)); | return (malloc(size, mtp, flags)); | ||||
/* | /* | ||||
* XXX: Should report free of old memory and alloc of new memory to | * XXX: Should report free of old memory and alloc of new memory to | ||||
* per-CPU stats. | * per-CPU stats. | ||||
▲ Show 20 Lines • Show All 498 Lines • Show Last 20 Lines |
The changes to malloc and free are redundant since these functions are built on top of UMA. So the assertions in uma_core.c should be sufficient.