[4.0] bba23ef Move obj.hits to objhead, make it read-only

Poul-Henning Kamp phk at FreeBSD.org
Tue Apr 1 15:09:50 CEST 2014


commit bba23ef151986671cef6d1ad8a126d30d093daa0
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Mar 19 21:33:44 2014 +0000

    Move obj.hits to objhead, make it read-only

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ce90e58..ac615a4 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -609,8 +609,6 @@ struct object {
 	struct exp		exp;
 
 	/* VCL only variables */
-	long			hits;
-
 	double			last_modified;
 
 	struct http		*http;
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 07c5931..d7263e1 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -433,6 +433,8 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			assert(oh->refcnt > 1);
 			assert(oc->objhead == oh);
 			oc->refcnt++;
+			if (oh->hits < LONG_MAX)
+				oh->hits++;
 			Lck_Unlock(&oh->mtx);
 			assert(HSH_DerefObjHead(&wrk->stats, &oh));
 			*ocp = oc;
@@ -460,12 +462,11 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 		} else {
 			retval = HSH_EXP;
 		}
-
+		if (oh->hits < LONG_MAX)
+			oh->hits++;
 		Lck_Unlock(&oh->mtx);
 		if (retval == HSH_EXP)
 			assert(HSH_DerefObjHead(&wrk->stats, &oh));
-		if (!cache_param->obj_readonly && exp_o->hits < INT_MAX)
-			exp_o->hits++;
 		*ocp = exp_oc;
 		return (retval);
 	}
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 0bcd5d5..b51d2de 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -36,6 +36,7 @@
 
 #include "cache.h"
 #include "common/heritage.h"
+#include "hash/hash_slinger.h"
 
 #include "cache_backend.h"
 #include "vrt.h"
@@ -570,29 +571,17 @@ VRT_r_server_hostname(const struct vrt_ctx *ctx)
 
 /*--------------------------------------------------------------------*/
 
-#define VOBJ_L(type, field)						\
-void									\
-VRT_l_obj_##field(const struct vrt_ctx *ctx, type a)			\
-{									\
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);				\
-	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);				\
-	CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);			\
-	ctx->req->obj->field = a;					\
-}
-
-#define VOBJ_R(type, field)						\
-type									\
-VRT_r_obj_##field(const struct vrt_ctx *ctx)				\
-{									\
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);				\
-	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);				\
-	CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);			\
-	return (ctx->req->obj->field);					\
+long
+VRT_r_obj_hits(const struct vrt_ctx *ctx)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req->obj->objcore, OBJCORE_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req->obj->objcore->objhead, OBJHEAD_MAGIC);
+	return (ctx->req->obj->objcore->objhead->hits);
 }
 
-VOBJ_L(long, hits)
-VOBJ_R(long, hits)
-
 unsigned
 VRT_r_obj_uncacheable(const struct vrt_ctx *ctx)
 {
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index f38c84d..40d3aef 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -94,6 +94,8 @@ struct objhead {
 	uint8_t			digest[DIGEST_LEN];
 	struct waitinglist	*waitinglist;
 
+	long			hits;
+
 	/*----------------------------------------------------
 	 * The fields below are for the sole private use of
 	 * the hash implementation(s).
diff --git a/bin/varnishtest/tests/v00013.vtc b/bin/varnishtest/tests/v00013.vtc
index 0bb2858..c428add 100644
--- a/bin/varnishtest/tests/v00013.vtc
+++ b/bin/varnishtest/tests/v00013.vtc
@@ -13,7 +13,6 @@ varnish v1 -vcl+backend {
 
 	sub vcl_deliver {
 		set resp.http.foo = obj.hits;
-		set obj.hits = obj.hits + 1;
 	}
 } -start
 
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 9d8239b..c63274e 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -512,7 +512,7 @@ sp_variables = [
 	('obj.hits',
 		'INT',
 		( 'hit', 'deliver',),
-		( 'hit', 'deliver',), """
+		( ), """
 		The approximate number of times the object has been
 		delivered. A value of 0 indicates a cache miss.
 		This variable is also available in vcl_deliver.



More information about the varnish-commit mailing list