FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
pmalloc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 #define _GNU_SOURCE
17 #include <stdlib.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <fcntl.h>
21 #include <unistd.h>
22 #include <sched.h>
23 
24 #include <vppinfra/format.h>
25 #include <vppinfra/linux/sysfs.h>
26 #include <vppinfra/mem.h>
27 #include <vppinfra/hash.h>
28 #include <vppinfra/pmalloc.h>
29 #include <vppinfra/cpu.h>
30 
31 #if __SIZEOF_POINTER__ >= 8
32 #define DEFAULT_RESERVED_MB 16384
33 #else
34 #define DEFAULT_RESERVED_MB 256
35 #endif
36 
37 static inline clib_pmalloc_chunk_t *
39 {
40  return pool_elt_at_index (pp->chunks, index);
41 }
42 
43 static inline uword
45 {
46  return round_pow2 (size, 1ULL << log2_page_sz) >> log2_page_sz;
47 }
48 
49 __clib_export int
51 {
52  uword base, pagesize;
53  u64 *pt = 0;
54 
55  ASSERT (pm->error == 0);
56 
58  pm->def_log2_page_sz = min_log2 (pagesize);
60 
61  /* check if pagemap is accessible */
63  if (pt == 0 || pt[0] == 0)
65 
66  size = size ? size : ((u64) DEFAULT_RESERVED_MB) << 20;
67  size = round_pow2 (size, pagesize);
68 
69  pm->max_pages = size >> pm->def_log2_page_sz;
70 
71  base = clib_mem_vm_reserve (base_addr, size, pm->def_log2_page_sz);
72 
73  if (base == ~0)
74  {
75  pm->error = clib_error_return (0, "failed to reserve %u pages",
76  pm->max_pages);
77  return -1;
78  }
79 
80  pm->base = uword_to_pointer (base, void *);
81  return 0;
82 }
83 
84 static inline void *
86  u32 n_blocks, u32 block_align, u32 numa_node)
87 {
90  void *va;
91  u32 off;
92  u32 alloc_chunk_index;
93 
95 
96  if (pp->chunks == 0)
97  {
98  u32 i, start = 0, prev = ~0;
99 
100  for (i = 0; i < a->subpages_per_page; i++)
101  {
102  pool_get (pp->chunks, c);
103  c->start = start;
104  c->prev = prev;
105  c->size = pp->n_free_blocks / a->subpages_per_page;
106  start += c->size;
107  if (prev == ~0)
108  pp->first_chunk_index = c - pp->chunks;
109  else
110  pp->chunks[prev].next = c - pp->chunks;
111  prev = c - pp->chunks;
112  }
113  c->next = ~0;
114  pp->n_free_chunks = a->subpages_per_page;
115  }
116 
117  if (pp->n_free_blocks < n_blocks)
118  return 0;
119 
120  alloc_chunk_index = pp->first_chunk_index;
121 
122 next_chunk:
123  c = pool_elt_at_index (pp->chunks, alloc_chunk_index);
124  off = (block_align - (c->start & (block_align - 1))) & (block_align - 1);
125 
126  if (c->used || n_blocks + off > c->size)
127  {
128  if (c->next == ~0)
129  return 0;
130  alloc_chunk_index = c->next;
131  goto next_chunk;
132  }
133 
134  /* if alignment is needed create new empty chunk */
135  if (off)
136  {
137  u32 offset_chunk_index;
139  pool_get (pp->chunks, c);
140  pp->n_free_chunks++;
141  offset_chunk_index = alloc_chunk_index;
142  alloc_chunk_index = c - pp->chunks;
143 
144  co = pool_elt_at_index (pp->chunks, offset_chunk_index);
145  c->size = co->size - off;
146  c->next = co->next;
147  c->start = co->start + off;
148  c->prev = offset_chunk_index;
149  co->size = off;
150  co->next = alloc_chunk_index;
151  }
152 
153  c->used = 1;
154  if (c->size > n_blocks)
155  {
156  u32 tail_chunk_index;
158  pool_get (pp->chunks, ct);
159  pp->n_free_chunks++;
160  tail_chunk_index = ct - pp->chunks;
161  c = pool_elt_at_index (pp->chunks, alloc_chunk_index);
162  ct->size = c->size - n_blocks;
163  ct->next = c->next;
164  ct->prev = alloc_chunk_index;
165  ct->start = c->start + n_blocks;
166 
167  c->size = n_blocks;
168  c->next = tail_chunk_index;
169  if (ct->next != ~0)
170  pool_elt_at_index (pp->chunks, ct->next)->prev = tail_chunk_index;
171  }
172  else if (c->next != ~0)
173  pool_elt_at_index (pp->chunks, c->next)->prev = alloc_chunk_index;
174 
175  c = get_chunk (pp, alloc_chunk_index);
176  va = pm->base + ((pp - pm->pages) << pm->def_log2_page_sz) +
177  (c->start << PMALLOC_LOG2_BLOCK_SZ);
178  hash_set (pm->chunk_index_by_va, pointer_to_uword (va), alloc_chunk_index);
179  pp->n_free_blocks -= n_blocks;
180  pp->n_free_chunks--;
181  return va;
182 }
183 
184 static void
186 {
187  uword seek, va, pa, p;
188  int fd;
189  u32 elts_per_page = 1U << (pm->def_log2_page_sz - pm->lookup_log2_page_sz);
190 
192  elts_per_page - 1, CLIB_CACHE_LINE_BYTES);
193 
194  p = (uword) first *elts_per_page;
196  {
197  while (p < (uword) elts_per_page * count)
198  {
199  pm->lookup_table[p] = pointer_to_uword (pm->base) +
200  (p << pm->lookup_log2_page_sz);
201  p++;
202  }
203  return;
204  }
205 
206  fd = open ((char *) "/proc/self/pagemap", O_RDONLY);
207  while (p < (uword) elts_per_page * count)
208  {
209  va = pointer_to_uword (pm->base) + (p << pm->lookup_log2_page_sz);
210  pa = 0;
211  seek = (va >> clib_mem_get_log2_page_size ()) * sizeof (pa);
212  if (fd != -1 && lseek (fd, seek, SEEK_SET) == seek &&
213  read (fd, &pa, sizeof (pa)) == (sizeof (pa)) &&
214  pa & (1ULL << 63) /* page present bit */ )
215  {
216  pa = (pa & pow2_mask (55)) << clib_mem_get_log2_page_size ();
217  }
218  pm->lookup_table[p] = va - pa;
219  p++;
220  }
221 
222  if (fd != -1)
223  close (fd);
224 }
225 
226 static inline clib_pmalloc_page_t *
228  u32 numa_node, u32 n_pages)
229 {
231  clib_pmalloc_page_t *pp = 0;
232  int rv, i, mmap_flags;
233  void *va = MAP_FAILED;
234  uword size = (uword) n_pages << pm->def_log2_page_sz;
235 
236  clib_error_free (pm->error);
237 
238  if (pm->max_pages <= vec_len (pm->pages))
239  {
240  pm->error = clib_error_return (0, "maximum number of pages reached");
241  return 0;
242  }
243 
244  if (a->log2_subpage_sz != clib_mem_get_log2_page_size ())
245  {
246  pm->error = clib_sysfs_prealloc_hugepages (numa_node,
247  a->log2_subpage_sz, n_pages);
248 
249  if (pm->error)
250  return 0;
251  }
252 
253  rv = clib_mem_set_numa_affinity (numa_node, /* force */ 1);
254  if (rv == CLIB_MEM_ERROR && numa_node != 0)
255  {
256  pm->error = clib_error_return_unix (0, "failed to set mempolicy for "
257  "numa node %u", numa_node);
258  return 0;
259  }
260 
261  mmap_flags = MAP_FIXED;
262 
263  if (a->flags & CLIB_PMALLOC_ARENA_F_SHARED_MEM)
264  {
265  mmap_flags |= MAP_SHARED;
266  a->fd = clib_mem_vm_create_fd (a->log2_subpage_sz, "%s", a->name);
267  if (a->fd == -1)
268  goto error;
269  if ((ftruncate (a->fd, size)) == -1)
270  goto error;
271  }
272  else
273  {
274  if (a->log2_subpage_sz != clib_mem_get_log2_page_size ())
275  mmap_flags |= MAP_HUGETLB;
276 
277  mmap_flags |= MAP_PRIVATE | MAP_ANONYMOUS;
278  a->fd = -1;
279  }
280 
281  va = pm->base + (((uword) vec_len (pm->pages)) << pm->def_log2_page_sz);
282  if (mmap (va, size, PROT_READ | PROT_WRITE, mmap_flags, a->fd, 0) ==
283  MAP_FAILED)
284  {
285  pm->error = clib_error_return_unix (0, "failed to mmap %u pages at %p "
286  "fd %d numa %d flags 0x%x", n_pages,
287  va, a->fd, numa_node, mmap_flags);
288  va = MAP_FAILED;
289  goto error;
290  }
291 
292  if (a->log2_subpage_sz != clib_mem_get_log2_page_size () &&
293  mlock (va, size) != 0)
294  {
295  pm->error = clib_error_return_unix (0, "Unable to lock pages");
296  goto error;
297  }
298 
299  clib_memset (va, 0, size);
300 
302  if (rv == CLIB_MEM_ERROR && numa_node != 0)
303  {
304  pm->error = clib_error_return_unix (0, "failed to restore mempolicy");
305  goto error;
306  }
307 
308  /* we tolerate move_pages failure only if request os for numa node 0
309  to support non-numa kernels */
311 
312  if (stats.per_numa[numa_node] != 1 &&
313  !(numa_node == 0 && stats.unknown == 1))
314  {
315  u16 allocated_at = ~0;
316  if (stats.unknown)
318  "unable to get information about numa allocation");
319 
320  for (u16 i = 0; i < CLIB_MAX_NUMAS; i++)
321  if (stats.per_numa[i] == 1)
322  allocated_at = i;
323 
325  "page allocated on the wrong numa node (%u), "
326  "expected %u",
327  allocated_at, numa_node);
328 
329  goto error;
330  }
331 
332  for (i = 0; i < n_pages; i++)
333  {
334  vec_add2 (pm->pages, pp, 1);
336  pp->index = pp - pm->pages;
337  pp->arena_index = a->index;
338  vec_add1 (a->page_indices, pp->index);
339  a->n_pages++;
340  }
341 
342 
343  /* if new arena is using smaller page size, we need to rebuild whole
344  lookup table */
345  if (a->log2_subpage_sz < pm->lookup_log2_page_sz)
346  {
347  pm->lookup_log2_page_sz = a->log2_subpage_sz;
348  pmalloc_update_lookup_table (pm, vec_len (pm->pages) - n_pages,
349  n_pages);
350  }
351  else
353 
354  /* return pointer to 1st page */
355  return pp - (n_pages - 1);
356 
357 error:
358  if (va != MAP_FAILED)
359  {
360  /* unmap & reserve */
361  munmap (va, size);
362  mmap (va, size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
363  -1, 0);
364  }
365  if (a->fd != -1)
366  close (a->fd);
367  return 0;
368 }
369 
370 __clib_export void *
372  uword size, u32 log2_page_sz, u32 numa_node)
373 {
376  u32 n_pages;
377 
378  clib_error_free (pm->error);
379 
380  if (log2_page_sz == 0)
381  log2_page_sz = pm->def_log2_page_sz;
382  else if (log2_page_sz != pm->def_log2_page_sz &&
383  log2_page_sz != clib_mem_get_log2_page_size ())
384  {
385  pm->error = clib_error_create ("unsupported page size (%uKB)",
386  1 << (log2_page_sz - 10));
387  return 0;
388  }
389 
390  n_pages = pmalloc_size2pages (size, pm->def_log2_page_sz);
391 
392  if (n_pages + vec_len (pm->pages) > pm->max_pages)
393  return 0;
394 
395  if (numa_node == CLIB_PMALLOC_NUMA_LOCAL)
396  numa_node = clib_get_current_numa_node ();
397 
398  pool_get (pm->arenas, a);
399  a->index = a - pm->arenas;
400  a->name = format (0, "%s%c", name, 0);
401  a->numa_node = numa_node;
403  a->log2_subpage_sz = log2_page_sz;
404  a->subpages_per_page = 1U << (pm->def_log2_page_sz - log2_page_sz);
405 
406  if ((pp = pmalloc_map_pages (pm, a, numa_node, n_pages)) == 0)
407  {
408  vec_free (a->name);
409  memset (a, 0, sizeof (*a));
410  pool_put (pm->arenas, a);
411  return 0;
412  }
413 
414  return pm->base + ((uword) pp->index << pm->def_log2_page_sz);
415 }
416 
417 static inline void *
419  uword size, uword align, u32 numa_node)
420 {
422  u32 n_blocks, block_align, *page_index;
423 
424  ASSERT (is_pow2 (align));
425 
426  if (numa_node == CLIB_PMALLOC_NUMA_LOCAL)
427  numa_node = clib_get_current_numa_node ();
428 
429  if (a == 0)
430  {
431  if (size > 1ULL << pm->def_log2_page_sz)
432  return 0;
433 
435  numa_node, ~0);
436  if (pm->default_arena_for_numa_node[numa_node] == ~0)
437  {
438  pool_get (pm->arenas, a);
439  pm->default_arena_for_numa_node[numa_node] = a - pm->arenas;
440  a->name = format (0, "default-numa-%u%c", numa_node, 0);
441  a->numa_node = numa_node;
442  a->log2_subpage_sz = pm->def_log2_page_sz;
443  a->subpages_per_page = 1;
444  }
445  else
446  a = pool_elt_at_index (pm->arenas,
447  pm->default_arena_for_numa_node[numa_node]);
448  }
449  else if (size > 1ULL << a->log2_subpage_sz)
450  return 0;
451 
453  block_align = align >> PMALLOC_LOG2_BLOCK_SZ;
454 
455  vec_foreach (page_index, a->page_indices)
456  {
457  pp = vec_elt_at_index (pm->pages, *page_index);
458  void *rv = alloc_chunk_from_page (pm, pp, n_blocks, block_align,
459  numa_node);
460 
461  if (rv)
462  return rv;
463  }
464 
465  if ((a->flags & CLIB_PMALLOC_ARENA_F_SHARED_MEM) == 0 &&
466  (pp = pmalloc_map_pages (pm, a, numa_node, 1)))
467  return alloc_chunk_from_page (pm, pp, n_blocks, block_align, numa_node);
468 
469  return 0;
470 }
471 
472 __clib_export void *
474  uword align, u32 numa_node)
475 {
476  return clib_pmalloc_alloc_inline (pm, 0, size, align, numa_node);
477 }
478 
479 void *
481 {
482  return clib_pmalloc_alloc_inline (pm, 0, size, align,
484 }
485 
486 __clib_export void *
488  uword size, uword align)
489 {
491  return clib_pmalloc_alloc_inline (pm, a, size, align, 0);
492 }
493 
494 static inline int
496  u32 ci1, u32 ci2)
497 {
498  clib_pmalloc_chunk_t *c1, *c2;
499 
500  if (ci1 == ~0 || ci2 == ~0)
501  return 0;
502 
503  c1 = get_chunk (pp, ci1);
504  c2 = get_chunk (pp, ci2);
505 
506  if (c1->used || c2->used)
507  return 0;
508 
509  if (c1->start >> (a->log2_subpage_sz - PMALLOC_LOG2_BLOCK_SZ) !=
510  c2->start >> (a->log2_subpage_sz - PMALLOC_LOG2_BLOCK_SZ))
511  return 0;
512 
513  return 1;
514 }
515 
516 __clib_export void
518 {
522  uword *p;
523  u32 chunk_index, page_index;
524 
526 
527  if (p == 0)
528  os_panic ();
529 
530  chunk_index = p[0];
531  page_index = clib_pmalloc_get_page_index (pm, va);
533 
534  pp = vec_elt_at_index (pm->pages, page_index);
535  c = pool_elt_at_index (pp->chunks, chunk_index);
536  a = pool_elt_at_index (pm->arenas, pp->arena_index);
537  c->used = 0;
538  pp->n_free_blocks += c->size;
539  pp->n_free_chunks++;
540 
541  /* merge with next if free */
542  if (pmalloc_chunks_mergeable (a, pp, chunk_index, c->next))
543  {
544  clib_pmalloc_chunk_t *next = get_chunk (pp, c->next);
545  c->size += next->size;
546  c->next = next->next;
547  if (next->next != ~0)
548  get_chunk (pp, next->next)->prev = chunk_index;
549  memset (next, 0, sizeof (*next));
550  pool_put (pp->chunks, next);
551  pp->n_free_chunks--;
552  }
553 
554  /* merge with prev if free */
555  if (pmalloc_chunks_mergeable (a, pp, c->prev, chunk_index))
556  {
557  clib_pmalloc_chunk_t *prev = get_chunk (pp, c->prev);
558  prev->size += c->size;
559  prev->next = c->next;
560  if (c->next != ~0)
561  get_chunk (pp, c->next)->prev = c->prev;
562  memset (c, 0, sizeof (*c));
563  pool_put (pp->chunks, c);
564  pp->n_free_chunks--;
565  }
566 }
567 
568 static u8 *
569 format_pmalloc_page (u8 * s, va_list * va)
570 {
571  clib_pmalloc_page_t *pp = va_arg (*va, clib_pmalloc_page_t *);
572  int verbose = va_arg (*va, int);
573  u32 indent = format_get_indent (s);
574 
575  if (pp->chunks == 0)
576  return s;
577 
578  s = format (s, "free %u chunks %u free-chunks %d ",
580  pool_elts (pp->chunks), pp->n_free_chunks);
581 
582  if (verbose >= 2)
583  {
586  s = format (s, "\n%U%12s%12s%8s%8s%8s%8s",
587  format_white_space, indent + 2,
588  "chunk offset", "size", "used", "index", "prev", "next");
589  while (1)
590  {
591  s = format (s, "\n%U%12u%12u%8s%8d%8d%8d",
592  format_white_space, indent + 2,
593  c->start << PMALLOC_LOG2_BLOCK_SZ,
594  c->size << PMALLOC_LOG2_BLOCK_SZ,
595  c->used ? "yes" : "no",
596  c - pp->chunks, c->prev, c->next);
597  if (c->next == ~0)
598  break;
599  c = pool_elt_at_index (pp->chunks, c->next);
600  }
601  }
602  return s;
603 }
604 
605 __clib_export u8 *
606 format_pmalloc (u8 * s, va_list * va)
607 {
608  clib_pmalloc_main_t *pm = va_arg (*va, clib_pmalloc_main_t *);
609  int verbose = va_arg (*va, int);
610  u32 indent = format_get_indent (s);
611 
614 
615  s = format (s, "used-pages %u reserved-pages %u default-page-size %U "
616  "lookup-page-size %U%s", vec_len (pm->pages), pm->max_pages,
619  pm->flags & CLIB_PMALLOC_F_NO_PAGEMAP ? " no-pagemap" : "");
620 
621 
622  if (verbose >= 2)
623  s = format (s, " va-start %p", pm->base);
624 
625  if (pm->error)
626  s = format (s, "\n%Ulast-error: %U", format_white_space, indent + 2,
627  format_clib_error, pm->error);
628 
629 
630  /* *INDENT-OFF* */
631  pool_foreach (a, pm->arenas)
632  {
633  u32 *page_index;
634  s = format (s, "\n%Uarena '%s' pages %u subpage-size %U numa-node %u",
635  format_white_space, indent + 2, a->name,
636  vec_len (a->page_indices), format_log2_page_size,
637  a->log2_subpage_sz, a->numa_node);
638  if (a->fd != -1)
639  s = format (s, " shared fd %d", a->fd);
640  if (verbose >= 1)
641  vec_foreach (page_index, a->page_indices)
642  {
643  pp = vec_elt_at_index (pm->pages, *page_index);
644  s = format (s, "\n%U%U", format_white_space, indent + 4,
645  format_pmalloc_page, pp, verbose);
646  }
647  }
648  /* *INDENT-ON* */
649 
650  return s;
651 }
652 
653 __clib_export u8 *
654 format_pmalloc_map (u8 * s, va_list * va)
655 {
656  clib_pmalloc_main_t *pm = va_arg (*va, clib_pmalloc_main_t *);
657 
658  u32 index;
659  s = format (s, "%16s %13s %8s", "virtual-addr", "physical-addr", "size");
661  {
662  uword *lookup_val, pa, va;
663  lookup_val = vec_elt_at_index (pm->lookup_table, index);
664  va =
665  pointer_to_uword (pm->base) +
666  ((uword) index << pm->lookup_log2_page_sz);
667  pa = va - *lookup_val;
668  s =
669  format (s, "\n %16p %13p %8U", uword_to_pointer (va, u64),
671  pm->lookup_log2_page_sz);
672  }
673  return s;
674 }
675 
676 /*
677  * fd.io coding-style-patch-verification: ON
678  *
679  * Local Variables:
680  * eval: (c-set-style "gnu")
681  * End:
682  */
CLIB_MEM_ERROR
#define CLIB_MEM_ERROR
Definition: mem.h:55
hash_set
#define hash_set(h, key, value)
Definition: hash.h:255
CLIB_PMALLOC_ARENA_F_SHARED_MEM
#define CLIB_PMALLOC_ARENA_F_SHARED_MEM
Definition: pmalloc.h:49
clib_mem_set_default_numa_affinity
__clib_export int clib_mem_set_default_numa_affinity()
Definition: mem.c:644
clib_mem_page_stats_t
Definition: mem.h:523
os_panic
void os_panic(void)
Definition: pnat_test_stubs.h:19
pow2_mask
static uword pow2_mask(uword x)
Definition: clib.h:252
clib_pmalloc_page_t::first_chunk_index
u32 first_chunk_index
Definition: pmalloc.h:40
pointer_to_uword
static uword pointer_to_uword(const void *p)
Definition: types.h:131
clib_pmalloc_main_t::lookup_log2_page_sz
u32 lookup_log2_page_sz
Definition: pmalloc.h:96
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
name
string name[64]
Definition: fib.api:25
format_pmalloc
__clib_export u8 * format_pmalloc(u8 *s, va_list *va)
Definition: pmalloc.c:606
next
u16 * next
Definition: nat44_ei_out2in.c:718
clib_pmalloc_page_t::index
u32 index
Definition: pmalloc.h:37
format_pmalloc_page
static u8 * format_pmalloc_page(u8 *s, va_list *va)
Definition: pmalloc.c:569
clib_mem_get_default_hugepage_size
static_always_inline uword clib_mem_get_default_hugepage_size(void)
Definition: mem.h:489
pmalloc_size2pages
static uword pmalloc_size2pages(uword size, u32 log2_page_sz)
Definition: pmalloc.c:44
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
clib_pmalloc_page_t::n_free_blocks
u32 n_free_blocks
Definition: pmalloc.h:42
CLIB_PMALLOC_NUMA_LOCAL
#define CLIB_PMALLOC_NUMA_LOCAL
Definition: pmalloc.h:24
u16
unsigned short u16
Definition: types.h:57
first
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
pmalloc_update_lookup_table
static void pmalloc_update_lookup_table(clib_pmalloc_main_t *pm, u32 first, u32 count)
Definition: pmalloc.c:185
clib_sysfs_prealloc_hugepages
clib_error_t * clib_sysfs_prealloc_hugepages(int numa_node, int log2_page_size, int nr)
Definition: sysfs.c:240
clib_pmalloc_arena_t
Definition: pmalloc.h:45
pmalloc_map_pages
static clib_pmalloc_page_t * pmalloc_map_pages(clib_pmalloc_main_t *pm, clib_pmalloc_arena_t *a, u32 numa_node, u32 n_pages)
Definition: pmalloc.c:227
clib_pmalloc_get_page_index
static u32 clib_pmalloc_get_page_index(clib_pmalloc_main_t *pm, void *va)
Definition: pmalloc.h:128
PMALLOC_LOG2_BLOCK_SZ
#define PMALLOC_LOG2_BLOCK_SZ
Definition: pmalloc.h:21
stats
vl_api_ikev2_sa_stats_t stats
Definition: ikev2_types.api:162
clib_mem_get_page_stats
__clib_export 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
error
Definition: cJSON.c:88
sysfs.h
hash_unset
#define hash_unset(h, key)
Definition: hash.h:261
format_clib_error
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
clib_mem_vm_create_fd
__clib_export int clib_mem_vm_create_fd(clib_mem_page_sz_t log2_page_size, char *fmt,...)
Definition: mem.c:231
format_log2_page_size
u8 * format_log2_page_size(u8 *s, va_list *va)
Definition: std-formats.c:273
clib_pmalloc_page_t::chunks
clib_pmalloc_chunk_t * chunks
Definition: pmalloc.h:39
get_chunk
static clib_pmalloc_chunk_t * get_chunk(clib_pmalloc_page_t *pp, u32 index)
Definition: pmalloc.c:38
clib_pmalloc_main_t::arenas
clib_pmalloc_arena_t * arenas
Definition: pmalloc.h:86
round_pow2
static uword round_pow2(uword x, uword pow2)
Definition: clib.h:279
clib_mem_set_numa_affinity
__clib_export int clib_mem_set_numa_affinity(u8 numa_node, int force)
Definition: mem.c:608
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
clib_pmalloc_page_t::n_free_chunks
u32 n_free_chunks
Definition: pmalloc.h:41
hash.h
CLIB_PMALLOC_F_NO_PAGEMAP
#define CLIB_PMALLOC_F_NO_PAGEMAP
Definition: pmalloc.h:64
count
u8 count
Definition: dhcp.api:208
DEFAULT_RESERVED_MB
#define DEFAULT_RESERVED_MB
Definition: pmalloc.c:34
clib_error_create
#define clib_error_create(args...)
Definition: error.h:96
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
clib_pmalloc_free
__clib_export void clib_pmalloc_free(clib_pmalloc_main_t *pm, void *va)
Definition: pmalloc.c:517
clib_pmalloc_main_t::default_arena_for_numa_node
u32 * default_arena_for_numa_node
Definition: pmalloc.h:90
vec_add2
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:644
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
clib_pmalloc_alloc_aligned
void * clib_pmalloc_alloc_aligned(clib_pmalloc_main_t *pm, uword size, uword align)
Definition: pmalloc.c:480
pmalloc_chunks_mergeable
static int pmalloc_chunks_mergeable(clib_pmalloc_arena_t *a, clib_pmalloc_page_t *pp, u32 ci1, u32 ci2)
Definition: pmalloc.c:495
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
hash_get
#define hash_get(h, key)
Definition: hash.h:249
vec_validate_aligned
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:534
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
alloc_chunk_from_page
static void * alloc_chunk_from_page(clib_pmalloc_main_t *pm, clib_pmalloc_page_t *pp, u32 n_blocks, u32 block_align, u32 numa_node)
Definition: pmalloc.c:85
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
uword
u64 uword
Definition: types.h:112
clib_pmalloc_main_t::lookup_table
uword * lookup_table
Definition: pmalloc.h:93
clib_pmalloc_page_t
Definition: pmalloc.h:35
clib_pmalloc_main_t::pages
clib_pmalloc_page_t * pages
Definition: pmalloc.h:77
clib_pmalloc_init
__clib_export int clib_pmalloc_init(clib_pmalloc_main_t *pm, uword base_addr, uword size)
Definition: pmalloc.c:50
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
format.h
clib_get_current_numa_node
__clib_export u32 clib_get_current_numa_node()
Definition: cpu.c:234
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_pmalloc_main_t
Definition: pmalloc.h:60
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:58
cpu.h
next_chunk
#define next_chunk(p)
Definition: dlmalloc.c:859
clib_pmalloc_alloc_from_arena
__clib_export void * clib_pmalloc_alloc_from_arena(clib_pmalloc_main_t *pm, void *arena_va, uword size, uword align)
Definition: pmalloc.c:487
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
size
u32 size
Definition: vhost_user.h:125
index
u32 index
Definition: flow_types.api:221
clib_pmalloc_main_t::base
u8 * base
Definition: pmalloc.h:67
clib_pmalloc_main_t::error
clib_error_t * error
Definition: pmalloc.h:99
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
off
u32 off
Definition: interface_output.c:1096
u32
unsigned int u32
Definition: types.h:88
CLIB_MEM_PAGE_SZ_DEFAULT
@ CLIB_MEM_PAGE_SZ_DEFAULT
Definition: mem.h:60
CLIB_MAX_NUMAS
#define CLIB_MAX_NUMAS
Definition: mem.h:53
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
clib_pmalloc_main_t::def_log2_page_sz
clib_mem_page_sz_t def_log2_page_sz
Definition: pmalloc.h:70
clib_error_return_unix
#define clib_error_return_unix(e, args...)
Definition: error.h:102
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
clib_pmalloc_chunk_t::next
u32 next
Definition: pmalloc.h:28
pmalloc.h
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_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
clib_pmalloc_main_t::max_pages
u32 max_pages
Definition: pmalloc.h:73
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:525
clib_pmalloc_main_t::flags
u32 flags
Definition: pmalloc.h:63
uword_to_pointer
#define uword_to_pointer(u, type)
Definition: types.h:136
clib_pmalloc_page_t::arena_index
u32 arena_index
Definition: pmalloc.h:38
i
int i
Definition: flowhash_template.h:376
clib_pmalloc_main_t::chunk_index_by_va
uword * chunk_index_by_va
Definition: pmalloc.h:81
clib_error_free
#define clib_error_free(e)
Definition: error.h:86
clib_mem_vm_get_paddr
__clib_export u64 * clib_mem_vm_get_paddr(void *mem, clib_mem_page_sz_t log2_page_size, int n_pages)
Definition: mem.c:566
clib_pmalloc_chunk_t
Definition: pmalloc.h:26
rv
int __clib_unused rv
Definition: application.c:491
clib_pmalloc_alloc_aligned_on_numa
__clib_export void * clib_pmalloc_alloc_aligned_on_numa(clib_pmalloc_main_t *pm, uword size, uword align, u32 numa_node)
Definition: pmalloc.c:473
clib_pmalloc_create_shared_arena
__clib_export void * clib_pmalloc_create_shared_arena(clib_pmalloc_main_t *pm, char *name, uword size, u32 log2_page_sz, u32 numa_node)
Definition: pmalloc.c:371
PMALLOC_BLOCK_SZ
#define PMALLOC_BLOCK_SZ
Definition: pmalloc.h:22
mem.h
min_log2
static uword min_log2(uword x)
Definition: clib.h:176
is_pow2
static uword is_pow2(uword x)
Definition: clib.h:267
format_pmalloc_map
__clib_export u8 * format_pmalloc_map(u8 *s, va_list *va)
Definition: pmalloc.c:654
clib_pmalloc_chunk_t::start
u32 start
Definition: pmalloc.h:28
clib_pmalloc_chunk_t::prev
u32 prev
Definition: pmalloc.h:28
clib_pmalloc_chunk_t::used
u32 used
Definition: pmalloc.h:30
clib_pmalloc_get_arena
static clib_pmalloc_arena_t * clib_pmalloc_get_arena(clib_pmalloc_main_t *pm, void *va)
Definition: pmalloc.h:139
clib_pmalloc_chunk_t::size
u32 size
Definition: pmalloc.h:29
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
clib_pmalloc_alloc_inline
static void * clib_pmalloc_alloc_inline(clib_pmalloc_main_t *pm, clib_pmalloc_arena_t *a, uword size, uword align, u32 numa_node)
Definition: pmalloc.c:418