38 #ifndef _included_clib_mem_h 39 #define _included_clib_mem_h 52 #define CLIB_MAX_MHEAPS 256 76 int os_out_of_memory_on_failure)
81 if (align_offset > align)
84 align_offset %= align;
104 if (os_out_of_memory_on_failure)
146 #define clib_mem_alloc_aligned_no_fail(size,align) \ 148 uword _clib_mem_alloc_size = (size); \ 149 void * _clib_mem_alloc_p; \ 150 _clib_mem_alloc_p = clib_mem_alloc_aligned (_clib_mem_alloc_size, (align)); \ 151 if (! _clib_mem_alloc_p) \ 152 clib_panic ("failed to allocate %d bytes", _clib_mem_alloc_size); \ 156 #define clib_mem_alloc_no_fail(size) clib_mem_alloc_aligned_no_fail(size,1) 159 #define clib_mem_alloc_stack(bytes) __builtin_alloca(bytes) 201 if (old_size < new_size)
202 copy_size = old_size;
204 copy_size = new_size;
278 flags |= MAP_ANONYMOUS;
281 mmap_addr = mmap (0, size, PROT_READ | PROT_WRITE, flags, -1, 0);
282 if (mmap_addr == (
void *) -1)
304 mmap_addr = mmap (addr, size, PROT_NONE, flags, -1, 0);
305 if (mmap_addr == (
void *) -1)
317 mmap_addr = mmap (addr, size, (PROT_READ | PROT_WRITE), flags, -1, 0);
318 if (mmap_addr == (
void *) -1)
326 #define CLIB_MEM_VM_F_SHARED (1 << 0) 327 #define CLIB_MEM_VM_F_HUGETLB (1 << 1) 328 #define CLIB_MEM_VM_F_NUMA_PREFER (1 << 2) 329 #define CLIB_MEM_VM_F_NUMA_FORCE (1 << 3) 330 #define CLIB_MEM_VM_F_HUGETLB_PREALLOC (1 << 4) 331 #define CLIB_MEM_VM_F_LOCKED (1 << 5)
void clib_mem_validate(void)
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)
uword bytes_free_reclaimed
clib_error_t * clib_mem_vm_ext_alloc(clib_mem_vm_alloc_t *a)
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)
u64 clib_mem_vm_get_page_size(int fd)
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)
uword size
Allocation size, set by caller.
int clib_mem_vm_get_log2_page_size(int fd)
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)
#define clib_memcpy(a, b, c)
static uword clib_mem_size(void *p)
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)
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)
void mheap_put(void *v, uword uoffset)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void clib_mem_usage(clib_mem_usage_t *usage)
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)
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)
void clib_mem_trace(int enable)
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)