[master] f2882d3 Add ObjKill() for sniping an objcore, for instance for LRU-kills.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Feb 3 11:32:10 CET 2016
commit f2882d3c402522cef330cd84217f5cab44748768
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Feb 3 09:02:40 2016 +0000
Add ObjKill() for sniping an objcore, for instance for LRU-kills.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 7dfb482..e965cc3 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -855,12 +855,13 @@ ssize_t ObjWaitExtend(struct worker *, struct objcore *, ssize_t l);
void ObjSetState(const struct objcore *, enum boc_state_e next);
void ObjWaitState(const struct objcore *, enum boc_state_e want);
void ObjTrimStore(struct worker *, struct objcore *);
-void ObjTouch(struct worker *wrk, struct objcore *oc, double now);
+void ObjTouch(struct worker *, struct objcore *, double now);
+int ObjKill(const struct worker *, struct objcore *);
unsigned ObjGetXID(struct worker *, struct objcore *);
-uint64_t ObjGetLen(struct worker *, struct objcore *oc);
+uint64_t ObjGetLen(struct worker *, struct objcore *);
void ObjUpdateMeta(struct worker *, struct objcore *);
void ObjFreeObj(struct worker *, struct objcore *);
-void ObjSlim(struct worker *, struct objcore *oc);
+void ObjSlim(struct worker *, struct objcore *);
struct lru *ObjGetLRU(const struct objcore *);
int ObjHasAttr(struct worker *, struct objcore *, enum obj_attr);
void *ObjGetAttr(struct worker *, struct objcore *, enum obj_attr,
@@ -879,7 +880,7 @@ int ObjGetDouble(struct worker *, struct objcore *, enum obj_attr, double *);
int ObjGetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t *);
int ObjGetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t *);
-int ObjCheckFlag(struct worker *, struct objcore *oc, enum obj_flags of);
+int ObjCheckFlag(struct worker *, struct objcore *, enum obj_flags of);
void ObjSetFlag(struct worker *, struct objcore *, enum obj_flags of, int val);
/* cache_panic.c */
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 119f521..65cf46c 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -279,7 +279,6 @@ int
EXP_NukeOne(struct worker *wrk, struct lru *lru)
{
struct objcore *oc, *oc2;
- struct objhead *oh;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
@@ -292,30 +291,12 @@ EXP_NukeOne(struct worker *wrk, struct lru *lru)
oc, oc->flags, oc->refcnt);
AZ(oc->exp_flags & OC_EF_OFFLRU);
- AZ(oc->exp_flags & OC_EF_DYING);
-
- /*
- * It wont release any space if we cannot release the last
- * reference, besides, if somebody else has a reference,
- * it's a bad idea to nuke this object anyway.
- */
- if (oc->refcnt > 1)
- continue;
- oh = oc->objhead;
- CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
- if (Lck_Trylock(&oh->mtx))
- continue;
- if (oc->refcnt == 1) {
- oc->exp_flags |= OC_EF_DYING | OC_EF_OFFLRU;
- oc->refcnt++;
+
+ if (ObjKill(wrk, oc)) {
VSC_C_main->n_lru_nuked++; // XXX per lru ?
VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
- } else {
- oc = NULL;
- }
- Lck_Unlock(&oh->mtx);
- if (oc != NULL)
break;
+ }
}
Lck_Unlock(&lru->mtx);
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index a1d2178..fb4c897 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -370,6 +370,35 @@ ObjTouch(struct worker *wrk, struct objcore *oc, double now)
}
/*====================================================================
+ * ObjKill()
+ *
+ * If objcore is idle, gain a ref and mark it dead.
+ */
+
+int
+ObjKill(const struct worker *wrk, struct objcore *oc)
+{
+ int retval = 0;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+ CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
+
+ AZ(oc->exp_flags & OC_EF_DYING);
+
+ if (oc->refcnt == 1 && !Lck_Trylock(&oc->objhead->mtx)) {
+ if (oc->refcnt == 1) {
+ oc->exp_flags |= OC_EF_DYING;
+ oc->exp_flags |= OC_EF_OFFLRU; /* XXX */
+ oc->refcnt++;
+ retval = 1;
+ }
+ Lck_Unlock(&oc->objhead->mtx);
+ }
+ return (retval);
+}
+
+/*====================================================================
* Utility functions which work on top of the previous ones
*/
More information about the varnish-commit
mailing list