From fb52edfef2b23d118f7ee8a63363c22868638260 Mon Sep 17 00:00:00 2001 From: des Date: Fri, 20 Jul 2007 09:44:21 +0000 Subject: [PATCH] Additional style cleanup; remove stevedore list from heritage; revert locking, which introduces a choke point. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1732 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 2 - varnish-cache/bin/varnishd/cache_fetch.c | 1 + varnish-cache/bin/varnishd/cache_hash.c | 3 +- varnish-cache/bin/varnishd/cache_main.c | 7 ++-- varnish-cache/bin/varnishd/cache_response.c | 1 - varnish-cache/bin/varnishd/cache_synthetic.c | 4 +- varnish-cache/bin/varnishd/heritage.h | 5 --- varnish-cache/bin/varnishd/mgt.h | 6 --- varnish-cache/bin/varnishd/stevedore.c | 44 +++++++++----------- varnish-cache/bin/varnishd/storage_file.c | 2 + varnish-cache/bin/varnishd/storage_malloc.c | 1 + varnish-cache/bin/varnishd/varnishd.c | 10 ++--- 12 files changed, 36 insertions(+), 50 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 8f180007..84df1e2c 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -214,8 +214,6 @@ struct storage { off_t where; }; -#include "stevedore.h" - /* -------------------------------------------------------------------*/ struct object { diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 2f2021f5..3a17701f 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -44,6 +44,7 @@ #include "shmlog.h" #include "cache.h" #include "heritage.h" +#include "stevedore.h" /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index f0be07f8..502f10f5 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -59,8 +59,9 @@ #include #include "shmlog.h" -#include "heritage.h" #include "cache.h" +#include "heritage.h" +#include "stevedore.h" static struct hash_slinger *hash; diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index 4f47b8e1..327a74fd 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -34,10 +34,10 @@ #include #include -#include "heritage.h" #include "shmlog.h" #include "cache.h" - +#include "heritage.h" +#include "stevedore.h" /*-------------------------------------------------------------------- * XXX: Think more about which order we start things @@ -46,6 +46,7 @@ void child_main(void) { + setbuf(stdout, NULL); setbuf(stderr, NULL); printf("Child starts\n"); @@ -65,7 +66,7 @@ child_main(void) BAN_Init(); STV_open(); - + printf("Ready\n"); VSL_stats->start_time = (time_t)TIM_real(); diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index e765be18..e88d2138 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -151,7 +151,6 @@ RES_WriteObj(struct sess *sp) TAILQ_FOREACH(st, &sp->obj->store, list) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); - AN(st->stevedore); u += st->len; sp->wrk->acct.bodybytes += st->len; #ifdef HAVE_SENDFILE diff --git a/varnish-cache/bin/varnishd/cache_synthetic.c b/varnish-cache/bin/varnishd/cache_synthetic.c index 28ded215..390895ea 100644 --- a/varnish-cache/bin/varnishd/cache_synthetic.c +++ b/varnish-cache/bin/varnishd/cache_synthetic.c @@ -34,8 +34,9 @@ #include #include "shmlog.h" -#include "heritage.h" #include "cache.h" +#include "heritage.h" +#include "stevedore.h" /* * Synthesize an error page. This assumes the session already has an @@ -87,7 +88,6 @@ SYN_ErrorPage(struct sess *sp, int status, const char *reason, int ttl) /* allocate space for body */ /* XXX what if the object already has a body? */ st = STV_alloc(1024); - XXXAN(st->stevedore); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); /* generate body */ diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 249224a4..a30e607e 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -41,7 +41,6 @@ struct listen_sock { }; TAILQ_HEAD(listen_sock_head, listen_sock); -TAILQ_HEAD(stevedore_head, stevedore); struct heritage { @@ -59,10 +58,6 @@ struct heritage { int vsl_fd; unsigned vsl_size; - /* Storage method */ - struct stevedore_head stevedore_h; - pthread_mutex_t stevedore_lock; - /* Hash method */ struct hash_slinger *hash; diff --git a/varnish-cache/bin/varnishd/mgt.h b/varnish-cache/bin/varnishd/mgt.h index 20c820b4..afd8fb4c 100644 --- a/varnish-cache/bin/varnishd/mgt.h +++ b/varnish-cache/bin/varnishd/mgt.h @@ -61,13 +61,7 @@ void mgt_vcc_init(void); int mgt_vcc_default(const char *bflag, const char *fflag, int f_fd, int Cflag); int mgt_push_vcls_and_start(unsigned *status, char **p); -#include "stevedore.h" - -extern struct stevedore sma_stevedore; -extern struct stevedore smf_stevedore; - #include "hash_slinger.h" extern struct hash_slinger hsl_slinger; extern struct hash_slinger hcl_slinger; - diff --git a/varnish-cache/bin/varnishd/stevedore.c b/varnish-cache/bin/varnishd/stevedore.c index 9e597b38..b018e3f1 100644 --- a/varnish-cache/bin/varnishd/stevedore.c +++ b/varnish-cache/bin/varnishd/stevedore.c @@ -34,46 +34,43 @@ #include "cache.h" #include "heritage.h" +#include "stevedore.h" extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; +static TAILQ_HEAD(stevedore_head, stevedore) stevedores; struct storage * STV_alloc(size_t size) { struct storage *st; struct stevedore *stv, *stv_first; - struct stevedore_head *stevedore_h = &heritage.stevedore_h; /* Simple round robin selecting of a stevedore. */ - pthread_mutex_lock(&heritage.stevedore_lock); - stv_first = TAILQ_FIRST(stevedore_h); + stv_first = TAILQ_FIRST(&stevedores); stv = stv_first; do { AN(stv->alloc); st = stv->alloc(stv, size); - TAILQ_REMOVE(stevedore_h, stv, stevedore_list); - TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); - if (st != NULL) { - pthread_mutex_unlock(&heritage.stevedore_lock); + TAILQ_REMOVE(&stevedores, stv, stevedore_list); + TAILQ_INSERT_TAIL(&stevedores, stv, stevedore_list); + if (st != NULL) return (st); - } - } while ((stv = TAILQ_FIRST(stevedore_h)) != stv_first); - + } while ((stv = TAILQ_FIRST(&stevedores)) != stv_first); + /* No stevedore with enough space is found. Make room in the first * one in the list, and move it to the end. Ensuring the round-robin. */ - stv = TAILQ_FIRST(stevedore_h); - TAILQ_REMOVE(stevedore_h, stv, stevedore_list); - TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); - pthread_mutex_unlock(&heritage.stevedore_lock); - + stv = TAILQ_FIRST(&stevedores); + TAILQ_REMOVE(&stevedores, stv, stevedore_list); + TAILQ_INSERT_TAIL(&stevedores, stv, stevedore_list); + do { if ((st = stv->alloc(stv, size)) == NULL) AN(LRU_DiscardOne()); } while (st == NULL); - + return (st); } @@ -118,9 +115,9 @@ STV_add(const char *spec) q = p + 1; xxxassert(p != NULL); xxxassert(q != NULL); - + stp = malloc(sizeof *stp); - + if (!cmp_storage(&sma_stevedore, spec, p)) { *stp = sma_stevedore; } else if (!cmp_storage(&smf_stevedore, spec, p)) { @@ -130,21 +127,18 @@ STV_add(const char *spec) (int)(p - spec), spec); exit (2); } - TAILQ_INSERT_HEAD(&heritage.stevedore_h, stp, stevedore_list); + TAILQ_INSERT_HEAD(&stevedores, stp, stevedore_list); if (stp->init != NULL) stp->init(stp, q); } -void +void STV_open(void) { - struct stevedore_head *stevedore_h; struct stevedore *st; - - stevedore_h = &heritage.stevedore_h; - TAILQ_FOREACH(st, stevedore_h, stevedore_list) { + + TAILQ_FOREACH(st, &stevedores, stevedore_list) { if (st->open != NULL) st->open(st); } - pthread_mutex_init(&heritage.stevedore_lock, NULL); } diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index 8b8da7da..344a5e4e 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -57,8 +57,10 @@ #ifndef HAVE_ASPRINTF #include "compat/asprintf.h" #endif + #include "shmlog.h" #include "cache.h" +#include "stevedore.h" #ifndef MAP_NOCORE #define MAP_NOCORE 0 /* XXX Linux */ diff --git a/varnish-cache/bin/varnishd/storage_malloc.c b/varnish-cache/bin/varnishd/storage_malloc.c index e7a2fbb4..6f62fd4f 100644 --- a/varnish-cache/bin/varnishd/storage_malloc.c +++ b/varnish-cache/bin/varnishd/storage_malloc.c @@ -37,6 +37,7 @@ #include "shmlog.h" #include "cache.h" +#include "stevedore.h" struct sma { struct storage s; diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index f9fc09ed..343478a7 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -61,9 +61,10 @@ #include "cli_priv.h" #include "cli_common.h" -#include "mgt.h" -#include "heritage.h" #include "shmlog.h" +#include "heritage.h" +#include "mgt.h" +#include "stevedore.h" /* INFTIM indicates an infinite timeout for poll(2) */ #ifndef INFTIM @@ -392,8 +393,7 @@ main(int argc, char *argv[]) cli[0].result = CLIS_OK; TAILQ_INIT(&heritage.socks); - TAILQ_INIT(&heritage.stevedore_h); - + mgt_vcc_init(); MCF_ParamInit(cli); @@ -536,7 +536,7 @@ main(int argc, char *argv[]) if (!s_arg_given) STV_add(s_arg); - + setup_hash(h_arg); VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024); -- 2.39.5