span class="p">(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 + 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; /* Build the free-index vector */ vh = (vec_header_t *) (v + vector_size); vh->len = max_elts; fi = (u32 *) (vh + 1); fh->free_indices = fi; /* 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); for (i = max_elts; i < set_bits; i++) fh->free_bitmap = clib_bitmap_set (fh->free_bitmap, i, 0); /* Create the initial free vector */ for (i = 0; i < max_elts; i++) fi[i] = (max_elts - 1) - i; *pool_ptr = v; } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */