svm: only try to pre-allocate requested number of fifo pairs 36/30136/4
authorBenoît Ganne <bganne@cisco.com>
Wed, 25 Nov 2020 14:06:01 +0000 (15:06 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 26 Nov 2020 17:45:36 +0000 (17:45 +0000)
Type: fix

Change-Id: I6f7679fd48d0ed98677c58f8c08d7e969e8e8220
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/svm/fifo_segment.c

index 815c5a2..00e51cf 100644 (file)
@@ -485,6 +485,8 @@ fsh_try_alloc_fifo_hdr_batch (fifo_segment_header_t * fsh,
   u8 *fmem;
   int i;
 
+  ASSERT (batch_size != 0);
+
   size = (uword) sizeof (*f) * batch_size;
 
   oldheap = ssvm_push_heap (fsh->ssvm_sh);
@@ -522,6 +524,8 @@ fsh_try_alloc_chunk_batch (fifo_segment_header_t * fsh,
   u8 *cmem;
   int i;
 
+  ASSERT (batch_size != 0);
+
   rounded_data_size = fs_freelist_index_to_size (fl_index);
   total_chunk_bytes = (uword) batch_size *rounded_data_size;
   size = (uword) (sizeof (*c) + rounded_data_size) * batch_size;
@@ -986,8 +990,11 @@ fifo_segment_preallocate_fifo_pairs (fifo_segment_t * fs,
 
   for (i = 0; i < fs->n_slices; i++)
     {
-      fss = fsh_slice_get (fsh, i);
       alloc_now = clib_min (pairs_per_slice, *n_fifo_pairs);
+      if (0 == alloc_now)
+       break;
+
+      fss = fsh_slice_get (fsh, i);
       if (fs_try_alloc_fifo_batch (fsh, fss, rx_fl_index, alloc_now))
        clib_warning ("rx prealloc failed: pairs %u", alloc_now);
       if (fs_try_alloc_fifo_batch (fsh, fss, tx_fl_index, alloc_now))