+static void
+allocate_new_fifo_chunk (svm_fifo_segment_header_t * fsh,
+ u32 data_size_in_bytes, int chunk_size)
+{
+ int freelist_index;
+ u32 size;
+ u8 *fifo_space;
+ u32 rounded_data_size;
+ svm_fifo_t *f;
+ int i;
+
+ rounded_data_size = (1 << (max_log2 (data_size_in_bytes)));
+ freelist_index = max_log2 (rounded_data_size)
+ - max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE);
+
+ /* Calculate space requirement $$$ round-up data_size_in_bytes */
+ size = (sizeof (*f) + rounded_data_size) * chunk_size;
+
+ /* Allocate fifo space. May fail. */
+ fifo_space = clib_mem_alloc_aligned_at_offset
+ (size, CLIB_CACHE_LINE_BYTES, 0 /* align_offset */ ,
+ 0 /* os_out_of_memory */ );
+
+ /* Out of space.. */
+ if (fifo_space == 0)
+ return;
+
+ /* Carve fifo space */
+ f = (svm_fifo_t *) fifo_space;
+ for (i = 0; i < chunk_size; i++)
+ {
+ f->freelist_index = freelist_index;
+ f->next = fsh->free_fifos[freelist_index];
+ fsh->free_fifos[freelist_index] = f;
+ fifo_space += sizeof (*f) + rounded_data_size;
+ f = (svm_fifo_t *) fifo_space;
+ }
+}
+