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

Add ObjKill() for sniping an objcore, for instance for LRU-kills.

parent c1ee4c9f
......@@ -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 */
......
......@@ -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);
......
......@@ -369,6 +369,35 @@ ObjTouch(struct worker *wrk, struct objcore *oc, double now)
om->objtouch(wrk, oc, 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
*/
......
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