FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
mem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  Copyright (c) 2001, 2002, 2003 Eliot Dresselhaus
17 
18  Permission is hereby granted, free of charge, to any person obtaining
19  a copy of this software and associated documentation files (the
20  "Software"), to deal in the Software without restriction, including
21  without limitation the rights to use, copy, modify, merge, publish,
22  distribute, sublicense, and/or sell copies of the Software, and to
23  permit persons to whom the Software is furnished to do so, subject to
24  the following conditions:
25 
26  The above copyright notice and this permission notice shall be
27  included in all copies or substantial portions of the Software.
28 
29  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 */
37 
38 #ifndef _included_clib_mem_h
39 #define _included_clib_mem_h
40 
41 #include <stdarg.h>
42 #include <unistd.h>
43 #include <sys/mman.h>
44 
45 #include <vppinfra/clib.h> /* uword, etc */
46 #include <vppinfra/clib_error.h>
47 
48 #include <vppinfra/os.h>
49 #include <vppinfra/string.h> /* memcpy, clib_memset */
50 #include <vppinfra/sanitizer.h>
51 
52 #define CLIB_MAX_MHEAPS 256
53 #define CLIB_MAX_NUMAS 16
54 #define CLIB_MEM_VM_MAP_FAILED ((void *) ~0)
55 #define CLIB_MEM_ERROR (-1)
56 
57 typedef enum
58 {
73 
74 typedef struct _clib_mem_vm_map_hdr
75 {
76  /* base address */
77  uword base_addr;
78 
79  /* number of pages */
80  uword num_pages;
81 
82  /* page size (log2) */
83  clib_mem_page_sz_t log2_page_sz;
84 
85  /* file descriptor, -1 if memory is not shared */
86  int fd;
87 
88  /* allocation mame */
89 #define CLIB_VM_MAP_HDR_NAME_MAX_LEN 64
91 
92  /* linked list */
93  struct _clib_mem_vm_map_hdr *prev, *next;
95 
96 #define foreach_clib_mem_heap_flag \
97  _(0, LOCKED, "locked") \
98  _(1, UNMAP_ON_DESTROY, "unmap-on-destroy")
99 
100 typedef enum
101 {
102 #define _(i, v, s) CLIB_MEM_HEAP_F_##v = (1 << i),
104 #undef _
106 
107 typedef struct
108 {
109  /* base address */
110  void *base;
111 
112  /* dlmalloc mspace */
113  void *mspace;
114 
115  /* heap size */
117 
118  /* page size (log2) */
120 
121  /* flags */
123 
124  /* name - _MUST_ be last */
125  char name[0];
127 
128 typedef struct
129 {
130  /* log2 system page size */
132 
133  /* log2 default hugepage size */
135 
136  /* log2 system default hugepage size */
138 
139  /* bitmap of available numa nodes */
141 
142  /* per CPU heaps */
143  void *per_cpu_mheaps[CLIB_MAX_MHEAPS];
144 
145  /* per NUMA heaps */
146  void *per_numa_mheaps[CLIB_MAX_NUMAS];
147 
148  /* memory maps */
150 
151  /* map lock */
153 
154  /* last error */
157 
159 
160 /* Unspecified NUMA socket */
161 #define VEC_NUMA_UNSPECIFIED (0xFF)
162 
165 {
166  int cpu = os_get_thread_index ();
167  return clib_mem_main.per_cpu_mheaps[cpu];
168 }
169 
170 always_inline void *
172 {
173  int cpu = os_get_thread_index ();
174  void *old = clib_mem_main.per_cpu_mheaps[cpu];
175  clib_mem_main.per_cpu_mheaps[cpu] = new_heap;
176  return old;
177 }
178 
179 always_inline void *
181 {
183  return clib_mem_main.per_numa_mheaps[numa_id];
184 }
185 
186 always_inline void *
188 {
189  int numa = os_get_numa_index ();
190  void *old = clib_mem_main.per_numa_mheaps[numa];
191  clib_mem_main.per_numa_mheaps[numa] = new_heap;
192  return old;
193 }
194 
195 always_inline void
197 {
198  /*
199  * Find an unused slot in the per-cpu-mheaps array,
200  * and grab it for this thread. We need to be able to
201  * push/pop the thread heap without affecting other thread(s).
202  */
203  int i;
204  if (__os_thread_index != 0)
205  return;
206  for (i = 0; i < ARRAY_LEN (clib_mem_main.per_cpu_mheaps); i++)
209  {
211  break;
212  }
213  ASSERT (__os_thread_index > 0);
214 }
215 
218 {
219  size_t mspace_usable_size_with_delta (const void *p);
221 }
222 
223 /* Memory allocator which may call os_out_of_memory() if it fails */
224 always_inline void *
226  int os_out_of_memory_on_failure)
227 {
228  void *mspace_get_aligned (void *msp, unsigned long n_user_data_bytes,
229  unsigned long align, unsigned long align_offset);
231  void *p;
232 
233  if (align_offset > align)
234  {
235  if (align > 0)
236  align_offset %= align;
237  else
238  align_offset = align;
239  }
240 
241  p = mspace_get_aligned (h->mspace, size, align, align_offset);
242 
243  if (PREDICT_FALSE (0 == p))
244  {
245  if (os_out_of_memory_on_failure)
246  os_out_of_memory ();
247  return 0;
248  }
249 
250  CLIB_MEM_UNPOISON (p, size);
251  return p;
252 }
253 
254 /* Memory allocator which calls os_out_of_memory() when it fails */
255 always_inline void *
257 {
258  return clib_mem_alloc_aligned_at_offset (size, /* align */ 1,
259  /* align_offset */ 0,
260  /* os_out_of_memory */ 1);
261 }
262 
263 always_inline void *
265 {
266  return clib_mem_alloc_aligned_at_offset (size, align, /* align_offset */ 0,
267  /* os_out_of_memory */ 1);
268 }
269 
270 /* Memory allocator which calls os_out_of_memory() when it fails */
271 always_inline void *
273 {
274  return clib_mem_alloc_aligned_at_offset (size, /* align */ 1,
275  /* align_offset */ 0,
276  /* os_out_of_memory */ 0);
277 }
278 
279 always_inline void *
281 {
282  return clib_mem_alloc_aligned_at_offset (size, align, /* align_offset */ 0,
283  /* os_out_of_memory */ 0);
284 }
285 
286 
287 
288 /* Memory allocator which panics when it fails.
289  Use macro so that clib_panic macro can expand __FUNCTION__ and __LINE__. */
290 #define clib_mem_alloc_aligned_no_fail(size,align) \
291 ({ \
292  uword _clib_mem_alloc_size = (size); \
293  void * _clib_mem_alloc_p; \
294  _clib_mem_alloc_p = clib_mem_alloc_aligned (_clib_mem_alloc_size, (align)); \
295  if (! _clib_mem_alloc_p) \
296  clib_panic ("failed to allocate %d bytes", _clib_mem_alloc_size); \
297  _clib_mem_alloc_p; \
298 })
299 
300 #define clib_mem_alloc_no_fail(size) clib_mem_alloc_aligned_no_fail(size,1)
301 
302 /* Alias to stack allocator for naming consistency. */
303 #define clib_mem_alloc_stack(bytes) __builtin_alloca(bytes)
304 
307 {
308  int mspace_is_heap_object (void *msp, void *p);
310  return mspace_is_heap_object (h->mspace, p);
311 }
312 
313 always_inline void
314 clib_mem_free (void *p)
315 {
316  void mspace_put (void *msp, void *p_arg);
318 
319  /* Make sure object is in the correct heap. */
321 
323 
324  mspace_put (h->mspace, p);
325 }
326 
327 always_inline void *
328 clib_mem_realloc (void *p, uword new_size, uword old_size)
329 {
330  /* By default use alloc, copy and free to emulate realloc. */
331  void *q = clib_mem_alloc (new_size);
332  if (q)
333  {
334  uword copy_size;
335  if (old_size < new_size)
336  copy_size = old_size;
337  else
338  copy_size = new_size;
339  clib_memcpy_fast (q, p, copy_size);
340  clib_mem_free (p);
341  }
342  return q;
343 }
344 
346 clib_mem_size (void *p)
347 {
349  return clib_mem_size_nocheck (p);
350 }
351 
352 always_inline void
354 {
355  uword size = clib_mem_size (p);
356  CLIB_MEM_UNPOISON (p, size);
357  memset_s_inline (p, size, 0, size);
358  clib_mem_free (p);
359 }
360 
363 {
364  return clib_mem_get_per_cpu_heap ();
365 }
366 
369 {
370  return clib_mem_set_per_cpu_heap (heap);
371 }
372 
374 clib_mem_heap_t *clib_mem_create_heap (void *base, uword size, int is_locked,
375  char *fmt, ...);
376 
377 void clib_mem_main_init ();
378 void *clib_mem_init (void *base, uword size);
380  clib_mem_page_sz_t log2_page_sz);
382 
383 void clib_mem_exit (void);
384 
385 void clib_mem_trace (int enable);
386 
387 int clib_mem_is_traced (void);
388 
389 typedef struct
390 {
391  /* Total number of objects allocated. */
393 
394  /* Total allocated bytes. Bytes used and free.
395  used + free = total */
396  uword bytes_total, bytes_used, bytes_free;
397 
398  /* Number of bytes used by mheap data structure overhead
399  (e.g. free lists, mheap header). */
401 
402  /* Amount of free space returned to operating system. */
404 
405  /* For malloc which puts small objects in sbrk region and
406  large objects in mmap'ed regions. */
409 
410  /* Max. number of bytes in this heap. */
413 
416 
420 
421 u8 *format_clib_mem_usage (u8 * s, va_list * args);
422 u8 *format_clib_mem_heap (u8 * s, va_list * va);
423 u8 *format_clib_mem_page_stats (u8 * s, va_list * va);
424 
425 /* Allocate virtual address space. */
426 always_inline void *
428 {
429  void *mmap_addr;
430  uword flags = MAP_PRIVATE;
431 
432 #ifdef MAP_ANONYMOUS
433  flags |= MAP_ANONYMOUS;
434 #endif
435 
436  mmap_addr = mmap (0, size, PROT_READ | PROT_WRITE, flags, -1, 0);
437  if (mmap_addr == (void *) -1)
438  mmap_addr = 0;
439  else
440  CLIB_MEM_UNPOISON (mmap_addr, size);
441 
442  return mmap_addr;
443 }
444 
445 always_inline void
447 {
448  munmap (addr, size);
449 }
450 
451 void *clib_mem_vm_map_internal (void *base, clib_mem_page_sz_t log2_page_sz,
452  uword size, int fd, uword offset, char *name);
453 
454 void *clib_mem_vm_map (void *start, uword size,
455  clib_mem_page_sz_t log2_page_size, char *fmt, ...);
456 void *clib_mem_vm_map_stack (uword size, clib_mem_page_sz_t log2_page_size,
457  char *fmt, ...);
458 void *clib_mem_vm_map_shared (void *start, uword size, int fd, uword offset,
459  char *fmt, ...);
460 int clib_mem_vm_unmap (void *base);
462  hdr);
463 
466 {
468 }
469 
472 {
473  return 1ULL << clib_mem_main.log2_page_sz;
474 }
475 
478 {
480 }
481 
484 {
486 }
487 
490 {
492 }
493 
494 int clib_mem_vm_create_fd (clib_mem_page_sz_t log2_page_size, char *fmt, ...);
498  clib_mem_page_sz_t log2_page_sz);
499 u64 *clib_mem_vm_get_paddr (void *mem, clib_mem_page_sz_t log2_page_size,
500  int n_pages);
501 void clib_mem_destroy (void);
502 int clib_mem_set_numa_affinity (u8 numa_node, int force);
504 void clib_mem_vm_randomize_va (uword * requested_va,
505  clib_mem_page_sz_t log2_page_size);
506 void mheap_trace (clib_mem_heap_t * v, int enable);
508 void clib_mem_trace (int enable);
509 
512 {
513  ASSERT (log2_page_size != CLIB_MEM_PAGE_SZ_UNKNOWN);
514 
515  if (log2_page_size == CLIB_MEM_PAGE_SZ_DEFAULT)
516  log2_page_size = clib_mem_get_log2_page_size ();
517  else if (log2_page_size == CLIB_MEM_PAGE_SZ_DEFAULT_HUGE)
518  log2_page_size = clib_mem_get_log2_default_hugepage_size ();
519 
520  return round_pow2 (size, 1ULL << log2_page_size);
521 }
522 
523 typedef struct
524 {
532 
533 void clib_mem_get_page_stats (void *start, clib_mem_page_sz_t log2_page_size,
534  uword n_pages, clib_mem_page_stats_t * stats);
535 
538 {
540  u32 bitmap = mm->numa_node_bitmap;
541 
542  if (numa >= 0)
543  bitmap &= ~pow2_mask (numa + 1);
544  if (bitmap == 0)
545  return -1;
546 
547  return count_trailing_zeros (bitmap);
548 }
549 
552 {
553  if (log2_page_size == CLIB_MEM_PAGE_SZ_DEFAULT)
554  return clib_mem_get_log2_page_size ();
555  if (log2_page_size == CLIB_MEM_PAGE_SZ_DEFAULT_HUGE)
557  return log2_page_size;
558 }
559 
562 {
563  return 1ULL << clib_mem_log2_page_size_validate (log2_page_size);
564 }
565 
568 {
569  return clib_mem_main.error;
570 }
571 
572 /* bulk allocator */
573 
576  u32 min_elts_per_chunk);
580 u8 *format_clib_mem_bulk (u8 *s, va_list *args);
581 
582 #include <vppinfra/error.h> /* clib_panic */
583 
584 #endif /* _included_clib_mem_h */
585 
586 /*
587  * fd.io coding-style-patch-verification: ON
588  *
589  * Local Variables:
590  * eval: (c-set-style "gnu")
591  * End:
592  */
clib_mem_main_t::error
clib_error_t * error
Definition: mem.h:155
CLIB_MAX_MHEAPS
#define CLIB_MAX_MHEAPS
Definition: mem.h:52
os.h
clib_mem_usage_t::bytes_used_sbrk
uword bytes_used_sbrk
Definition: mem.h:407
clib_mem_vm_map_stack
void * clib_mem_vm_map_stack(uword size, clib_mem_page_sz_t log2_page_size, char *fmt,...)
Definition: mem.c:42
CLIB_MEM_PAGE_SZ_64K
@ CLIB_MEM_PAGE_SZ_64K
Definition: mem.h:64
clib_mem_round_to_page_size
static uword clib_mem_round_to_page_size(uword size, clib_mem_page_sz_t log2_page_size)
Definition: mem.h:511
clib_mem_vm_unmap
int clib_mem_vm_unmap(void *base)
Definition: mem.c:478
CLIB_MEM_PAGE_SZ_32M
@ CLIB_MEM_PAGE_SZ_32M
Definition: mem.h:68
count_trailing_zeros
#define count_trailing_zeros(x)
Definition: clib.h:161
os_set_thread_index
static_always_inline void os_set_thread_index(uword thread_index)
Definition: os.h:69
clib_mem_vm_map_hdr_t
struct _clib_mem_vm_map_hdr clib_mem_vm_map_hdr_t
clib_mem_page_stats_t
Definition: mem.h:523
clib_mem_page_stats_t::mapped
uword mapped
Definition: mem.h:527
CLIB_MEM_PAGE_SZ_16G
@ CLIB_MEM_PAGE_SZ_16G
Definition: mem.h:71
clib_mem_log2_page_size_validate
static_always_inline clib_mem_page_sz_t clib_mem_log2_page_size_validate(clib_mem_page_sz_t log2_page_size)
Definition: mem.h:551
clib_mem_get_heap
static clib_mem_heap_t * clib_mem_get_heap(void)
Definition: mem.h:362
clib_mem_vm_reserve
uword clib_mem_vm_reserve(uword start, uword size, clib_mem_page_sz_t log2_page_sz)
Definition: mem.c:299
clib_mem_get_heap_base
void * clib_mem_get_heap_base(clib_mem_heap_t *heap)
Definition: mem_dlmalloc.c:586
clib_mem_bulk_handle_t
void * clib_mem_bulk_handle_t
Definition: mem.h:574
clib_mem_realloc
static void * clib_mem_realloc(void *p, uword new_size, uword old_size)
Definition: mem.h:328
CLIB_MEM_PAGE_SZ_DEFAULT_HUGE
@ CLIB_MEM_PAGE_SZ_DEFAULT_HUGE
Definition: mem.h:61
clib_mem_usage_t::bytes_max
uword bytes_max
Definition: mem.h:411
clib_mem_usage_t
Definition: mem.h:389
CLIB_MEM_POISON
#define CLIB_MEM_POISON(a, s)
Definition: sanitizer.h:113
pow2_mask
static uword pow2_mask(uword x)
Definition: clib.h:252
name
string name[64]
Definition: fib.api:25
clib.h
clib_mem_heap_t::mspace
void * mspace
Definition: mem.h:113
usage
static void usage(void)
Definition: health_check.c:14
next
u16 * next
Definition: nat44_ei_out2in.c:718
string.h
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
clib_mem_heap_t::base
void * base
Definition: mem.h:110
clib_mem_get_default_hugepage_size
static_always_inline uword clib_mem_get_default_hugepage_size(void)
Definition: mem.h:489
clib_mem_get_heap_free_space
uword clib_mem_get_heap_free_space(clib_mem_heap_t *heap)
Definition: mem_dlmalloc.c:579
mspace_usable_size_with_delta
DLMALLOC_EXPORT size_t mspace_usable_size_with_delta(const void *p)
clib_mem_main_t::log2_sys_default_hugepage_sz
clib_mem_page_sz_t log2_sys_default_hugepage_sz
Definition: mem.h:137
format_clib_mem_heap
u8 * format_clib_mem_heap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:422
os_out_of_memory
void os_out_of_memory(void)
Definition: unix-misc.c:219
clib_mem_get_heap_size
uword clib_mem_get_heap_size(clib_mem_heap_t *heap)
Definition: mem_dlmalloc.c:592
clib_mem_bulk_free
void clib_mem_bulk_free(clib_mem_bulk_handle_t h, void *p)
Definition: mem_bulk.c:179
clib_mem_alloc_aligned_or_null
static void * clib_mem_alloc_aligned_or_null(uword size, uword align)
Definition: mem.h:280
clib_mem_page_bytes
static_always_inline uword clib_mem_page_bytes(clib_mem_page_sz_t log2_page_size)
Definition: mem.h:561
mem
void * mem
Definition: flowhash_template.h:361
clib_mem_vm_get_next_map_hdr
clib_mem_vm_map_hdr_t * clib_mem_vm_get_next_map_hdr(clib_mem_vm_map_hdr_t *hdr)
Definition: mem.c:355
stats
vl_api_ikev2_sa_stats_t stats
Definition: ikev2_types.api:162
clib_mem_trace_enable_disable
uword clib_mem_trace_enable_disable(uword enable)
Definition: mem_dlmalloc.c:525
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
clib_mem_set_thread_index
static void clib_mem_set_thread_index(void)
Definition: mem.h:196
clib_mem_set_per_numa_heap
static void * clib_mem_set_per_numa_heap(void *new_heap)
Definition: mem.h:187
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
memory_size
u64 memory_size
Definition: vhost_user.h:124
h
h
Definition: flowhash_template.h:372
clib_mem_set_default_numa_affinity
int clib_mem_set_default_numa_affinity()
Definition: mem.c:644
clib_mem_main_t
Definition: mem.h:128
clib_mem_alloc_or_null
static void * clib_mem_alloc_or_null(uword size)
Definition: mem.h:272
clib_mem_main_t::per_cpu_mheaps
void * per_cpu_mheaps[CLIB_MAX_MHEAPS]
Definition: mem.h:143
round_pow2
static uword round_pow2(uword x, uword pow2)
Definition: clib.h:279
clib_mem_heap_t::size
uword size
Definition: mem.h:116
clib_mem_get_per_numa_heap
static void * clib_mem_get_per_numa_heap(u32 numa_id)
Definition: mem.h:180
mspace_get_aligned
DLMALLOC_EXPORT void * mspace_get_aligned(mspace msp, unsigned long n_user_data_bytes, unsigned long align, unsigned long align_offset)
clib_mem_set_numa_affinity
int clib_mem_set_numa_affinity(u8 numa_node, int force)
Definition: mem.c:608
clib_mem_page_stats_t::unknown
uword unknown
Definition: mem.h:530
clib_mem_get_per_cpu_heap
static clib_mem_heap_t * clib_mem_get_per_cpu_heap(void)
Definition: mem.h:164
clib_mem_create_heap
clib_mem_heap_t * clib_mem_create_heap(void *base, uword size, int is_locked, char *fmt,...)
Definition: mem_dlmalloc.c:536
error.h
clib_mem_size
static uword clib_mem_size(void *p)
Definition: mem.h:346
clib_mem_page_stats_t::total
uword total
Definition: mem.h:526
memory
vhost_user_memory_t memory
Definition: vhost_user.h:131
CLIB_MEM_PAGE_SZ_1G
@ CLIB_MEM_PAGE_SZ_1G
Definition: mem.h:70
clib_mem_vm_map
void * clib_mem_vm_map(void *start, uword size, clib_mem_page_sz_t log2_page_size, char *fmt,...)
Definition: mem.c:25
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
clib_mem_vm_map_shared
void * clib_mem_vm_map_shared(void *start, uword size, int fd, uword offset, char *fmt,...)
Definition: mem.c:59
clib_mem_main_t::per_numa_mheaps
void * per_numa_mheaps[CLIB_MAX_NUMAS]
Definition: mem.h:146
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
static_always_inline
#define static_always_inline
Definition: clib.h:112
CLIB_MEM_PAGE_SZ_16K
@ CLIB_MEM_PAGE_SZ_16K
Definition: mem.h:63
clib_mem_destroy_heap
void clib_mem_destroy_heap(clib_mem_heap_t *heap)
Definition: mem_dlmalloc.c:566
foreach_clib_mem_heap_flag
#define foreach_clib_mem_heap_flag
Definition: mem.h:96
CLIB_MEM_PAGE_SZ_4K
@ CLIB_MEM_PAGE_SZ_4K
Definition: mem.h:62
clib_mem_free_s
static void clib_mem_free_s(void *p)
Definition: mem.h:353
uword
u64 uword
Definition: types.h:112
clib_mem_main_t::numa_node_bitmap
u32 numa_node_bitmap
Definition: mem.h:140
clib_mem_destroy
void clib_mem_destroy(void)
Definition: mem_dlmalloc.c:287
CLIB_MEM_PAGE_SZ_512M
@ CLIB_MEM_PAGE_SZ_512M
Definition: mem.h:69
CLIB_MEM_PAGE_SZ_1M
@ CLIB_MEM_PAGE_SZ_1M
Definition: mem.h:65
memset_s_inline
static errno_t memset_s_inline(void *s, rsize_t smax, int c, rsize_t n)
Definition: string.h:202
CLIB_VM_MAP_HDR_NAME_MAX_LEN
#define CLIB_VM_MAP_HDR_NAME_MAX_LEN
Definition: mem.h:89
clib_mem_set_log2_default_hugepage_size
static_always_inline void clib_mem_set_log2_default_hugepage_size(clib_mem_page_sz_t log2_page_sz)
Definition: mem.h:477
clib_mem_vm_free
static void clib_mem_vm_free(void *addr, uword size)
Definition: mem.h:446
clib_mem_bulk_init
clib_mem_bulk_handle_t clib_mem_bulk_init(u32 elt_sz, u32 align, u32 min_elts_per_chunk)
Definition: mem_bulk.c:54
CLIB_MEM_PAGE_SZ_2M
@ CLIB_MEM_PAGE_SZ_2M
Definition: mem.h:66
CLIB_MEM_PAGE_SZ_16M
@ CLIB_MEM_PAGE_SZ_16M
Definition: mem.h:67
clib_mem_exit
void clib_mem_exit(void)
vlib_mem_get_next_numa_node
static_always_inline int vlib_mem_get_next_numa_node(int numa)
Definition: mem.h:537
clib_mem_heap_t::log2_page_sz
clib_mem_page_sz_t log2_page_sz
Definition: mem.h:119
align_offset
#define align_offset(A)
Definition: dlmalloc.c:200
clib_mem_vm_get_paddr
u64 * clib_mem_vm_get_paddr(void *mem, clib_mem_page_sz_t log2_page_size, int n_pages)
Definition: mem.c:566
fmt
int cJSON_bool fmt
Definition: cJSON.h:160
format_clib_mem_page_stats
u8 * format_clib_mem_page_stats(u8 *s, va_list *va)
Definition: mem.c:75
os_get_thread_index
static_always_inline uword os_get_thread_index(void)
Definition: os.h:63
clib_mem_init_thread_safe
void * clib_mem_init_thread_safe(void *memory, uword memory_size)
Definition: mem_dlmalloc.c:280
size
u32 size
Definition: vhost_user.h:125
clib_mem_main_t::log2_page_sz
clib_mem_page_sz_t log2_page_sz
Definition: mem.h:131
format_clib_mem_bulk
u8 * format_clib_mem_bulk(u8 *s, va_list *args)
Definition: mem_bulk.c:213
clib_mem_vm_create_fd
int clib_mem_vm_create_fd(clib_mem_page_sz_t log2_page_size, char *fmt,...)
Definition: mem.c:231
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
clib_bihash_value
template key/value backing page structure
Definition: bihash_doc.h:44
clib_mem_heap_flag_t
clib_mem_heap_flag_t
Definition: mem.h:100
u64
unsigned long u64
Definition: types.h:89
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
clib_mem_get_log2_default_hugepage_size
static_always_inline clib_mem_page_sz_t clib_mem_get_log2_default_hugepage_size()
Definition: mem.h:483
clib_mem_vm_alloc
static void * clib_mem_vm_alloc(uword size)
Definition: mem.h:427
clib_mem_bulk_alloc
void * clib_mem_bulk_alloc(clib_mem_bulk_handle_t h)
Definition: mem_bulk.c:141
clib_mem_main
clib_mem_main_t clib_mem_main
Definition: mem.c:22
clib_mem_get_page_stats
void clib_mem_get_page_stats(void *start, clib_mem_page_sz_t log2_page_size, uword n_pages, clib_mem_page_stats_t *stats)
Definition: mem.c:522
u32
unsigned int u32
Definition: types.h:88
clib_mem_get_fd_page_size
uword clib_mem_get_fd_page_size(int fd)
Definition: mem.c:148
clib_mem_usage_t::bytes_used_mmap
uword bytes_used_mmap
Definition: mem.h:408
CLIB_MEM_PAGE_SZ_DEFAULT
@ CLIB_MEM_PAGE_SZ_DEFAULT
Definition: mem.h:60
CLIB_MEM_UNPOISON
#define CLIB_MEM_UNPOISON(a, s)
Definition: sanitizer.h:114
clib_mem_set_per_cpu_heap
static void * clib_mem_set_per_cpu_heap(void *new_heap)
Definition: mem.h:171
clib_mem_main_t::map_lock
u8 map_lock
Definition: mem.h:152
CLIB_MAX_NUMAS
#define CLIB_MAX_NUMAS
Definition: mem.h:53
clib_mem_vm_randomize_va
void clib_mem_vm_randomize_va(uword *requested_va, clib_mem_page_sz_t log2_page_size)
Definition: mem.c:164
clib_mem_get_page_size
static_always_inline uword clib_mem_get_page_size(void)
Definition: mem.h:471
mspace_put
DLMALLOC_EXPORT void mspace_put(mspace msp, void *p)
clib_mem_main_t::log2_default_hugepage_sz
clib_mem_page_sz_t log2_default_hugepage_sz
Definition: mem.h:134
clib_mem_get_log2_page_size
static_always_inline clib_mem_page_sz_t clib_mem_get_log2_page_size(void)
Definition: mem.h:465
clib_mem_vm_map_internal
void * clib_mem_vm_map_internal(void *base, clib_mem_page_sz_t log2_page_sz, uword size, int fd, uword offset, char *name)
Definition: mem.c:375
clib_mem_usage_t::bytes_used
uword bytes_used
Definition: mem.h:396
clib_mem_init
void * clib_mem_init(void *base, uword size)
Definition: mem_dlmalloc.c:266
clib_mem_heap_t::flags
clib_mem_heap_flag_t flags
Definition: mem.h:122
clib_mem_page_sz_t
clib_mem_page_sz_t
Definition: mem.h:57
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
mheap_trace
void mheap_trace(clib_mem_heap_t *v, int enable)
Definition: mem_dlmalloc.c:494
clib_mem_main_t::last_map
clib_mem_vm_map_hdr_t * last_map
Definition: mem.h:149
clib_error.h
os_get_numa_index
static_always_inline uword os_get_numa_index(void)
Definition: os.h:75
i
int i
Definition: flowhash_template.h:376
clib_mem_alloc_aligned_at_offset
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
Definition: mem.h:225
clib_mem_is_traced
int clib_mem_is_traced(void)
Definition: mem_dlmalloc.c:518
clib_mem_alloc_aligned
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:264
mspace_is_heap_object
DLMALLOC_EXPORT int mspace_is_heap_object(mspace msp, void *p)
clib_mem_get_fd_log2_page_size
clib_mem_page_sz_t clib_mem_get_fd_log2_page_size(int fd)
Definition: mem.c:157
clib_mem_init_with_page_size
void * clib_mem_init_with_page_size(uword memory_size, clib_mem_page_sz_t log2_page_sz)
Definition: mem_dlmalloc.c:273
clib_mem_usage_t::object_count
uword object_count
Definition: mem.h:392
clib_mem_bulk_destroy
void clib_mem_bulk_destroy(clib_mem_bulk_handle_t h)
Definition: mem_bulk.c:83
clib_mem_get_heap_usage
void clib_mem_get_heap_usage(clib_mem_heap_t *heap, clib_mem_usage_t *usage)
Definition: mem_dlmalloc.c:473
sanitizer.h
clib_mem_get_last_error
static_always_inline clib_error_t * clib_mem_get_last_error(void)
Definition: mem.h:567
clib_mem_page_stats_t::not_mapped
uword not_mapped
Definition: mem.h:528
CLIB_MEM_PAGE_SZ_UNKNOWN
@ CLIB_MEM_PAGE_SZ_UNKNOWN
Definition: mem.h:59
clib_mem_main_init
void clib_mem_main_init()
Definition: mem.c:102
clib_mem_usage_t::bytes_free_reclaimed
uword bytes_free_reclaimed
Definition: mem.h:403
clib_mem_set_heap
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
Definition: mem.h:368
clib_mem_heap_t
Definition: mem.h:107
clib_mem_page_stats_t::log2_page_sz
clib_mem_page_sz_t log2_page_sz
Definition: mem.h:525
clib_atomic_bool_cmp_and_swap
#define clib_atomic_bool_cmp_and_swap(addr, old, new)
Definition: atomics.h:38
clib_mem_size_nocheck
static uword clib_mem_size_nocheck(void *p)
Definition: mem.h:217
clib_mem_alloc
static void * clib_mem_alloc(uword size)
Definition: mem.h:256
clib_mem_trace
void clib_mem_trace(int enable)
Definition: mem_dlmalloc.c:503
clib_mem_is_heap_object
static uword clib_mem_is_heap_object(void *p)
Definition: mem.h:306
format_clib_mem_usage
u8 * format_clib_mem_usage(u8 *s, va_list *args)
Definition: mem_dlmalloc.c:301
clib_mem_usage_t::bytes_overhead
uword bytes_overhead
Definition: mem.h:400
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105