38 #ifndef _included_clib_mem_h 39 #define _included_clib_mem_h 54 #define CLIB_MAX_MHEAPS 256 55 #define CLIB_MAX_NUMAS 8 58 #define VEC_NUMA_UNSPECIFIED (0xFF) 105 if (__os_thread_index != 0)
114 ASSERT (__os_thread_index > 0);
126 int os_out_of_memory_on_failure)
131 if (align_offset > align)
134 align_offset %= align;
136 align_offset = align;
146 if (os_out_of_memory_on_failure)
191 #define clib_mem_alloc_aligned_no_fail(size,align) \ 193 uword _clib_mem_alloc_size = (size); \ 194 void * _clib_mem_alloc_p; \ 195 _clib_mem_alloc_p = clib_mem_alloc_aligned (_clib_mem_alloc_size, (align)); \ 196 if (! _clib_mem_alloc_p) \ 197 clib_panic ("failed to allocate %d bytes", _clib_mem_alloc_size); \ 201 #define clib_mem_alloc_no_fail(size) clib_mem_alloc_aligned_no_fail(size,1) 204 #define clib_mem_alloc_stack(bytes) __builtin_alloca(bytes) 235 if (old_size < new_size)
236 copy_size = old_size;
238 copy_size = new_size;
325 flags |= MAP_ANONYMOUS;
328 mmap_addr = mmap (0, size, PROT_READ | PROT_WRITE, flags, -1, 0);
329 if (mmap_addr == (
void *) -1)
353 mmap_addr = mmap (addr, size, PROT_NONE, flags, -1, 0);
354 if (mmap_addr == (
void *) -1)
366 uword flags = MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS;
368 mmap_addr = mmap (addr, size, (PROT_READ | PROT_WRITE), flags, -1, 0);
369 if (mmap_addr == (
void *) -1)
379 #define CLIB_MEM_VM_F_SHARED (1 << 0) 380 #define CLIB_MEM_VM_F_HUGETLB (1 << 1) 381 #define CLIB_MEM_VM_F_NUMA_PREFER (1 << 2) 382 #define CLIB_MEM_VM_F_NUMA_FORCE (1 << 3) 383 #define CLIB_MEM_VM_F_HUGETLB_PREALLOC (1 << 4) 384 #define CLIB_MEM_VM_F_LOCKED (1 << 5)
void clib_mem_validate(void)
#define CLIB_MEM_UNPOISON(a, s)
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.
uword clib_mem_vm_reserve(uword start, uword size, u32 log2_page_sz)
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_always_inline uword os_get_numa_index(void)
static void clib_mem_set_thread_index(void)
uword requested_va
Request fixed position mapping.
static errno_t memset_s_inline(void *s, rsize_t smax, int c, rsize_t n)
char * name
Name for memory allocation, set by caller.
void mheap_trace(void *v, int enable)
uword size
Allocation size, set by caller.
void * clib_per_numa_mheaps[CLIB_MAX_NUMAS]
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)
static void * clib_mem_alloc_or_null(uword size)
sll srl srl sll sra u16x4 i
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)
static void * clib_mem_get_per_numa_heap(u32 numa_id)
clib_error_t * clib_mem_create_hugetlb_fd(char *name, int *fdp)
static void clib_mem_free_s(void *p)
static void * clib_mem_alloc(uword size)
static void * clib_mem_set_per_cpu_heap(u8 *new_heap)
#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 clib_mem_vm_ext_free(clib_mem_vm_alloc_t *a)
void clib_mem_usage(clib_mem_usage_t *usage)
static uword clib_mem_size_nocheck(void *p)
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)
void * clib_mem_init_thread_safe_numa(void *memory, uword memory_size, u8 numa)
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)
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)
void * addr
Pointer to mapped memory, if successful.
static void * clib_mem_set_per_numa_heap(u8 *new_heap)
#define CLIB_MEM_POISON(a, s)
static void * clib_mem_vm_map(void *addr, uword size)