[master] ac1fe6e Used a linked list allocated of req->ws for VDPs

Poul-Henning Kamp phk at FreeBSD.org
Wed Oct 22 00:14:26 CEST 2014


commit ac1fe6e814a7d7277f3fde41aa2d81d5e882749d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Oct 21 22:08:34 2014 +0000

    Used a linked list allocated of req->ws for VDPs

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 47a9e0a..048830a 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -201,18 +201,6 @@ struct http {
  * VFP filter state
  */
 
-struct vfp_entry {
-	unsigned		magic;
-#define VFP_ENTRY_MAGIC		0xbe32a027
-	const struct vfp	*vfp;
-	void			*priv1;
-	intptr_t		priv2;
-	enum vfp_status		closed;
-	VTAILQ_ENTRY(vfp_entry)	list;
-	uint64_t		calls;
-	uint64_t		bytes_out;
-};
-
 VTAILQ_HEAD(vfp_entry_s, vfp_entry);
 
 struct vfp_ctx {
@@ -534,6 +522,8 @@ struct busyobj {
 
 /*--------------------------------------------------------------------*/
 
+VTAILQ_HEAD(vdp_entry_s, vdp_entry);
+
 struct req {
 	unsigned		magic;
 #define REQ_MAGIC		0x2751aaa1
@@ -614,10 +604,8 @@ struct req {
 #define RES_PIPE		(1<<7)
 
 	/* Deliver pipeline */
-#define	N_VDPS			5
-	vdp_bytes		*vdps[N_VDPS];
-	void			*vdpp[N_VDPS];
-	int			vdp_nxt;
+	struct vdp_entry_s	vdp;
+	struct vdp_entry	*vdp_nxt;
 
 	/* Transaction VSL buffer */
 	struct vsl_log		vsl[1];
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index f231da0..55e1d9f 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -35,46 +35,52 @@
 int
 VDP_bytes(struct req *req, enum vdp_action act, const void *ptr, ssize_t len)
 {
-	int i, retval;
+	int retval;
+	struct vdp_entry *vdp;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	vdp = req->vdp_nxt;
+	CHECK_OBJ_NOTNULL(vdp, VDP_ENTRY_MAGIC);
+	req->vdp_nxt = VTAILQ_NEXT(vdp, list);
 
 	assert(act > VDP_NULL || len > 0);
 	/* Call the present layer, while pointing to the next layer down */
-	i = req->vdp_nxt--;
-	assert(i >= 0 && i < N_VDPS);
-	retval = req->vdps[i](req, act, &req->vdpp[i], ptr, len);
-	req->vdp_nxt++;
+	retval = vdp->func(req, act, &vdp->priv, ptr, len);
+	req->vdp_nxt = vdp;
 	return (retval);
 }
 
 void
 VDP_push(struct req *req, vdp_bytes *func, void *priv)
 {
+	struct vdp_entry *vdp;
+
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	AN(func);
 
-	/* Push another layer */
-	assert(req->vdp_nxt >= 0);
-	assert(req->vdp_nxt + 1 < N_VDPS);
-	req->vdps[++req->vdp_nxt] = func;
-	req->vdpp[req->vdp_nxt] = priv;
-	AZ(req->vdps[req->vdp_nxt](req, VDP_INIT,
-	   &req->vdpp[req->vdp_nxt], NULL, 0));
+	vdp = WS_Alloc(req->ws, sizeof *vdp);
+	AN(vdp);
+	memset(vdp, 0, sizeof *vdp);
+	vdp->magic = VDP_ENTRY_MAGIC;
+	vdp->func = func;
+	vdp->priv = priv;
+	VTAILQ_INSERT_HEAD(&req->vdp, vdp, list);
+	req->vdp_nxt = vdp;
+
+	AZ(func(req, VDP_INIT, &vdp->priv, NULL, 0));
 }
 
 void
 VDP_pop(struct req *req, vdp_bytes *func)
 {
+	struct vdp_entry *vdp;
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 
-	/* Pop top layer */
-	assert(req->vdp_nxt >= 1);
-	assert(req->vdp_nxt < N_VDPS);
-	assert(req->vdps[req->vdp_nxt] == func);
-	AZ(req->vdps[req->vdp_nxt](req, VDP_FINI,
-	   &req->vdpp[req->vdp_nxt], NULL, 0));
-	AZ(req->vdpp[req->vdp_nxt]);
-	req->vdps[req->vdp_nxt] = NULL;
-	req->vdp_nxt--;
+	vdp = VTAILQ_FIRST(&req->vdp);
+	CHECK_OBJ_NOTNULL(vdp, VDP_ENTRY_MAGIC);
+	assert(vdp->func == func);
+	VTAILQ_REMOVE(&req->vdp, vdp, list);
+	AZ(vdp->func(req, VDP_FINI, &vdp->priv, NULL, 0));
+	AZ(vdp->priv);
+	req->vdp_nxt = VTAILQ_FIRST(&req->vdp);
 }
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 1ee0952..c26c665 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -55,6 +55,19 @@ struct vfp {
 	intptr_t	priv2;
 };
 
+struct vfp_entry {
+	unsigned		magic;
+#define VFP_ENTRY_MAGIC		0xbe32a027
+	const struct vfp	*vfp;
+	void			*priv1;
+	intptr_t		priv2;
+	enum vfp_status		closed;
+	VTAILQ_ENTRY(vfp_entry)	list;
+	uint64_t		calls;
+	uint64_t		bytes_out;
+};
+
+
 extern const struct vfp vfp_gunzip;
 extern const struct vfp vfp_gzip;
 extern const struct vfp vfp_testgunzip;
@@ -78,9 +91,18 @@ enum vdp_action {
 	VDP_FINISH,
 	VDP_FINI,
 };
+
 typedef int vdp_bytes(struct req *, enum vdp_action, void **priv,
     const void *ptr, ssize_t len);
 
+struct vdp_entry {
+	unsigned		magic;
+#define VDP_ENTRY_MAGIC		0x353eb781
+	vdp_bytes		*func;
+	void			*priv;
+	VTAILQ_ENTRY(vdp_entry)	list;
+};
+
 int VDP_bytes(struct req *, enum vdp_action act, const void *ptr, ssize_t len);
 void VDP_push(struct req *, vdp_bytes *func, void *priv);
 void VDP_pop(struct req *, vdp_bytes *func);
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 3ab930e..b97c925 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -46,7 +46,7 @@ v1d_bytes(struct req *req, enum vdp_action act, void **priv,
 	if (act == VDP_INIT || act == VDP_FINI)
 		return (0);
 
-	assert(req->vdp_nxt == -1);	/* always at the bottom of the pile */
+	AZ(req->vdp_nxt);		/* always at the bottom of the pile */
 
 	if (len > 0)
 		wl = WRW_Write(req->wrk, ptr, len);
@@ -336,8 +336,9 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 	http_SetHeader(req->resp,
 	    req->doclose ? "Connection: close" : "Connection: keep-alive");
 
-	req->vdps[0] = v1d_bytes;
 	req->vdp_nxt = 0;
+	VTAILQ_INIT(&req->vdp);
+	VDP_push(req, v1d_bytes, NULL);
 
 	if (
 	    req->wantbody &&



More information about the varnish-commit mailing list