[master] 3e590da LRU is now completely detached from EXP
Poul-Henning Kamp
phk at FreeBSD.org
Wed Feb 3 23:45:28 CET 2016
commit 3e590da45c341536f08edcc2d9e8fa39e82344f1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Feb 3 22:45:02 2016 +0000
LRU is now completely detached from EXP
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index b95255e..a52434d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -695,7 +695,6 @@ void EXP_Inject(struct worker *wrk, struct objcore *oc);
void EXP_Rearm(struct objcore *, double now, double ttl, double grace,
double keep);
void EXP_Poke(struct objcore *);
-int EXP_NukeOne(struct worker *wrk, struct lru *lru);
enum exp_event_e {
EXP_INSERT,
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 7b5341d..d60900c 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -167,7 +167,7 @@ EXP_Poke(struct objcore *oc)
}
/*--------------------------------------------------------------------
- * Inject an object with a reference into the lru/binheap.
+ * Inject an object with a reference into the binheap.
*
* This can either come from a stevedore (persistent) during startup
* or from EXP_Insert() below.
@@ -288,9 +288,8 @@ EXP_Deregister_Callback(uintptr_t *handle)
*/
static void
-exp_inbox(struct exp_priv *ep, struct objcore *oc, double now, unsigned flags)
+exp_inbox(struct exp_priv *ep, struct objcore *oc, unsigned flags)
{
- struct lru *lru;
CHECK_OBJ_NOTNULL(ep, EXP_PRIV_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -298,21 +297,6 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now, unsigned flags)
VSLb(&ep->vsl, SLT_ExpKill, "EXP_Inbox p=%p e=%.9f f=0x%x", oc,
oc->timer_when, oc->flags);
- lru = ObjGetLRU(oc);
- CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
-
- Lck_Lock(&lru->mtx);
- if (isnan(oc->last_lru)) {
- if (!(oc->flags & OC_F_DYING)) {
- VTAILQ_INSERT_TAIL(&lru->lru_head, oc, lru_list);
- oc->last_lru = now;
- }
- } else if (oc->flags & OC_F_DYING) {
- VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
- oc->last_lru = NAN;
- }
- Lck_Unlock(&lru->mtx);
-
if (oc->flags & OC_F_DYING) {
VSLb(&ep->vsl, SLT_ExpKill, "EXP_Kill p=%p e=%.9f f=0x%x", oc,
oc->timer_when, oc->flags);
@@ -360,8 +344,6 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now, unsigned flags)
static double
exp_expire(struct exp_priv *ep, double now)
{
-
- struct lru *lru;
struct objcore *oc;
CHECK_OBJ_NOTNULL(ep, EXP_PRIV_MAGIC);
@@ -369,6 +351,8 @@ exp_expire(struct exp_priv *ep, double now)
oc = binheap_root(ep->heap);
if (oc == NULL)
return (now + 355./113.);
+ VSLb(&ep->vsl, SLT_ExpKill, "EXP_expire p=%p e=%.9f f=0x%x", oc,
+ oc->timer_when, oc->flags);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -381,21 +365,6 @@ exp_expire(struct exp_priv *ep, double now)
if (!(oc->flags & OC_F_DYING))
ObjKill(oc);
- lru = ObjGetLRU(oc);
- CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
- Lck_Lock(&lru->mtx);
-
- if (isnan(oc->last_lru)) {
- oc = NULL;
- } else {
- oc->last_lru = NAN;
- VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
- }
- Lck_Unlock(&lru->mtx);
-
- if (oc == NULL)
- return (now + 1e-3); // XXX ?
-
/* Remove from binheap */
assert(oc->timer_idx != BINHEAP_NOIDX);
binheap_delete(ep->heap, oc->timer_idx);
@@ -469,7 +438,7 @@ exp_thread(struct worker *wrk, void *priv)
t = VTIM_real();
if (oc != NULL)
- exp_inbox(ep, oc, t, flags);
+ exp_inbox(ep, oc, flags);
else
tnext = exp_expire(ep, t);
}
diff --git a/bin/varnishd/cache/cache_obj.h b/bin/varnishd/cache/cache_obj.h
index 3fba1ef..a981fb2 100644
--- a/bin/varnishd/cache/cache_obj.h
+++ b/bin/varnishd/cache/cache_obj.h
@@ -70,3 +70,4 @@ struct obj_methods {
objsetattr_f *objsetattr;
objtouch_f *objtouch;
};
+
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index b7dd9a1..ac4b485 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -121,6 +121,7 @@ uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
struct lru *LRU_Alloc(void);
void LRU_Free(struct lru *lru);
+int EXP_NukeOne(struct worker *wrk, struct lru *lru);
/*--------------------------------------------------------------------*/
extern const struct stevedore sma_stevedore;
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index 20d20a4..35cf916 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -39,6 +39,8 @@
#include "storage/storage.h"
#include "storage/storage_simple.h"
+#include "vtim.h"
+
/*--------------------------------------------------------------------
* Attempt to make space by nuking the oldest object on the LRU list
* which isn't in use.
@@ -247,6 +249,7 @@ static void __match_proto__(objfree_f)
sml_objfree(struct worker *wrk, struct objcore *oc)
{
struct object *o;
+ struct lru *lru;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -254,6 +257,15 @@ sml_objfree(struct worker *wrk, struct objcore *oc)
CAST_OBJ_NOTNULL(o, oc->stobj->priv, OBJECT_MAGIC);
o->magic = 0;
+ lru = ObjGetLRU(oc);
+ CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
+ Lck_Lock(&lru->mtx);
+ if (!isnan(oc->last_lru)) {
+ VTAILQ_REMOVE(&lru->lru_head, oc, lru_list);
+ oc->last_lru = NAN;
+ }
+ Lck_Unlock(&lru->mtx);
+
sml_stv_free(oc->stobj->stevedore, o->objstore);
memset(oc->stobj, 0, sizeof oc->stobj);
@@ -536,19 +548,28 @@ sml_stable(struct worker *wrk, struct objcore *oc, struct boc *boc)
{
const struct stevedore *stv;
struct storage *st;
+ struct lru *lru;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(boc, BOC_MAGIC);
- if (boc->stevedore_priv == NULL)
- return;
- CAST_OBJ_NOTNULL(st, boc->stevedore_priv, STORAGE_MAGIC);
- boc->stevedore_priv = 0;
- CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
- stv = oc->stobj->stevedore;
- CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
- sml_stv_free(stv, st);
+ if (boc->stevedore_priv != NULL) {
+ /* Free any leftovers from Trim */
+ CAST_OBJ_NOTNULL(st, boc->stevedore_priv, STORAGE_MAGIC);
+ boc->stevedore_priv = 0;
+ CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
+ stv = oc->stobj->stevedore;
+ CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
+ sml_stv_free(stv, st);
+ }
+
+ lru = ObjGetLRU(oc);
+ CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
+ Lck_Lock(&lru->mtx);
+ VTAILQ_INSERT_TAIL(&lru->lru_head, oc, lru_list);
+ oc->last_lru = VTIM_real();
+ Lck_Unlock(&lru->mtx);
}
static void * __match_proto__(objgetattr_f)
More information about the varnish-commit
mailing list