38 #ifndef _included_clib_mem_h 39 #define _included_clib_mem_h 58 #define CLIB_MAX_MHEAPS 256 72 if (__os_thread_index != 0)
81 ASSERT (__os_thread_index > 0);
103 int os_out_of_memory_on_failure)
108 if (align_offset > align)
111 align_offset %= align;
113 align_offset = align;
119 #if USE_DLMALLOC == 0 134 if (os_out_of_memory_on_failure)
142 if (os_out_of_memory_on_failure)
187 #define clib_mem_alloc_aligned_no_fail(size,align) \ 189 uword _clib_mem_alloc_size = (size); \ 190 void * _clib_mem_alloc_p; \ 191 _clib_mem_alloc_p = clib_mem_alloc_aligned (_clib_mem_alloc_size, (align)); \ 192 if (! _clib_mem_alloc_p) \ 193 clib_panic ("failed to allocate %d bytes", _clib_mem_alloc_size); \ 197 #define clib_mem_alloc_no_fail(size) clib_mem_alloc_aligned_no_fail(size,1) 200 #define clib_mem_alloc_stack(bytes) __builtin_alloca(bytes) 205 #if USE_DLMALLOC == 0 233 #if USE_DLMALLOC == 0 252 if (old_size < new_size)
253 copy_size = old_size;
255 copy_size = new_size;
265 #if USE_DLMALLOC == 0 337 flags |= MAP_ANONYMOUS;
340 mmap_addr = mmap (0, size, PROT_READ | PROT_WRITE, flags, -1, 0);
341 if (mmap_addr == (
void *) -1)
363 mmap_addr = mmap (addr, size, PROT_NONE, flags, -1, 0);
364 if (mmap_addr == (
void *) -1)
374 uword flags = MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS;
376 mmap_addr = mmap (addr, size, (PROT_READ | PROT_WRITE), flags, -1, 0);
377 if (mmap_addr == (
void *) -1)
385 #define CLIB_MEM_VM_F_SHARED (1 << 0) 386 #define CLIB_MEM_VM_F_HUGETLB (1 << 1) 387 #define CLIB_MEM_VM_F_NUMA_PREFER (1 << 2) 388 #define CLIB_MEM_VM_F_NUMA_FORCE (1 << 3) 389 #define CLIB_MEM_VM_F_HUGETLB_PREALLOC (1 << 4) 390 #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)
static void clib_mem_set_thread_index(void)
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.
uword clib_mem_trace_enable_disable(uword enable)
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)
int clib_mem_is_traced(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
#define clib_atomic_bool_cmp_and_swap(addr, old, new)
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_always_inline void os_set_thread_index(uword thread_index)
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)