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