[master] 4410846 Centralize objcore and boc create/destroy.

Poul-Henning Kamp phk at FreeBSD.org
Fri Feb 26 22:55:23 CET 2016


commit 44108468b65654f894a1a39634dc7f0ba2b95e31
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Feb 26 21:54:39 2016 +0000

    Centralize objcore and boc create/destroy.
    
    Rename ObjStable() to ObjBocDone() which is more precise.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 08eaa2d..fc3ff5e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -859,6 +859,7 @@ void MPL_Free(struct mempool *mpl, void *item);
 
 /* cache_obj.c */
 struct objcore * ObjNew(struct worker *);
+void ObjDestroy(struct worker *, struct objcore **);
 typedef int objiterate_f(void *priv, int flush, const void *ptr, ssize_t len);
 int ObjIterate(struct worker *, struct objcore *,
     void *priv, objiterate_f *func);
@@ -882,7 +883,7 @@ void *ObjSetAttr(struct worker *, struct objcore *, enum obj_attr,
     ssize_t len, const void *);
 int ObjCopyAttr(struct worker *, struct objcore *, struct objcore *,
     enum obj_attr attr);
-void ObjStable(struct worker *, struct objcore *, struct boc *);
+void ObjBocDone(struct worker *, struct objcore *, struct boc **);
 
 int ObjSetDouble(struct worker *, struct objcore *, enum obj_attr, double);
 int ObjSetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 86523be..f952769 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -91,10 +91,8 @@ hsh_prealloc(struct worker *wrk)
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
-	if (wrk->nobjcore == NULL) {
+	if (wrk->nobjcore == NULL)
 		wrk->nobjcore = ObjNew(wrk);
-		wrk->nobjcore->flags |= OC_F_BUSY;
-	}
 	CHECK_OBJ_NOTNULL(wrk->nobjcore, OBJCORE_MAGIC);
 
 	if (wrk->nobjhead == NULL) {
@@ -120,7 +118,7 @@ HSH_Private(struct worker *wrk)
 	AN(oc);
 	oc->refcnt = 1;
 	oc->objhead = private_oh;
-	oc->flags |= OC_F_PRIVATE | OC_F_BUSY;
+	oc->flags |= OC_F_PRIVATE;
 	Lck_Lock(&private_oh->mtx);
 	VTAILQ_INSERT_TAIL(&private_oh->objcs, oc, hsh_list);
 	private_oh->refcnt++;
@@ -133,11 +131,9 @@ void
 HSH_Cleanup(struct worker *wrk)
 {
 
-	if (wrk->nobjcore != NULL) {
-		FREE_OBJ(wrk->nobjcore);
-		wrk->stats->n_objectcore--;
-		wrk->nobjcore = NULL;
-	}
+	if (wrk->nobjcore != NULL)
+		ObjDestroy(wrk, &wrk->nobjcore);
+
 	if (wrk->nobjhead != NULL) {
 		Lck_Delete(&wrk->nobjhead->mtx);
 		FREE_OBJ(wrk->nobjhead);
@@ -798,14 +794,8 @@ HSH_DerefBoc(struct worker *wrk, struct objcore *oc)
 	if (r == 0)
 		oc->boc = NULL;
 	Lck_Unlock(&oc->objhead->mtx);
-	if (r == 0) {
-		if (oc->stobj->stevedore != NULL)
-			ObjStable(wrk, oc, boc);
-		AZ(pthread_cond_destroy(&boc->cond));
-		Lck_Delete(&boc->mtx);
-		free(boc->vary);
-		FREE_OBJ(boc);
-	}
+	if (r == 0)
+		ObjBocDone(wrk, oc, &boc);
 }
 
 /*--------------------------------------------------------------------
@@ -850,9 +840,8 @@ HSH_DerefObjCore(struct worker *wrk, struct objcore **ocp)
 
 	if (oc->stobj->stevedore != NULL)
 		ObjFreeObj(wrk, oc);
-	FREE_OBJ(oc);
+	ObjDestroy(wrk, &oc);
 
-	wrk->stats->n_objectcore--;
 	/* Drop our ref on the objhead */
 	assert(oh->refcnt > 0);
 	(void)HSH_DerefObjHead(wrk, &oh);
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 09ddeed..b4201cb 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -54,7 +54,7 @@
  * 2	  ObjSetU32()
  * 2	  ObjSetU64()
  *
- * 2->3	ObjStable()	Will no longer be modified (clean up boc)
+ * 2->3	ObjBocDone()	Boc removed from OC, clean it up
  *
  * 23	ObjHasAttr()
  * 23	ObjGetAttr()
@@ -99,6 +99,34 @@ obj_getmethods(const struct objcore *oc)
 	return (oc->stobj->stevedore->methods);
 }
 
+static struct boc *
+obj_newboc(void)
+{
+	struct boc *boc;
+
+	ALLOC_OBJ(boc, BOC_MAGIC);
+	AN(boc);
+	Lck_New(&boc->mtx, lck_busyobj);
+	AZ(pthread_cond_init(&boc->cond, NULL));
+	boc->refcount = 1;
+	return (boc);
+}
+
+static void
+obj_deleteboc(struct boc **p)
+{
+	struct boc *boc;
+
+	AN(p);
+	boc = *p;
+	*p = NULL;
+	Lck_Delete(&boc->mtx);
+	AZ(pthread_cond_destroy(&boc->cond));
+	if (boc->vary != NULL)
+		free(boc->vary);
+	FREE_OBJ(boc);
+}
+
 /*====================================================================
  * ObjNew()
  *
@@ -115,15 +143,35 @@ ObjNew(struct worker *wrk)
 	AN(oc);
 	wrk->stats->n_objectcore++;
 	oc->last_lru = NAN;
-	ALLOC_OBJ(oc->boc, BOC_MAGIC);
-	AN(oc->boc);
-	Lck_New(&oc->boc->mtx, lck_busyobj);
-	AZ(pthread_cond_init(&oc->boc->cond, NULL));
-	oc->boc->refcount = 1;
+	oc->flags = OC_F_BUSY;
+
+	oc->boc = obj_newboc();
+
 	return (oc);
 }
 
 /*====================================================================
+ * ObjDestroy()
+ *
+ */
+
+void
+ObjDestroy(struct worker *wrk, struct objcore **p)
+{
+	struct objcore *oc;
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	AN(p);
+	oc = *p;
+	*p = NULL;
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	if (oc->boc != NULL)
+		obj_deleteboc(&oc->boc);
+	FREE_OBJ(oc);
+	wrk->stats->n_objectcore--;
+}
+
+/*====================================================================
  * ObjIterate()
  *
  */
@@ -322,14 +370,19 @@ ObjSlim(struct worker *wrk, struct objcore *oc)
  */
 
 void
-ObjStable(struct worker *wrk, struct objcore *oc, struct boc *boc)
+ObjBocDone(struct worker *wrk, struct objcore *oc, struct boc **boc)
 {
-	const struct obj_methods *m = obj_getmethods(oc);
+	const struct obj_methods *m;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(boc, BOC_MAGIC);
-	if (m->objstable != NULL)
-		m->objstable(wrk, oc, boc);
+	AN(boc);
+	CHECK_OBJ_NOTNULL(*boc, BOC_MAGIC);
+	if (oc->stobj->stevedore != NULL) {
+		m = obj_getmethods(oc);
+		if (m->objbocdone != NULL)
+			m->objbocdone(wrk, oc, *boc);
+	}
+	obj_deleteboc(boc);
 }
 
 /*====================================================================
diff --git a/bin/varnishd/cache/cache_obj.h b/bin/varnishd/cache/cache_obj.h
index 45f7e61..3d8e245 100644
--- a/bin/varnishd/cache/cache_obj.h
+++ b/bin/varnishd/cache/cache_obj.h
@@ -41,7 +41,7 @@ typedef int objgetspace_f(struct worker *, struct objcore *,
      ssize_t *sz, uint8_t **ptr);
 typedef void objextend_f(struct worker *, struct objcore *, ssize_t l);
 typedef void objtrimstore_f(struct worker *, struct objcore *);
-typedef void objstable_f(struct worker *, struct objcore *, struct boc *);
+typedef void objbocdone_f(struct worker *, struct objcore *, struct boc *);
 typedef void objslim_f(struct worker *, struct objcore *);
 typedef const void *objgetattr_f(struct worker *, struct objcore *,
     enum obj_attr attr, ssize_t *len);
@@ -55,7 +55,7 @@ struct obj_methods {
 	objgetspace_f	*objgetspace;
 	objextend_f	*objextend;
 	objtrimstore_f	*objtrimstore;
-	objstable_f	*objstable;
+	objbocdone_f	*objbocdone;
 	objslim_f	*objslim;
 	objgetattr_f	*objgetattr;
 	objsetattr_f	*objsetattr;
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index 8b862db..d9c858f 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -451,13 +451,13 @@ sml_trimstore(struct worker *wrk, struct objcore *oc)
 	VTAILQ_REMOVE(&o->list, st, list);
 	VTAILQ_INSERT_TAIL(&o->list, st1, list);
 	Lck_Unlock(&oc->boc->mtx);
-	/* sml_stable frees this */
+	/* sml_bocdone frees this */
 	AZ(oc->boc->stevedore_priv);
 	oc->boc->stevedore_priv = st;
 }
 
-static void __match_proto__(objstable_f)
-sml_stable(struct worker *wrk, struct objcore *oc, struct boc *boc)
+static void __match_proto__(objbocdone_f)
+sml_bocdone(struct worker *wrk, struct objcore *oc, struct boc *boc)
 {
 	const struct stevedore *stv;
 	struct storage *st;
@@ -610,7 +610,7 @@ const struct obj_methods SML_methods = {
 	.objgetspace	= sml_getspace,
 	.objextend	= sml_extend,
 	.objtrimstore	= sml_trimstore,
-	.objstable	= sml_stable,
+	.objbocdone	= sml_bocdone,
 	.objslim	= sml_slim,
 	.objgetattr	= sml_getattr,
 	.objsetattr	= sml_setattr,



More information about the varnish-commit mailing list