+ fsh_active_fifos_update (fsh, -1);
+}
+
+int
+fifo_segment_prealloc_fifo_hdrs (fifo_segment_t * fs, u32 slice_index,
+ u32 batch_size)
+{
+ fifo_segment_header_t *fsh = fs->h;
+ fifo_segment_slice_t *fss;
+ svm_fifo_t *f;
+ void *oldheap;
+ uword size;
+ u8 *fmem;
+ int i;
+
+ fss = fsh_slice_get (fsh, slice_index);
+ size = (uword) (sizeof (*f)) * batch_size;
+
+ oldheap = ssvm_push_heap (fsh->ssvm_sh);
+ fmem = clib_mem_alloc_aligned_at_offset (size, CLIB_CACHE_LINE_BYTES,
+ 0 /* align_offset */ ,
+ 0 /* os_out_of_memory */ );
+ ssvm_pop_heap (oldheap);
+
+ /* Out of space.. */
+ if (fmem == 0)
+ return -1;
+
+ /* Carve fifo + chunk space */
+ for (i = 0; i < batch_size; i++)
+ {
+ f = (svm_fifo_t *) fmem;
+ memset (f, 0, sizeof (*f));
+ f->next = fss->free_fifos;
+ fss->free_fifos = f;
+ fmem += sizeof (*f);
+ }
+
+ fsh_free_bytes_sub (fsh, size);
+
+ return 0;
+}
+
+int
+fifo_segment_prealloc_fifo_chunks (fifo_segment_t * fs, u32 slice_index,
+ u32 chunk_size, u32 batch_size)
+{
+ fifo_segment_header_t *fsh = fs->h;
+ u32 rounded_data_size, fl_index;
+ fifo_segment_slice_t *fss;
+ svm_fifo_chunk_t *c;
+ void *oldheap;
+ uword size;
+ u8 *cmem;
+ int i;
+
+ if (!fs_chunk_size_is_valid (fsh, chunk_size))
+ {
+ clib_warning ("chunk size out of range %d", chunk_size);
+ return -1;
+ }
+
+ fl_index = fs_freelist_for_size (chunk_size);
+ rounded_data_size = fs_freelist_index_to_size (fl_index);
+ size = (uword) (sizeof (*c) + rounded_data_size) * batch_size;
+
+ oldheap = ssvm_push_heap (fsh->ssvm_sh);
+ cmem = clib_mem_alloc_aligned_at_offset (size, CLIB_CACHE_LINE_BYTES,
+ 0 /* align_offset */ ,
+ 0 /* os_out_of_memory */ );
+ ssvm_pop_heap (oldheap);
+
+ /* Out of space.. */
+ if (cmem == 0)
+ return -1;
+
+ fss = fsh_slice_get (fsh, slice_index);
+
+ /* Carve fifo + chunk space */
+ for (i = 0; i < batch_size; i++)
+ {
+ c = (svm_fifo_chunk_t *) cmem;
+ c->start_byte = 0;
+ c->length = rounded_data_size;
+ c->next = fss->free_chunks[fl_index];
+ fss->free_chunks[fl_index] = c;
+ cmem += sizeof (*c) + rounded_data_size;
+ }
+
+ fss->n_fl_chunk_bytes += batch_size * rounded_data_size;
+ fsh_free_bytes_sub (fsh, size);
+
+ return 0;