Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/malloc.h
Show First 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* XXX this should be declared in <sys/uio.h>, but that tends to fail | * XXX this should be declared in <sys/uio.h>, but that tends to fail | ||||
* because <sys/uio.h> is included in a header before the source file | * because <sys/uio.h> is included in a header before the source file | ||||
* has a chance to include <sys/malloc.h> to get MALLOC_DECLARE() defined. | * has a chance to include <sys/malloc.h> to get MALLOC_DECLARE() defined. | ||||
*/ | */ | ||||
MALLOC_DECLARE(M_IOV); | MALLOC_DECLARE(M_IOV); | ||||
struct domainset; | |||||
extern struct mtx malloc_mtx; | extern struct mtx malloc_mtx; | ||||
/* | /* | ||||
* Function type used when iterating over the list of malloc types. | * Function type used when iterating over the list of malloc types. | ||||
*/ | */ | ||||
typedef void malloc_type_list_func_t(struct malloc_type *, void *); | typedef void malloc_type_list_func_t(struct malloc_type *, void *); | ||||
void contigfree(void *addr, unsigned long size, struct malloc_type *type); | void contigfree(void *addr, unsigned long size, struct malloc_type *type); | ||||
void *contigmalloc(unsigned long size, struct malloc_type *type, int flags, | void *contigmalloc(unsigned long size, struct malloc_type *type, int flags, | ||||
vm_paddr_t low, vm_paddr_t high, unsigned long alignment, | vm_paddr_t low, vm_paddr_t high, unsigned long alignment, | ||||
vm_paddr_t boundary) __malloc_like __result_use_check | vm_paddr_t boundary) __malloc_like __result_use_check | ||||
__alloc_size(1) __alloc_align(6); | __alloc_size(1) __alloc_align(6); | ||||
void *contigmalloc_domain(unsigned long size, struct malloc_type *type, | void *contigmalloc_domain(unsigned long size, struct malloc_type *type, | ||||
int domain, int flags, vm_paddr_t low, vm_paddr_t high, | int domain, int flags, vm_paddr_t low, vm_paddr_t high, | ||||
unsigned long alignment, vm_paddr_t boundary) | unsigned long alignment, vm_paddr_t boundary) | ||||
__malloc_like __result_use_check __alloc_size(1) __alloc_align(6); | __malloc_like __result_use_check __alloc_size(1) __alloc_align(6); | ||||
void *contigmalloc_domainset(unsigned long size, struct malloc_type *type, | |||||
struct domainset *ds, int flags, vm_paddr_t low, vm_paddr_t high, | |||||
unsigned long alignment, vm_paddr_t boundary) | |||||
__malloc_like __result_use_check __alloc_size(1) __alloc_align(6); | |||||
void free(void *addr, struct malloc_type *type); | void free(void *addr, struct malloc_type *type); | ||||
void free_domain(void *addr, struct malloc_type *type); | void free_domain(void *addr, struct malloc_type *type); | ||||
void *malloc(size_t size, struct malloc_type *type, int flags) __malloc_like | void *malloc(size_t size, struct malloc_type *type, int flags) __malloc_like | ||||
__result_use_check __alloc_size(1); | __result_use_check __alloc_size(1); | ||||
/* | /* | ||||
* Try to optimize malloc(..., ..., M_ZERO) allocations by doing zeroing in | * Try to optimize malloc(..., ..., M_ZERO) allocations by doing zeroing in | ||||
* place if the size is known at compilation time. | * place if the size is known at compilation time. | ||||
* | * | ||||
* Passing the flag down requires malloc to blindly zero the entire object. | * Passing the flag down requires malloc to blindly zero the entire object. | ||||
* In practice a lot of the zeroing can be avoided if most of the object | * In practice a lot of the zeroing can be avoided if most of the object | ||||
* gets explicitly initialized after the allocation. Letting the compiler | * gets explicitly initialized after the allocation. Letting the compiler | ||||
* zero in place gives it the opportunity to take advantage of this state. | * zero in place gives it the opportunity to take advantage of this state. | ||||
Show All 34 Lines | if (((flags) & M_WAITOK) != 0 || \ | ||||
__predict_true(_malloc_item != NULL)) \ | __predict_true(_malloc_item != NULL)) \ | ||||
bzero(_malloc_item, _size); \ | bzero(_malloc_item, _size); \ | ||||
} else { \ | } else { \ | ||||
_malloc_item = malloc(_size, type, flags); \ | _malloc_item = malloc(_size, type, flags); \ | ||||
} \ | } \ | ||||
_malloc_item; \ | _malloc_item; \ | ||||
}) | }) | ||||
void *malloc_domain(size_t size, struct malloc_type *type, int domain, | void *malloc_domain(size_t size, struct malloc_type *type, int domain, | ||||
int flags) __malloc_like __result_use_check __alloc_size(1); | int flags) __malloc_like __result_use_check __alloc_size(1); | ||||
void *malloc_domainset(size_t size, struct malloc_type *type, | |||||
struct domainset *ds, int flags) __malloc_like __result_use_check | |||||
__alloc_size(1); | |||||
jeff: malloc_domain is used in so few places and they should probably all be 'prefer' anyway. We… | |||||
Done Inline ActionsI ended up removing it entirely, and just changing the behaviour of malloc_domain(). This makes it inconsistent with every other *_domain() KPI. markj: I ended up removing it entirely, and just changing the behaviour of malloc_domain(). This makes… | |||||
void *mallocarray(size_t nmemb, size_t size, struct malloc_type *type, | void *mallocarray(size_t nmemb, size_t size, struct malloc_type *type, | ||||
int flags) __malloc_like __result_use_check | int flags) __malloc_like __result_use_check | ||||
__alloc_size2(1, 2); | __alloc_size2(1, 2); | ||||
void malloc_init(void *); | void malloc_init(void *); | ||||
int malloc_last_fail(void); | int malloc_last_fail(void); | ||||
void malloc_type_allocated(struct malloc_type *type, unsigned long size); | void malloc_type_allocated(struct malloc_type *type, unsigned long size); | ||||
void malloc_type_freed(struct malloc_type *type, unsigned long size); | void malloc_type_freed(struct malloc_type *type, unsigned long size); | ||||
void malloc_type_list(malloc_type_list_func_t *, void *); | void malloc_type_list(malloc_type_list_func_t *, void *); | ||||
Show All 24 Lines |
malloc_domain is used in so few places and they should probably all be 'prefer' anyway. We could implement this as a macro/inline wrapper or eliminate it altogether. I'd prefer not to keep the somewhat redundant functions.