summaryrefslogtreecommitdiffstats
path: root/src/svm/fifo_segment.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2021-02-18 21:35:23 -0800
committerDave Barach <openvpp@barachs.net>2021-02-20 19:10:59 +0000
commit255554fd7e75a803569e311c28e8ec8da8e7a286 (patch)
tree19bf870118c48b174482fb82090b4eaa701e11d1 /src/svm/fifo_segment.c
parent7f8d1746783384a08d7e219d7669b8ed54446c37 (diff)
svm: return chunks to slice on fifo detach
Ensure chunk alloc distribution is maintained on fifo detach. Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I5aa5524e06a703dc50e90da6d177663d2d997aa4
Diffstat (limited to 'src/svm/fifo_segment.c')
-rw-r--r--src/svm/fifo_segment.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index f23b2dbbf71..e3e6caaa6cc 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -942,9 +942,8 @@ fifo_segment_detach_fifo (fifo_segment_t *fs, svm_fifo_t **f)
{
fifo_slice_private_t *pfss;
fifo_segment_slice_t *fss;
- u32 fl_index, slice_index;
- svm_fifo_chunk_t **c;
svm_fifo_t *of = *f;
+ u32 slice_index;
slice_index = of->master_thread_index;
fss = fsh_slice_get (fs->h, slice_index);
@@ -953,13 +952,9 @@ fifo_segment_detach_fifo (fifo_segment_t *fs, svm_fifo_t **f)
if (of->flags & SVM_FIFO_F_LL_TRACKED)
pfss_fifo_del_active_list (pfss, of);
- /* Update slice counts for chunks that were detached */
- vec_foreach (c, of->chunks_at_attach)
- {
- fl_index = fs_freelist_for_size ((*c)->length);
- clib_atomic_fetch_sub_rel (&fss->num_chunks[fl_index], 1);
- }
- vec_free (of->chunks_at_attach);
+ /* Collect chunks that were provided in return for those detached */
+ fsh_slice_collect_chunks (fs->h, fss, of->chunks_at_attach);
+ of->chunks_at_attach = 0;
clib_mem_bulk_free (pfss->fifos, *f);
*f = 0;
@@ -968,11 +963,10 @@ fifo_segment_detach_fifo (fifo_segment_t *fs, svm_fifo_t **f)
void
fifo_segment_attach_fifo (fifo_segment_t *fs, svm_fifo_t **f, u32 slice_index)
{
+ svm_fifo_chunk_t *c, *nc, *pc = 0;
fifo_slice_private_t *pfss;
fifo_segment_slice_t *fss;
- svm_fifo_chunk_t *c;
svm_fifo_t *nf, *of;
- u32 fl_index;
nf = fs_fifo_alloc (fs, slice_index);
clib_memcpy_fast (nf, *f, sizeof (*nf));
@@ -984,17 +978,19 @@ fifo_segment_attach_fifo (fifo_segment_t *fs, svm_fifo_t **f, u32 slice_index)
if (nf->flags & SVM_FIFO_F_LL_TRACKED)
pfss_fifo_add_active_list (pfss, nf);
- /* Update allocated chunks for fifo segment and build list
- * of chunks to be freed at detach */
+ /* Update allocated chunks for fifo segment and build list of
+ * chunks to be freed, i.e, returned to old slice at detach */
of = *f;
- of->chunks_at_attach = 0;
c = fs_chunk_ptr (fs->h, nf->shr->start_chunk);
+ of->chunks_at_attach = pc = fsh_try_alloc_chunk (fs->h, fss, c->length);
+ c = fs_chunk_ptr (fs->h, c->next);
+
while (c)
{
- fl_index = fs_freelist_for_size (c->length);
- clib_atomic_fetch_add_rel (&fss->num_chunks[fl_index], 1);
- vec_add1 (of->chunks_at_attach, c);
+ nc = fsh_try_alloc_chunk (fs->h, fss, c->length);
+ pc->next = fs_chunk_sptr (fs->h, nc);
+ pc = nc;
c = fs_chunk_ptr (fs->h, c->next);
}