38 #ifndef _included_clib_mem_h 39 #define _included_clib_mem_h 58 #define CLIB_MAX_MHEAPS 256 82 int os_out_of_memory_on_failure)
87 if (align_offset > align)
90 align_offset %= align;
113 if (os_out_of_memory_on_failure)
121 if (os_out_of_memory_on_failure)
166 #define clib_mem_alloc_aligned_no_fail(size,align) \ 168 uword _clib_mem_alloc_size = (size); \ 169 void * _clib_mem_alloc_p; \ 170 _clib_mem_alloc_p = clib_mem_alloc_aligned (_clib_mem_alloc_size, (align)); \ 171 if (! _clib_mem_alloc_p) \ 172 clib_panic ("failed to allocate %d bytes", _clib_mem_alloc_size); \ 176 #define clib_mem_alloc_no_fail(size) clib_mem_alloc_aligned_no_fail(size,1) 179 #define clib_mem_alloc_stack(bytes) __builtin_alloca(bytes) 184 #if USE_DLMALLOC == 0 212 #if USE_DLMALLOC == 0 231 if (old_size < new_size)
232 copy_size = old_size;
234 copy_size = new_size;
244 #if USE_DLMALLOC == 0 314 flags |= MAP_ANONYMOUS;
317 mmap_addr = mmap (0, size, PROT_READ | PROT_WRITE, flags, -1, 0);
318 if (mmap_addr == (
void *) -1)
340 mmap_addr = mmap (addr, size, PROT_NONE, flags, -1, 0);
341 if (mmap_addr == (
void *) -1)
351 uword flags = MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS;
353 mmap_addr = mmap (addr, size, (PROT_READ | PROT_WRITE), flags, -1, 0);
354 if (mmap_addr == (
void *) -1)
362 #define CLIB_MEM_VM_F_SHARED (1 << 0) 363 #define CLIB_MEM_VM_F_HUGETLB (1 << 1) 364 #define CLIB_MEM_VM_F_NUMA_PREFER (1 << 2) 365 #define CLIB_MEM_VM_F_NUMA_FORCE (1 << 3) 366 #define CLIB_MEM_VM_F_HUGETLB_PREALLOC (1 << 4) 367 #define CLIB_MEM_VM_F_LOCKED (1 << 5)
void clib_mem_validate(void)
vhost_user_memory_t memory
void * clib_per_cpu_mheaps[CLIB_MAX_MHEAPS]
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
int clib_mem_get_fd_log2_page_size(int fd)
uword bytes_free_reclaimed
Optimized string handling code, including c11-compliant "safe C library" variants.
clib_error_t * clib_mem_vm_ext_alloc(clib_mem_vm_alloc_t *a)
#define clib_memcpy_fast(a, b, c)
void * addr
Pointer to allocated memory, set on successful allocation.
uword requested_va
Request fixed position mapping.
static void * clib_mem_realloc(void *p, uword new_size, uword old_size)
void os_out_of_memory(void)
int numa_node
numa node preference.
clib_error_t * clib_mem_vm_ext_map(clib_mem_vm_map_t *a)
DLMALLOC_EXPORT int mspace_is_heap_object(mspace msp, void *p)
uword requested_va
Request fixed position mapping.
char * name
Name for memory allocation, set by caller.
static uword mheap_elt_data_bytes(mheap_elt_t *e)
void mheap_trace(void *v, int enable)
uword size
Allocation size, set by caller.
int fd
File descriptor, set on successful allocation if CLIB_MEM_VM_F_SHARED is set.
static void * clib_mem_get_per_cpu_heap(void)
u8 * format_clib_mem_usage(u8 *s, va_list *args)
u64 * clib_mem_vm_get_paddr(void *mem, int log2_page_size, int n_pages)
void * clib_mem_init(void *heap, uword size)
#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed)
static void * clib_mem_alloc_or_null(uword size)
void * mheap_get_aligned(void *v, uword n_user_data_bytes, uword align, uword align_offset, uword *offset_return)
static void * clib_mem_set_heap(void *heap)
static uword clib_mem_size(void *p)
clib_error_t * clib_mem_create_fd(char *name, int *fdp)
u32 flags
vm allocation flags: CLIB_MEM_VM_F_SHARED: request shared memory, file descriptor will be provided ...
static void * clib_mem_get_heap(void)
static void * clib_mem_alloc_aligned_or_null(uword size, uword align)
static void clib_mem_free(void *p)
static uword clib_mem_is_heap_object(void *p)
clib_error_t * clib_mem_create_hugetlb_fd(char *name, int *fdp)
static void * clib_mem_alloc(uword size)
static void * clib_mem_set_per_cpu_heap(u8 *new_heap)
static mheap_elt_t * mheap_elt_at_uoffset(void *v, uword uo)
template key/value backing page structure
static void clib_mem_vm_free(void *addr, uword size)
uword clib_mem_get_default_hugepage_size(void)
void mheap_put(void *v, uword uoffset)
void clib_mem_vm_ext_free(clib_mem_vm_alloc_t *a)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void clib_mem_usage(clib_mem_usage_t *usage)
u64 clib_mem_get_fd_page_size(int fd)
DLMALLOC_EXPORT void * mspace_get_aligned(mspace msp, unsigned long n_user_data_bytes, unsigned long align, unsigned long align_offset)
static_always_inline uword os_get_thread_index(void)
static mheap_elt_t * mheap_next_elt(mheap_elt_t *e)
struct clib_bihash_value offset
template key/value backing page structure
static void * clib_mem_alloc_aligned(uword size, uword align)
int fd
File descriptor to be mapped.
static void * clib_mem_vm_unmap(void *addr, uword size)
DLMALLOC_EXPORT void mspace_put(mspace msp, void *p)
void clib_mem_vm_randomize_va(uword *requested_va, u32 log2_page_size)
#define VALGRIND_FREELIKE_BLOCK(addr, rzB)
static uword mheap_data_bytes(void *v, uword uo)
DLMALLOC_EXPORT size_t mspace_usable_size_with_delta(const void *p)
void clib_mem_trace(int enable)
void * clib_mem_init_thread_safe(void *memory, uword memory_size)
uword clib_mem_get_page_size(void)
static void * clib_mem_vm_alloc(uword size)
static mheap_elt_t * mheap_user_pointer_to_elt(void *v)
void * addr
Pointer to mapped memory, if successful.
static void * clib_mem_vm_map(void *addr, uword size)