+svm_fifo_chunk_t *
+fs_try_alloc_multi_chunk (fifo_segment_header_t * fsh,
+ fifo_segment_slice_t * fss, u32 data_bytes)
+{
+ u32 fl_index, fl_size, n_alloc = 0, req_bytes = data_bytes;
+ svm_fifo_chunk_t *c, *first = 0, *next;
+
+ fl_index = fs_freelist_for_size (req_bytes);
+ if (fl_index > 0)
+ fl_index -= 1;
+
+ fl_size = fs_freelist_index_to_size (fl_index);
+
+ while (req_bytes)
+ {
+ c = fss->free_chunks[fl_index];
+ if (c)
+ {
+ fss->free_chunks[fl_index] = c->next;
+ c->next = first;
+ first = c;
+ n_alloc += fl_size;
+ req_bytes -= clib_min (fl_size, req_bytes);
+ }
+ else
+ {
+ /* Failed to allocate with smaller chunks */
+ if (fl_index == 0)
+ {
+ /* free all chunks if any allocated */
+ c = first;
+ while (c)
+ {
+ fl_index = fs_freelist_for_size (c->length);
+ fl_size = fs_freelist_index_to_size (fl_index);
+ next = c->next;
+ c->next = fss->free_chunks[fl_index];
+ fss->free_chunks[fl_index] = c;
+ fss->n_fl_chunk_bytes += fl_size;
+ c = next;
+ }
+ n_alloc = 0;
+ first = 0;
+ fl_index = fs_freelist_for_size (data_bytes);
+ if (fss->free_chunks[fl_index + 1])
+ {
+ fl_index += 1;
+ fl_size = fs_freelist_index_to_size (fl_index);
+ continue;
+ }
+
+ return 0;
+ }
+ fl_index -= 1;
+ fl_size = fl_size >> 1;
+ }
+ }
+
+ fss->n_fl_chunk_bytes -= n_alloc;
+ fsh_cached_bytes_sub (fsh, n_alloc);
+ return first;
+}
+