Commit 3e590da4 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

LRU is now completely detached from EXP

parent c5b9d70b
......@@ -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,
......
......@@ -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);
}
......
......@@ -70,3 +70,4 @@ struct obj_methods {
objsetattr_f *objsetattr;
objtouch_f *objtouch;
};
......@@ -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;
......
......@@ -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)
......
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