[master] 1bda658 Hide the hash preallocation in cache_hash.c again, by tasking persistent with allocating its own objcores.

Poul-Henning Kamp phk at varnish-cache.org
Sun Feb 19 12:41:37 CET 2012


commit 1bda6584df023d47c6a6715089310c72b3ba2ccf
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sun Feb 19 11:41:08 2012 +0000

    Hide the hash preallocation in cache_hash.c again, by tasking persistent
    with allocating its own objcores.

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index eff6357..ce596df 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -65,17 +65,14 @@ static const struct hash_slinger *hash;
 
 /*---------------------------------------------------------------------*/
 /* Precreate an objhead and object for later use */
-void
-HSH_Prealloc(const struct sess *sp)
+static void
+hsh_prealloc(struct worker *wrk)
 {
-	struct worker *wrk;
 	struct objhead *oh;
 	struct objcore *oc;
 	struct waitinglist *wl;
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
-	wrk = sp->wrk;
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
 	if (wrk->nobjcore == NULL) {
 		ALLOC_OBJ(oc, OBJCORE_MAGIC);
@@ -107,7 +104,7 @@ HSH_Prealloc(const struct sess *sp)
 	CHECK_OBJ_NOTNULL(wrk->nwaitinglist, WAITINGLIST_MAGIC);
 
 	if (hash->prep != NULL)
-		hash->prep(sp);
+		hash->prep(wrk);
 }
 
 void
@@ -247,24 +244,26 @@ hsh_testmagic(void *result)
  * Return it with a reference held.
  */
 
-struct objcore *
-HSH_Insert(const struct sess *sp)
+void
+HSH_Insert(const struct sess *sp, const void *digest, struct objcore *oc)
 {
 	struct worker *wrk;
 	struct objhead *oh;
-	struct objcore *oc;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
-	AN(hash);
+	AN(digest);
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+
 	wrk = sp->wrk;
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
-	HSH_Prealloc(sp);
+	hsh_prealloc(wrk);
 	if (cache_param->diag_bitmap & 0x80000000)
-		hsh_testmagic(sp->wrk->nobjhead->digest);
+		hsh_testmagic(wrk->nobjhead->digest);
 
 	AZ(sp->req);
 	AN(wrk->nobjhead);
+	memcpy(wrk->nobjhead->digest, digest, SHA256_LEN);
 	oh = hash->lookup(sp, wrk->nobjhead);
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 	if (oh == wrk->nobjhead)
@@ -273,8 +272,6 @@ HSH_Insert(const struct sess *sp)
 	assert(oh->refcnt > 0);
 
 	/* Insert (precreated) objcore in objecthead */
-	oc = wrk->nobjcore;
-	wrk->nobjcore = NULL;
 	oc->refcnt = 1;
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	AZ(oc->flags & OC_F_BUSY);
@@ -283,8 +280,8 @@ HSH_Insert(const struct sess *sp)
 	/* NB: do not deref objhead the new object inherits our reference */
 	oc->objhead = oh;
 	Lck_Unlock(&oh->mtx);
-	sp->wrk->stats.n_vampireobject++;
-	return (oc);
+	wrk->stats.n_objectcore++;
+	wrk->stats.n_vampireobject++;
 }
 
 /*---------------------------------------------------------------------
@@ -307,7 +304,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
 	AN(hash);
 	wrk = sp->wrk;
 
-	HSH_Prealloc(sp);
+	hsh_prealloc(wrk);
 	memcpy(sp->wrk->nobjhead->digest, sp->req->digest,
 	    sizeof sp->req->digest);
 	if (cache_param->diag_bitmap & 0x80000000)
diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt
index 97ff04a..0c9f5d0 100644
--- a/bin/varnishd/flint.lnt
+++ b/bin/varnishd/flint.lnt
@@ -116,6 +116,7 @@
 
 -emacro(527, NEEDLESS_RETURN)	// unreachable code
 
+-sem(EXP_Inject, custodial(1))
 -sem(WS_Init, custodial(2))
 -sem(http_Setup, custodial(2))
 
diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index 069a1c2..fbdc906 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -469,13 +469,14 @@ hcb_lookup(const struct sess *sp, struct objhead *noh)
 }
 
 static void
-hcb_prep(const struct sess *sp)
+hcb_prep(struct worker *wrk)
 {
 	struct hcb_y *y;
 
-	if (sp->wrk->nhashpriv == NULL) {
+	if (wrk->nhashpriv == NULL) {
 		ALLOC_OBJ(y, HCB_Y_MAGIC);
-		sp->wrk->nhashpriv = y;
+		AN(y);
+		wrk->nhashpriv = y;
 	}
 }
 
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index f2b41e2..9add938 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -34,7 +34,7 @@ struct object;
 
 typedef void hash_init_f(int ac, char * const *av);
 typedef void hash_start_f(void);
-typedef void hash_prep_f(const struct sess *sp);
+typedef void hash_prep_f(struct worker *);
 typedef struct objhead *
     hash_lookup_f(const struct sess *sp, struct objhead *nobj);
 typedef int hash_deref_f(struct objhead *obj);
@@ -51,7 +51,6 @@ struct hash_slinger {
 };
 
 /* cache_hash.c */
-void HSH_Prealloc(const struct sess *sp);
 void HSH_Cleanup(struct worker *w);
 struct objcore *HSH_Lookup(struct sess *sp, struct objhead **poh);
 void HSH_Unbusy(struct objcore *);
@@ -59,7 +58,7 @@ void HSH_Ref(struct objcore *o);
 void HSH_Drop(struct worker *, struct object **);
 void HSH_Init(const struct hash_slinger *slinger);
 void HSH_AddString(const struct sess *sp, const char *str);
-struct objcore *HSH_Insert(const struct sess *sp);
+void HSH_Insert(const struct sess *sp, const void *hash, struct objcore *);
 void HSH_Purge(const struct sess *, struct objhead *, double ttl, double grace);
 void HSH_config(const char *h_arg);
 
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index a6a02e6..4d6fd9a 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -150,15 +150,13 @@ smp_load_seg(const struct sess *sp, const struct smp_sc *sc,
 	for (;no > 0; so++,no--) {
 		if (so->ttl == 0 || so->ttl < t_now)
 			continue;
-		HSH_Prealloc(sp);
-		oc = sp->wrk->nobjcore;
+		ALLOC_OBJ(oc, OBJCORE_MAGIC);
+		AN(oc);
 		oc->flags |= OC_F_NEEDFIXUP | OC_F_LRUDONTMOVE;
 		oc->flags &= ~OC_F_BUSY;
 		smp_init_oc(oc, sg, no);
 		oc->ban = BAN_RefBan(oc, so->ban, sc->tailban);
-		memcpy(sp->wrk->nobjhead->digest, so->hash, SHA256_LEN);
-		(void)HSH_Insert(sp);
-		AZ(sp->wrk->nobjcore);
+		HSH_Insert(sp, so->hash, oc);
 		EXP_Inject(oc, sg->lru, so->ttl);
 		sg->nobj++;
 	}



More information about the varnish-commit mailing list