Commit bba23ef1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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

parent 2001b7ef
...@@ -609,8 +609,6 @@ struct object { ...@@ -609,8 +609,6 @@ struct object {
struct exp exp; struct exp exp;
/* VCL only variables */ /* VCL only variables */
long hits;
double last_modified; double last_modified;
struct http *http; struct http *http;
......
...@@ -433,6 +433,8 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp, ...@@ -433,6 +433,8 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
assert(oh->refcnt > 1); assert(oh->refcnt > 1);
assert(oc->objhead == oh); assert(oc->objhead == oh);
oc->refcnt++; oc->refcnt++;
if (oh->hits < LONG_MAX)
oh->hits++;
Lck_Unlock(&oh->mtx); Lck_Unlock(&oh->mtx);
assert(HSH_DerefObjHead(&wrk->stats, &oh)); assert(HSH_DerefObjHead(&wrk->stats, &oh));
*ocp = oc; *ocp = oc;
...@@ -460,12 +462,11 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp, ...@@ -460,12 +462,11 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
} else { } else {
retval = HSH_EXP; retval = HSH_EXP;
} }
if (oh->hits < LONG_MAX)
oh->hits++;
Lck_Unlock(&oh->mtx); Lck_Unlock(&oh->mtx);
if (retval == HSH_EXP) if (retval == HSH_EXP)
assert(HSH_DerefObjHead(&wrk->stats, &oh)); assert(HSH_DerefObjHead(&wrk->stats, &oh));
if (!cache_param->obj_readonly && exp_o->hits < INT_MAX)
exp_o->hits++;
*ocp = exp_oc; *ocp = exp_oc;
return (retval); return (retval);
} }
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "cache.h" #include "cache.h"
#include "common/heritage.h" #include "common/heritage.h"
#include "hash/hash_slinger.h"
#include "cache_backend.h" #include "cache_backend.h"
#include "vrt.h" #include "vrt.h"
...@@ -570,29 +571,17 @@ VRT_r_server_hostname(const struct vrt_ctx *ctx) ...@@ -570,29 +571,17 @@ VRT_r_server_hostname(const struct vrt_ctx *ctx)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
#define VOBJ_L(type, field) \ long
void \ VRT_r_obj_hits(const struct vrt_ctx *ctx)
VRT_l_obj_##field(const struct vrt_ctx *ctx, type a) \ {
{ \ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \ CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC); \ CHECK_OBJ_NOTNULL(ctx->req->obj->objcore, OBJCORE_MAGIC);
ctx->req->obj->field = a; \ CHECK_OBJ_NOTNULL(ctx->req->obj->objcore->objhead, OBJHEAD_MAGIC);
} return (ctx->req->obj->objcore->objhead->hits);
#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); \
} }
VOBJ_L(long, hits)
VOBJ_R(long, hits)
unsigned unsigned
VRT_r_obj_uncacheable(const struct vrt_ctx *ctx) VRT_r_obj_uncacheable(const struct vrt_ctx *ctx)
{ {
......
...@@ -94,6 +94,8 @@ struct objhead { ...@@ -94,6 +94,8 @@ struct objhead {
uint8_t digest[DIGEST_LEN]; uint8_t digest[DIGEST_LEN];
struct waitinglist *waitinglist; struct waitinglist *waitinglist;
long hits;
/*---------------------------------------------------- /*----------------------------------------------------
* The fields below are for the sole private use of * The fields below are for the sole private use of
* the hash implementation(s). * the hash implementation(s).
......
...@@ -13,7 +13,6 @@ varnish v1 -vcl+backend { ...@@ -13,7 +13,6 @@ varnish v1 -vcl+backend {
sub vcl_deliver { sub vcl_deliver {
set resp.http.foo = obj.hits; set resp.http.foo = obj.hits;
set obj.hits = obj.hits + 1;
} }
} -start } -start
......
...@@ -512,7 +512,7 @@ sp_variables = [ ...@@ -512,7 +512,7 @@ sp_variables = [
('obj.hits', ('obj.hits',
'INT', 'INT',
( 'hit', 'deliver',), ( 'hit', 'deliver',),
( 'hit', 'deliver',), """ ( ), """
The approximate number of times the object has been The approximate number of times the object has been
delivered. A value of 0 indicates a cache miss. delivered. A value of 0 indicates a cache miss.
This variable is also available in vcl_deliver. This variable is also available in vcl_deliver.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment