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