summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/fifo_segment.c30
-rw-r--r--src/svm/fifo_types.h2
2 files changed, 14 insertions, 18 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);
}
diff --git a/src/svm/fifo_types.h b/src/svm/fifo_types.h
index 7b844f00bfe..a1b57748e09 100644
--- a/src/svm/fifo_types.h
+++ b/src/svm/fifo_types.h
@@ -109,7 +109,7 @@ typedef struct _svm_fifo
struct _svm_fifo *next; /**< prev in active chain */
struct _svm_fifo *prev; /**< prev in active chain */
- svm_fifo_chunk_t **chunks_at_attach; /**< chunks to be accounted at detach */
+ svm_fifo_chunk_t *chunks_at_attach; /**< chunks to be accounted at detach */
#if SVM_FIFO_TRACE
svm_fifo_trace_elem_t *trace;