[master] 6f6bf9d Move LRU-touching behind a oc->touch method.

Poul-Henning Kamp phk at FreeBSD.org
Wed Dec 16 11:22:17 CET 2015


commit 6f6bf9dbb8ca834855a22d10d169efbd5557e184
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Dec 16 10:21:25 2015 +0000

    Move LRU-touching behind a oc->touch method.
    
    This makes it easier for -spersistent to avoid LRU touching

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ffdbcbb..fe1f37e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -363,9 +363,6 @@ struct lru {
 #define LRU_MAGIC		0x3fec7bb0
 	VTAILQ_HEAD(,objcore)	lru_head;
 	struct lock		mtx;
-	unsigned		flags;
-#define LRU_F_DONTMOVE		(1<<1)
-#define LRU_F_CONDEMMED		(1<<2)
 	unsigned		n_objcore;
 };
 
@@ -850,6 +847,7 @@ int ObjIterate(struct worker *, struct objcore *,
 int ObjGetSpace(struct worker *, struct objcore *, ssize_t *sz, uint8_t **ptr);
 void ObjExtend(struct worker *, struct objcore *, ssize_t l);
 void ObjTrimStore(struct worker *, struct objcore *);
+void ObjTouch(struct worker *wrk, struct objcore *oc, double now);
 unsigned ObjGetXID(struct worker *, struct objcore *);
 uint64_t ObjGetLen(struct worker *, struct objcore *oc);
 void ObjUpdateMeta(struct worker *, struct objcore *);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 5c27d07..a01ca0a 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -240,13 +240,6 @@ EXP_Touch(struct objcore *oc, double now)
 	lru = ObjGetLRU(oc);
 	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
 
-	/*
-	 * For -spersistent (and possibly other stevedores, we don't move
-	 * objects on the lru list, since LRU doesn't really help much.
-	 */
-	if (lru->flags & LRU_F_DONTMOVE)
-		return;
-
 	if (Lck_Trylock(&lru->mtx))
 		return;
 
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 35e7a2f..ebbb76f 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -36,6 +36,7 @@
  *	ObjSetAttr	Set attr now
  *	ObjGetAttr	Get attr no
  *	ObjRelease	Done with attr ptr
+ *	ObjTouch	Object was used
  */
 
 #include "config.h"
@@ -247,6 +248,20 @@ ObjSetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
 }
 
 /*====================================================================
+ * ObjTouch()
+ */
+
+void
+ObjTouch(struct worker *wrk, struct objcore *oc, double now)
+{
+	const struct obj_methods *om = obj_getmethods(oc);
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	if (om->objtouch != NULL)
+		om->objtouch(wrk, oc, now);
+}
+
+/*====================================================================
  * Utility functions which work on top of the previous ones
  */
 
diff --git a/bin/varnishd/cache/cache_obj.h b/bin/varnishd/cache/cache_obj.h
index 3b2a937..c08d75c 100644
--- a/bin/varnishd/cache/cache_obj.h
+++ b/bin/varnishd/cache/cache_obj.h
@@ -49,6 +49,7 @@ typedef void *objgetattr_f(struct worker *, struct objcore *,
 typedef void *objsetattr_f(struct worker *, struct objcore *,
     enum obj_attr attr, ssize_t len, const void *ptr);
 typedef uint64_t objgetlen_f(struct worker *, struct objcore *);
+typedef void objtouch_f(struct worker *, struct objcore *, double now);
 
 struct obj_methods {
 	objfree_f	*objfree;
@@ -65,4 +66,5 @@ struct obj_methods {
 	objslim_f	*objslim;
 	objgetattr_f	*objgetattr;
 	objsetattr_f	*objsetattr;
+	objtouch_f	*objtouch;
 };
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 5127f55..8279bdd 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -126,7 +126,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 	assert(req->objcore->refcnt > 0);
 
 	if (req->objcore->exp_flags & OC_EF_EXP)
-		EXP_Touch(req->objcore, req->t_prev);
+		ObjTouch(req->wrk, req->objcore, req->t_prev);
 
 	HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
 	if (HTTP_Decode(req->resp,
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index dd0c66b..330f580 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -708,6 +708,7 @@ SMP_Init(void)
 	smp_oc_realmethods.objupdatemeta =	smp_oc_methods.objupdatemeta;
 	smp_oc_realmethods.objfree = smp_oc_methods.objfree;
 	smp_oc_realmethods.objgetlru = smp_oc_methods.objgetlru;
+	smp_oc_realmethods.objtouch = NULL;
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index e8034cd..90b9fb6 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -225,7 +225,6 @@ smp_new_seg(struct smp_sc *sc)
 	*sg = tmpsg;
 	sg->lru = LRU_Alloc();
 	CHECK_OBJ_NOTNULL(sg->lru, LRU_MAGIC);
-	sg->lru->flags |= LRU_F_DONTMOVE;
 
 	sg->p.offset = IRNUP(sc, sg->p.offset);
 	sg->p.length -= sg->p.offset - tmpsg.p.offset;
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index e79f86b..168e7ff 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -557,6 +557,14 @@ sml_setattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
 	return (retval);
 }
 
+static void __match_proto__(objtouch_f)
+sml_touch(struct worker *wrk, struct objcore *oc, double now)
+{
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	EXP_Touch(oc, now);
+}
 
 const struct obj_methods SML_methods = {
 	.objfree	= sml_objfree,
@@ -569,4 +577,5 @@ const struct obj_methods SML_methods = {
 	.objslim	= sml_slim,
 	.objgetattr	= sml_getattr,
 	.objsetattr	= sml_setattr,
+	.objtouch	= sml_touch,
 };



More information about the varnish-commit mailing list