[master] a328ddd Shave 8 bytes of struct ws on 64 bit archs.

Poul-Henning Kamp phk at FreeBSD.org
Tue Dec 3 17:38:41 CET 2013


commit a328ddd5e0ee28959615c051981ff94057071fcf
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Dec 3 10:05:30 2013 +0000

    Shave 8 bytes of struct ws on 64 bit archs.
    
    With 8 byte pointers, having a char[X] for X <= 8 is cheaper than
    than a char *.
    
    Don't waste 32bits on the overflow flag.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index bf7fa0f..eb7136b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -170,8 +170,7 @@ struct lock { void *priv; };	// Opaque
 struct ws {
 	unsigned		magic;
 #define WS_MAGIC		0x35fac554
-	unsigned		overflow;	/* workspace overflowed */
-	const char		*id;		/* identity */
+	char			id[4];		/* identity */
 	char			*s;		/* (S)tart of buffer */
 	char			*f;		/* (F)ree/front pointer */
 	char			*r;		/* (R)eserved length */
@@ -1207,6 +1206,7 @@ void WS_Reset(struct ws *ws, char *p);
 char *WS_Alloc(struct ws *ws, unsigned bytes);
 void *WS_Copy(struct ws *ws, const void *str, int len);
 char *WS_Snapshot(struct ws *ws);
+int WS_Overflowed(const struct ws *ws);
 
 /* rfc2616.c */
 void RFC2616_Ttl(struct busyobj *);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index ae72c62..79449fc 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -433,7 +433,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 	assert(bo->refcount >= 1);
 
-	AZ(bo->ws_o->overflow);
+	AZ(WS_Overflowed(bo->ws_o));
 	if (bo->do_stream)
 		HSH_Unbusy(&wrk->stats, obj->objcore);
 
@@ -587,7 +587,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	http_CopyHome(obj->http);
 
 
-	AZ(bo->ws_o->overflow);
+	AZ(WS_Overflowed(bo->ws_o));
 	VBO_setstate(bo, BOS_FETCHING);
 	HSH_Unbusy(&wrk->stats, obj->objcore);
 
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 6f26703..97775ae 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -108,9 +108,10 @@ static void
 pan_ws(const struct ws *ws, int indent)
 {
 
-	VSB_printf(pan_vsp, "%*sws = %p { %s\n", indent, "",
-	    ws, ws->overflow ? "overflow" : "");
-	VSB_printf(pan_vsp, "%*sid = \"%s\",\n", indent + 2, "", ws->id);
+	VSB_printf(pan_vsp, "%*sws = %p {", indent, "", ws);
+	if (WS_Overflowed(ws))
+		VSB_printf(pan_vsp, " OVERFLOW");
+	VSB_printf(pan_vsp, "\n%*sid = \"%s\",\n", indent + 2, "", ws->id);
 	VSB_printf(pan_vsp, "%*s{s,f,r,e} = {%p", indent + 2, "", ws->s);
 	if (ws->f > ws->s)
 		VSB_printf(pan_vsp, ",+%ld", (long) (ws->f - ws->s));
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index ae41fd1..46cb31f 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -111,7 +111,7 @@ ses_new(struct sesspool *pp)
 	p = (char*)(sp + 1);
 	p = (void*)PRNDUP(p);
 	assert(p < e);
-	WS_Init(sp->ws, "sess", p, e - p);
+	WS_Init(sp->ws, "ses", p, e - p);
 	sp->local_addr = (void*)WS_Alloc(sp->ws, vsa_suckaddr_len);
 	sp->remote_addr = (void*)WS_Alloc(sp->ws, vsa_suckaddr_len);
 
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 31738e3..17245b1 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -56,6 +56,11 @@ WS_Assert(const struct ws *ws)
 	}
 }
 
+/*
+ * NB: The id must be max 3 char and lower-case.
+ * (upper-case the first char to indicate overflow)
+ */
+
 void
 WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
 {
@@ -70,10 +75,21 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
 	ws->e = ws->s + len;
 	assert(PAOK(len));
 	ws->f = ws->s;
-	ws->id = id;
+	assert(id[0] & 0x40);
+	assert(strlen(id) < sizeof ws->id);
+	strcpy(ws->id, id);
 	WS_Assert(ws);
 }
 
+
+static void
+WS_MarkOverflow(struct ws *ws)
+{
+	WS_Assert(ws);
+
+	ws->id[0] &= ~0x40;		// Cheasy toupper()
+}
+
 /*
  * Reset a WS to start or a given pointer, likely from WS_Snapshot
  */
@@ -105,7 +121,7 @@ WS_Alloc(struct ws *ws, unsigned bytes)
 
 	assert(ws->r == NULL);
 	if (ws->f + bytes > ws->e) {
-		ws->overflow++;
+		WS_MarkOverflow(ws);
 		WS_Assert(ws);
 		return(NULL);
 	}
@@ -131,7 +147,7 @@ WS_Copy(struct ws *ws, const void *str, int len)
 
 	bytes = PRNDUP((unsigned)len);
 	if (ws->f + bytes > ws->e) {
-		ws->overflow++;
+		WS_MarkOverflow(ws);
 		WS_Assert(ws);
 		return(NULL);
 	}
@@ -201,3 +217,12 @@ WS_ReleaseP(struct ws *ws, char *ptr)
 	ws->r = NULL;
 	WS_Assert(ws);
 }
+int
+WS_Overflowed(const struct ws *ws)
+{
+	WS_Assert(ws);
+
+	if (ws->id[0] & 0x40)
+		return (0);
+	return (1);
+}



More information about the varnish-commit mailing list