[master] 8c113ff Make sure that the ban-lurker cleans the tail at least once every 10 loops. Simplify the structure of the code some more.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Dec 3 10:12:56 CET 2012
commit 8c113ff64b78554f6219f14774fed418c466318c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Dec 3 09:12:21 2012 +0000
Make sure that the ban-lurker cleans the tail at least once every
10 loops. Simplify the structure of the code some more.
Prodded by: martin
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 688842b..985057f 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -818,25 +818,30 @@ BAN_CheckObject(struct object *o, struct req *req)
return (ban_check_object(o, req->vsl, req->http) > 0);
}
-static struct ban *
-ban_CheckLast(void)
+static void
+ban_cleantail(void)
{
struct ban *b;
- Lck_AssertHeld(&ban_mtx);
- b = VTAILQ_LAST(&ban_head, banhead_s);
- if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
- if (b->flags & BAN_F_GONE)
- VSC_C_main->bans_gone--;
- if (b->flags & BAN_F_REQ)
- VSC_C_main->bans_req--;
- VSC_C_main->bans--;
- VSC_C_main->bans_deleted++;
- VTAILQ_REMOVE(&ban_head, b, list);
- } else {
- b = NULL;
- }
- return (b);
+ do {
+ Lck_Lock(&ban_mtx);
+ b = VTAILQ_LAST(&ban_head, banhead_s);
+ if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
+ if (b->flags & BAN_F_GONE)
+ VSC_C_main->bans_gone--;
+ if (b->flags & BAN_F_REQ)
+ VSC_C_main->bans_req--;
+ VSC_C_main->bans--;
+ VSC_C_main->bans_deleted++;
+ VTAILQ_REMOVE(&ban_head, b, list);
+ STV_BanInfo(BI_DROP, b->spec, ban_len(b->spec));
+ } else {
+ b = NULL;
+ }
+ Lck_Unlock(&ban_mtx);
+ if (b != NULL)
+ BAN_Free(b);
+ } while (b != NULL);
}
/*--------------------------------------------------------------------
@@ -983,41 +988,29 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl)
static void * __match_proto__(bgthread_t)
ban_lurker(struct worker *wrk, void *priv)
{
- struct ban *bf;
struct vsl_log vsl;
+ volatile double d;
+ int i = 0, n = 0;
- int i = 0;
VSL_Setup(&vsl, NULL, 0);
(void)priv;
while (1) {
-
- do {
- /*
- * Ban-lurker is disabled:
- * Clean the last ban, if possible, and sleep
- */
- Lck_Lock(&ban_mtx);
- bf = ban_CheckLast();
- if (bf != NULL)
- /* Notify stevedores */
- STV_BanInfo(BI_DROP, bf->spec,
- ban_len(bf->spec));
- Lck_Unlock(&ban_mtx);
- if (bf != NULL)
- BAN_Free(bf);
- } while (bf != NULL);
-
- if (cache_param->ban_lurker_sleep != 0.0) {
- do {
- i = ban_lurker_work(wrk, &vsl);
- VSL_Flush(&vsl, 0);
- WRK_SumStat(wrk);
- if (i)
- VTIM_sleep(
- cache_param->ban_lurker_sleep);
- } while (i);
+ d = cache_param->ban_lurker_sleep;
+ if (d > 0.0) {
+ i = ban_lurker_work(wrk, &vsl);
+ VSL_Flush(&vsl, 0);
+ WRK_SumStat(wrk);
+ if (i) {
+ VTIM_sleep(d);
+ if (++n > 10) {
+ ban_cleantail();
+ n = 0;
+ }
+ continue;
+ }
}
+ ban_cleantail();
VTIM_sleep(0.609); // Random, non-magic
}
NEEDLESS_RETURN(NULL);
More information about the varnish-commit
mailing list