summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/pool.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-03-18 12:28:35 +0100
committerDamjan Marion <damarion@cisco.com>2022-03-18 14:15:29 +0100
commit86bbdf926c6d642e789ad6dce6534c23820f3c63 (patch)
treedb764b29b24a369fb576b116bbb426502a04ad1f /src/vppinfra/pool.c
parent762cfd408b16b6ab43ade3ab491292b93bdeb9b3 (diff)
vppinfra: fixed pool from heap
Immediate benefit is ability to use hugepage backed memory. Type: improvement Change-Id: Ibcae961aa09ea92d3e931a40bedbc6346a4b2039 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/pool.c')
-rw-r--r--src/vppinfra/pool.c88
1 files changed, 16 insertions, 72 deletions
diff --git a/src/vppinfra/pool.c b/src/vppinfra/pool.c
index 25398455402..0cd14d4bb97 100644
--- a/src/vppinfra/pool.c
+++ b/src/vppinfra/pool.c
@@ -40,92 +40,36 @@
__clib_export void
_pool_init_fixed (void **pool_ptr, u32 elt_size, u32 max_elts)
{
- u8 *mmap_base;
- u64 vector_size;
- u64 free_index_size;
- u64 total_size;
- u64 page_size;
- pool_header_t *fh;
- vec_header_t *vh;
+ uword *b;
+ pool_header_t *ph;
u8 *v;
- u32 *fi;
u32 i;
- u32 set_bits;
ASSERT (elt_size);
ASSERT (max_elts);
- vector_size =
- vec_header_bytes (pool_aligned_header_bytes) + (u64) elt_size * max_elts;
- free_index_size = vec_header_bytes (0) + sizeof (u32) * max_elts;
+ v = vec_resize_allocate_memory (0, max_elts, elt_size * max_elts,
+ sizeof (pool_header_t),
+ CLIB_CACHE_LINE_BYTES, VEC_NUMA_UNSPECIFIED);
- /* Round up to a cache line boundary */
- vector_size = (vector_size + CLIB_CACHE_LINE_BYTES - 1)
- & ~(CLIB_CACHE_LINE_BYTES - 1);
-
- free_index_size = (free_index_size + CLIB_CACHE_LINE_BYTES - 1)
- & ~(CLIB_CACHE_LINE_BYTES - 1);
-
- total_size = vector_size + free_index_size;
-
- /* Round up to an even number of pages */
- page_size = clib_mem_get_page_size ();
- total_size = (total_size + page_size - 1) & ~(page_size - 1);
-
- /* mmap demand zero memory */
-
- mmap_base = mmap (0, total_size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-
- if (mmap_base == MAP_FAILED)
- {
- clib_unix_warning ("mmap");
- *pool_ptr = 0;
- }
-
- /* First comes the pool header */
- fh = (pool_header_t *) mmap_base;
- /* Find the user vector pointer */
- v = (u8 *) (mmap_base + vec_header_bytes (pool_aligned_header_bytes));
- /* Finally, the vector header */
- vh = _vec_find (v);
-
- fh->free_bitmap = 0; /* No free elts (yet) */
- fh->max_elts = max_elts;
- fh->mmap_base = mmap_base;
- fh->mmap_size = total_size;
-
- vh->len = max_elts;
+ ph = pool_header (v);
+ ph->max_elts = max_elts;
/* Build the free-index vector */
- vh = (vec_header_t *) ((u8 *) fh + vector_size);
- vh->len = max_elts;
- fi = (u32 *) (vh + 1);
-
- fh->free_indices = fi;
+ vec_validate_aligned (ph->free_indices, max_elts - 1, CLIB_CACHE_LINE_BYTES);
+ for (i = 0; i < max_elts; i++)
+ ph->free_indices[i] = (max_elts - 1) - i;
/* Set the entire free bitmap */
- clib_bitmap_alloc (fh->free_bitmap, max_elts);
- clib_memset (fh->free_bitmap, 0xff,
- vec_len (fh->free_bitmap) * sizeof (uword));
-
- /* Clear any extraneous set bits */
- set_bits = vec_len (fh->free_bitmap) * BITS (uword);
+ clib_bitmap_alloc (ph->free_bitmap, max_elts);
- for (i = max_elts; i < set_bits; i++)
- fh->free_bitmap = clib_bitmap_set (fh->free_bitmap, i, 0);
+ for (b = ph->free_bitmap, i = max_elts; i >= uword_bits;
+ i -= uword_bits, b++)
+ b[0] = ~0ULL;
- /* Create the initial free vector */
- for (i = 0; i < max_elts; i++)
- fi[i] = (max_elts - 1) - i;
+ if (i)
+ b[0] = pow2_mask (i);
*pool_ptr = v;
}
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */