[experimental-ims] 2d7d3c8 Pack struct ws better to avoid padding.

Geoff Simmons geoff at varnish-cache.org
Fri Jul 8 11:47:43 CEST 2011


commit 2d7d3c8610d1507a976576f9ed9e3c880cff8b6f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 20 09:16:20 2011 +0000

    Pack struct ws better to avoid padding.
    
    Repack struct object, reducing a couple of field widths along the way.
    
    This shaves 16 bytes of struct object.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 48d1456..f8dedb1 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -143,12 +143,12 @@ enum step {
 struct ws {
 	unsigned		magic;
 #define WS_MAGIC		0x35fac554
+	unsigned		overflow;	/* workspace overflowed */
 	const char		*id;		/* identity */
 	char			*s;		/* (S)tart of buffer */
 	char			*f;		/* (F)ree pointer */
 	char			*r;		/* (R)eserved length */
 	char			*e;		/* (E)nd of buffer */
-	int			overflow;	/* workspace overflowed */
 };
 
 /*--------------------------------------------------------------------
@@ -479,12 +479,13 @@ struct object {
 	struct objcore		*objcore;
 
 	struct ws		ws_o[1];
-	unsigned char		*vary;
 
-	unsigned		response;
+	uint8_t 		*vary;
+	unsigned		hits;
+	uint16_t		response;
 
 	/* XXX: make bitmap */
-	unsigned		gziped;
+	uint8_t			gziped;
 	/* Bit positions in the gzip stream */
 	ssize_t			gzip_start;
 	ssize_t			gzip_last;
@@ -507,7 +508,6 @@ struct object {
 
 	double			last_use;
 
-	int			hits;
 };
 
 /* -------------------------------------------------------------------*/
@@ -566,7 +566,7 @@ struct sess {
 	unsigned		handling;
 	unsigned char		sendbody;
 	unsigned char		wantbody;
-	int			err_code;
+	uint16_t		err_code;
 	const char		*err_reason;
 
 	VTAILQ_ENTRY(sess)	list;
diff --git a/bin/varnishd/cache_cli.c b/bin/varnishd/cache_cli.c
index 387dffb..2d3066c 100644
--- a/bin/varnishd/cache_cli.c
+++ b/bin/varnishd/cache_cli.c
@@ -38,6 +38,7 @@
 
 #include <stdio.h>
 #include <errno.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -124,7 +125,7 @@ cli_debug_sizeof(struct cli *cli, const char * const *av, void *priv)
 	(void)priv;
 
 #define SZOF(foo)       VCLI_Out(cli, \
-    "sizeof(%s) = %zd = 0x%zx\n", #foo, sizeof(foo), sizeof(foo));
+    "sizeof(%s) = %zd = 0x%zx\n", #foo, sizeof(foo), sizeof(foo))
 	SZOF(struct ws);
 	SZOF(struct http);
 	SZOF(struct http_conn);
@@ -139,6 +140,63 @@ cli_debug_sizeof(struct cli *cli, const char * const *av, void *priv)
 	SZOF(struct vbc);
 	SZOF(struct VSC_C_main);
 	SZOF(struct lock);
+#define OFOF(foo, bar)	{ foo __foo; VCLI_Out(cli, \
+    "%-30s = 0x%4zx @ 0x%4zx\n", \
+	#foo "." #bar, sizeof(__foo.bar), offsetof(foo, bar)); }
+#if 0
+	OFOF(struct objhead, magic);
+	OFOF(struct objhead, refcnt);
+	OFOF(struct objhead, mtx);
+	OFOF(struct objhead, objcs);
+	OFOF(struct objhead, digest);
+	OFOF(struct objhead, waitinglist);
+	OFOF(struct objhead, _u);
+#endif
+#if 0
+	OFOF(struct http, magic);
+	OFOF(struct http, logtag);
+	OFOF(struct http, ws);
+	OFOF(struct http, hd);
+	OFOF(struct http, hdf);
+	OFOF(struct http, shd);
+	OFOF(struct http, nhd);
+	OFOF(struct http, status);
+	OFOF(struct http, protover);
+	OFOF(struct http, conds);
+#endif
+#if 0
+	OFOF(struct storage, magic);
+	OFOF(struct storage, fd);
+	OFOF(struct storage, where);
+	OFOF(struct storage, list);
+	OFOF(struct storage, stevedore);
+	OFOF(struct storage, priv);
+	OFOF(struct storage, ptr);
+	OFOF(struct storage, len);
+	OFOF(struct storage, space);
+#endif
+	OFOF(struct object, magic);
+	OFOF(struct object, xid);
+	OFOF(struct object, objstore);
+	OFOF(struct object, objcore);
+	OFOF(struct object, ws_o);
+	OFOF(struct object, vary);
+	OFOF(struct object, hits);
+	OFOF(struct object, response);
+	OFOF(struct object, gziped);
+	OFOF(struct object, gzip_start);
+	OFOF(struct object, gzip_last);
+	OFOF(struct object, gzip_stop);
+	OFOF(struct object, len);
+	OFOF(struct object, age);
+	OFOF(struct object, entered);
+	OFOF(struct object, exp);
+	OFOF(struct object, last_modified);
+	OFOF(struct object, last_lru);
+	OFOF(struct object, http);
+	OFOF(struct object, store);
+	OFOF(struct object, esidata);
+	OFOF(struct object, last_use);
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list