Skip to content

Commit

Permalink
Refs #100984 Merge branch '101049-cache-replacement' into 100984-stra…
Browse files Browse the repository at this point in the history
…tegy-labels
  • Loading branch information
Michael Plass committed Oct 4, 2013
2 parents d196745 + c88dfe3 commit 5a58923
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
52 changes: 32 additions & 20 deletions csrc/ccnd/ccnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ static void strategy_callout(struct ccnd_handle *h,
*/
#define WTHZ 500U

/**
* Allow a few extra entries in the cache to allow for output queuing
*/
#define CACHE_MARGIN 10

/**
* Name of our unix-domain listener
*
Expand Down Expand Up @@ -1700,9 +1705,11 @@ face_send_queue_insert(struct ccnd_handle *h,
{
int ans;
int delay;
int n;
enum cq_delay_class c;
enum cq_delay_class k;
struct content_queue *q;

if (face == NULL || content == NULL || (face->flags & CCN_FACE_NOSEND) != 0)
return(-1);
c = choose_content_delay_class(h, face->faceid, content->flags);
Expand All @@ -1723,8 +1730,10 @@ face_send_queue_insert(struct ccnd_handle *h,
}
}
}
content->refs++;
n = q->send_queue->n;
ans = ccn_indexbuf_set_insert(q->send_queue, content->accession);
if (n != q->send_queue->n)
content->refs++;
if (q->sender == NULL) {
delay = randomize_content_delay(h, q);
q->ready = q->send_queue->n;
Expand Down Expand Up @@ -4494,8 +4503,8 @@ set_content_timer(struct ccnd_handle *h, struct content_entry *content,
int seconds = 0;
size_t start = pco->offset[CCN_PCO_B_FreshnessSeconds];
size_t stop = pco->offset[CCN_PCO_E_FreshnessSeconds];
if (h->force_zero_freshness)
goto Finish;
if (h->capacity == 0)
goto Finish; /* force zero freshness */
if (start == stop)
seconds = h->tts_default;
else
Expand All @@ -4520,24 +4529,32 @@ content_tree_trim(struct ccnd_handle *h) {
struct content_entry *c;
struct content_entry *nextx;

if (h->content_tree->n < h->capacity)
if (h->content_tree->n <= h->capacity)
return;

tries = 30;
for (c = h->headx->nextx; c != h->headx; c = nextx) {
nextx = c->nextx;
if (c->refs == 0 || c->staletime < h->sec - h->starttime) {
if (c->refs == 0) {
remove_content(h, c);
if (h->content_tree->n < h->capacity)
if (h->content_tree->n <= h->capacity)
return;
}
if (--tries <= 0)
else if (!is_stale(h, c)) {
/* add to no new queues so it will drain eventually */
mark_stale(h, c);
if (h->debug & 4)
ccnd_debug_content(h, __LINE__, "force_stale", NULL, c);
break;
}
else if (--tries <= 0)
break;
}
/* we've tried and failed to preserve queued content */
c = h->headx->nextx;
if (c != h->headx)
remove_content(h, c); /* logs remove_queued_content */
if (h->content_tree->n > h->content_tree->limit) {
/* we've tried and failed to preserve queued content */
c = h->headx->nextx;
if (c != h->headx)
remove_content(h, c); /* logs remove_queued_content */
}
}

/**
Expand Down Expand Up @@ -4597,7 +4614,7 @@ process_incoming_content(struct ccnd_handle *h, struct face *face,
}
}
if (h->content_tree->n >= h->content_tree->limit) {
if (h->content_tree->limit < h->capacity)
if (h->content_tree->limit < h->capacity + CACHE_MARGIN)
ccn_nametree_grow(h->content_tree);
}
ccn_flatname_append_from_ccnb(f, msg, size, 0, -1);
Expand Down Expand Up @@ -5801,13 +5818,8 @@ ccnd_create(const char *progname, ccnd_logger logger, void *loggerdata)
h->portstr = portstr;
entrylimit = getenv("CCND_CAP");
h->capacity = (~0U)/2;
if (entrylimit != NULL && entrylimit[0] != 0) {
h->capacity = atol(entrylimit);
if (h->capacity == 0)
h->force_zero_freshness = 1;
if (h->capacity <= 0)
h->capacity = 10;
}
if (entrylimit != NULL && entrylimit[0] != 0)
h->capacity = strtoul(entrylimit, NULL, 10);
ccnd_msg(h, "CCND_DEBUG=%d CCND_CAP=%lu", h->debug, h->capacity);
cap = 100000; /* Don't try to allocate an insanely high number */
cap = h->capacity < cap ? h->capacity : cap;
Expand Down
1 change: 0 additions & 1 deletion csrc/ccnd/ccnd_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ struct ccnd_handle {
int mtu; /**< Target size for stuffing interests */
int flood; /**< Internal control for auto-reg */
struct ccn_charbuf *autoreg; /**< URIs to auto-register */
int force_zero_freshness; /**< Simulate freshness=0 on all content */
unsigned interest_faceid; /**< for self_reg internal client */
const char *progname; /**< our name, for locating helpers */
struct ccn *internal_client; /**< internal client */
Expand Down

0 comments on commit 5a58923

Please sign in to comment.