From 2de9c0f92bb486072d8371a24d9b23fd85e1aa80 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Sun, 2 Feb 2020 19:30:39 +0000 Subject: svm: minimal initial fifo Type: refactor Signed-off-by: Florin Coras Change-Id: I4ee46a6c3c53c58199c275e20702f7fd11b60d9a --- src/svm/fifo_segment.c | 15 ++++++++------- src/svm/fifo_types.h | 1 + src/svm/svm_fifo.c | 7 +++---- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/svm') diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c index 88600b84e36..7b1163e0750 100644 --- a/src/svm/fifo_segment.c +++ b/src/svm/fifo_segment.c @@ -294,8 +294,7 @@ fs_chunk_size_is_valid (fifo_segment_header_t * fsh, u32 size) } static svm_fifo_t * -fs_try_alloc_fifo_freelist (fifo_segment_slice_t * fss, - u32 fl_index, u32 data_bytes) +fs_try_alloc_fifo_freelist (fifo_segment_slice_t * fss, u32 fl_index) { svm_fifo_chunk_t *c; svm_fifo_t *f; @@ -471,14 +470,16 @@ fs_try_alloc_fifo (fifo_segment_header_t * fsh, fifo_segment_slice_t * fss, u32 fifo_sz, fl_index; svm_fifo_t *f = 0; uword n_free_bytes; + u32 min_size; - fl_index = fs_freelist_for_size (data_bytes); + min_size = clib_max ((fsh->pct_first_alloc * data_bytes) / 100, 4096); + fl_index = fs_freelist_for_size (min_size); fifo_sz = sizeof (svm_fifo_t) + sizeof (svm_fifo_chunk_t); - fifo_sz += 1 << max_log2 (data_bytes); + fifo_sz += 1 << max_log2 (min_size); if (fss->free_fifos && fss->free_chunks[fl_index]) { - f = fs_try_alloc_fifo_freelist (fss, fl_index, data_bytes); + f = fs_try_alloc_fifo_freelist (fss, fl_index); if (f) { fsh_cached_bytes_sub (fsh, fs_freelist_index_to_size (fl_index)); @@ -494,7 +495,7 @@ fs_try_alloc_fifo (fifo_segment_header_t * fsh, fifo_segment_slice_t * fss, FIFO_SEGMENT_ALLOC_BATCH_SIZE)) goto done; - f = fs_try_alloc_fifo_freelist (fss, fl_index, data_bytes); + f = fs_try_alloc_fifo_freelist (fss, fl_index); if (f) fsh_cached_bytes_sub (fsh, fs_freelist_index_to_size (fl_index)); goto done; @@ -502,7 +503,7 @@ fs_try_alloc_fifo (fifo_segment_header_t * fsh, fifo_segment_slice_t * fss, if (fifo_sz <= n_free_bytes) { void *oldheap = ssvm_push_heap (fsh->ssvm_sh); - f = svm_fifo_alloc (data_bytes); + f = svm_fifo_alloc (min_size); ssvm_pop_heap (oldheap); if (f) { diff --git a/src/svm/fifo_types.h b/src/svm/fifo_types.h index f0a286d46a0..a80130b0e92 100644 --- a/src/svm/fifo_types.h +++ b/src/svm/fifo_types.h @@ -120,6 +120,7 @@ struct fifo_segment_header_ u8 n_slices; /**< Number of slices */ u8 high_watermark; /**< Memory pressure watermark high */ u8 low_watermark; /**< Memory pressure watermark low */ + u8 pct_first_alloc; /**< Pct of fifo size to alloc */ }; #endif /* SRC_SVM_FIFO_TYPES_H_ */ diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c index 0168c08e49c..971eda351d5 100644 --- a/src/svm/svm_fifo.c +++ b/src/svm/svm_fifo.c @@ -368,7 +368,7 @@ void svm_fifo_init (svm_fifo_t * f, u32 size) { svm_fifo_chunk_t *c, *prev; - u32 first_chunk, min_alloc; + u32 min_alloc; f->size = size; f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX; @@ -378,9 +378,8 @@ svm_fifo_init (svm_fifo_t * f, u32 size) f->head_chunk = f->tail_chunk = f->start_chunk; f->ooo_deq = f->ooo_enq = 0; - first_chunk = f->start_chunk->length; - min_alloc = first_chunk > 16 << 10 ? first_chunk >> 2 : 4096; - min_alloc = clib_min (first_chunk, 64 << 10); + min_alloc = size > 32 << 10 ? size >> 3 : 4096; + min_alloc = clib_min (min_alloc, 64 << 10); f->min_alloc = min_alloc; /* -- cgit 1.2.3-korg