Commit 7050ccee authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Dridi Boukelmoune

Repurpose OC_EF_REFD flag slightly

The OC_EF_REFD flag indicates whether expiry has a ref on the
OC. Previously, the flag was only gained during the call to
EXP_Insert. With this patch, and the helper function EXP_RefNewObjcore(),
the flag is gained while holding the objhead mutex during
HSH_Unbusy(). This enables the expiry functions to test on missing
OC_EF_REFD and quickly return without having to take the main expiry
mutex.
parent 9210cd77
......@@ -105,10 +105,11 @@ exp_mail_it(struct objcore *oc, uint8_t cmds)
{
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
assert(oc->refcnt > 0);
AZ(cmds & OC_EF_REFD);
Lck_AssertHeld(&exphdl->mtx);
if ((cmds | oc->exp_flags) & OC_EF_REFD) {
if (oc->exp_flags & OC_EF_REFD) {
if (!(oc->exp_flags & OC_EF_POSTED)) {
if (cmds & OC_EF_REMOVE)
VSTAILQ_INSERT_HEAD(&exphdl->inbox,
......@@ -119,11 +120,30 @@ exp_mail_it(struct objcore *oc, uint8_t cmds)
VSC_C_main->exp_mailed++;
}
oc->exp_flags |= cmds | OC_EF_POSTED;
AN(oc->exp_flags & OC_EF_REFD);
AZ(pthread_cond_signal(&exphdl->condvar));
}
}
/*--------------------------------------------------------------------
* Setup a new ObjCore for control by expire. Should be called with the
* ObjHead locked by HSH_Unbusy(/HSH_Insert) (in private access).
*/
void
EXP_RefNewObjcore(struct objcore *oc)
{
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
Lck_AssertHeld(&oc->objhead->mtx);
AZ(oc->exp_flags);
assert(oc->refcnt >= 1);
oc->refcnt++;
oc->exp_flags |= OC_EF_REFD;
}
/*--------------------------------------------------------------------
* Call EXP's attention to a an oc
*/
......@@ -152,6 +172,10 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
if (!(oc->exp_flags & OC_EF_REFD))
return;
assert(oc->refcnt >= 2);
AZ(oc->flags & OC_F_DYING);
......@@ -159,7 +183,7 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
ObjSendEvent(wrk, oc, OEV_INSERT);
Lck_Lock(&exphdl->mtx);
AZ(oc->exp_flags & (OC_EF_INSERT | OC_EF_MOVE));
exp_mail_it(oc, OC_EF_INSERT | OC_EF_REFD | OC_EF_MOVE);
exp_mail_it(oc, OC_EF_INSERT | OC_EF_MOVE);
Lck_Unlock(&exphdl->mtx);
}
......
......@@ -305,7 +305,7 @@ HSH_Insert(struct worker *wrk, const void *digest, struct objcore *oc,
objecthead. The new object inherits our objhead reference. */
oc->objhead = oh;
VTAILQ_INSERT_TAIL(&oh->objcs, oc, hsh_list);
oc->refcnt++; // For EXP_Insert
EXP_RefNewObjcore(oc);
Lck_Unlock(&oh->mtx);
BAN_RefBan(oc, ban);
......@@ -836,7 +836,7 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc)
assert(oh->refcnt > 0);
assert(oc->refcnt > 0);
if (!(oc->flags & OC_F_PRIVATE))
oc->refcnt++; // For EXP_Insert
EXP_RefNewObjcore(oc); /* Takes a ref for expiry */
/* XXX: strictly speaking, we should sort in Date: order. */
VTAILQ_REMOVE(&oh->objcs, oc, hsh_list);
VTAILQ_INSERT_HEAD(&oh->objcs, oc, hsh_list);
......@@ -846,8 +846,8 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc)
hsh_rush1(wrk, oh, &rush, HSH_RUSH_POLICY);
}
Lck_Unlock(&oh->mtx);
if (!(oc->flags & OC_F_PRIVATE))
EXP_Insert(wrk, oc);
EXP_Insert(wrk, oc); /* Does nothing unless EXP_RefNewObjcore was
* called */
hsh_rush2(wrk, &rush);
}
......
......@@ -165,6 +165,7 @@ void VDI_Init(void);
/* cache_exp.c */
vtim_real EXP_Ttl(const struct req *, const struct objcore *);
vtim_real EXP_Ttl_grace(const struct req *, const struct objcore *oc);
void EXP_RefNewObjcore(struct objcore *);
void EXP_Insert(struct worker *wrk, struct objcore *oc);
void EXP_Remove(struct objcore *);
......
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