aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/memory_shared.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2017-01-09 15:54:00 -0500
committerDave Barach <dave@barachs.net>2017-01-09 15:54:41 -0500
commit842b9c59cc21b3e2917aaa25069fb15addf976f1 (patch)
treedff8bd1e948ac1e311bf8547ee40175b6eeace8e /src/vlibmemory/memory_shared.c
parentd995c757f05f78aa759b0a65c0a7e38088e690a9 (diff)
Self-service garbage collection for the API message allocator
Change-Id: Iadc08eede15fa5978e4010bbece0232aab8b0fee Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vlibmemory/memory_shared.c')
-rw-r--r--src/vlibmemory/memory_shared.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c
index d8d3200485e..c41f32f70f9 100644
--- a/src/vlibmemory/memory_shared.c
+++ b/src/vlibmemory/memory_shared.c
@@ -95,12 +95,31 @@ vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null)
*/
if (rv->q)
{
+ u32 now = (u32) time (0);
+
+ if (PREDICT_TRUE (rv->gc_mark_timestamp == 0))
+ rv->gc_mark_timestamp = now;
+ else
+ {
+ if (now - rv->gc_mark_timestamp > 10)
+ {
+ if (CLIB_DEBUG > 0)
+ clib_warning ("garbage collect pool %d ring %d index %d",
+ pool, i, q->head);
+ shmem_hdr->garbage_collects++;
+ goto collected;
+ }
+ }
+
+
/* yes, loser; try next larger pool */
ap[i].misses++;
if (pool == 0)
pthread_mutex_unlock (&q->mutex);
continue;
}
+ collected:
+
/* OK, we have a winner */
ap[i].hits++;
/*
@@ -108,6 +127,7 @@ vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null)
* don't need to know the queue to free the item.
*/
rv->q = q;
+ rv->gc_mark_timestamp = 0;
q->head++;
if (q->head == q->maxsize)
q->head = 0;
@@ -201,6 +221,7 @@ vl_msg_api_free (void *a)
if (rv->q)
{
rv->q = 0;
+ rv->gc_mark_timestamp = 0;
return;
}