Skip to content

Commit

Permalink
hash: Retire HSH_RUSH_POLICY
Browse files Browse the repository at this point in the history
From now on, the policy will be derived from the objcore.
  • Loading branch information
dridi committed May 6, 2024
1 parent b0f36e1 commit 16af9b8
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_ban_lurker.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
if (i)
ObjSendEvent(wrk, oc, OEV_BANCHG);
}
(void)HSH_DerefObjCore(wrk, &oc, 0);
(void)HSH_DerefObjCore(wrk, &oc);
}
}

Expand Down
3 changes: 1 addition & 2 deletions bin/varnishd/cache/cache_busyobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ VBO_ReleaseBusyObj(struct worker *wrk, struct busyobj **pbo)
wrk->stats->ws_backend_overflow++;

if (bo->fetch_objcore != NULL) {
(void)HSH_DerefObjCore(wrk, &bo->fetch_objcore,
HSH_RUSH_POLICY);
(void)HSH_DerefObjCore(wrk, &bo->fetch_objcore);
}

VRT_Assign_Backend(&bo->director_req, NULL);
Expand Down
6 changes: 3 additions & 3 deletions bin/varnishd/cache/cache_expire.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
ObjSendEvent(wrk, oc, OEV_EXPIRE);
tmpoc = oc;
assert(oc->refcnt >= 2); /* Silence coverity */
(void)HSH_DerefObjCore(wrk, &oc, 0);
(void)HSH_DerefObjCore(wrk, &oc);
AZ(oc);
assert(tmpoc->refcnt >= 1); /* Silence coverity */
}
Expand Down Expand Up @@ -309,7 +309,7 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, unsigned flags, double now)
VXID(ObjGetXID(ep->wrk, oc)), EXP_Ttl(NULL, oc) - now,
(intmax_t)oc->hits);
ObjSendEvent(ep->wrk, oc, OEV_EXPIRE);
(void)HSH_DerefObjCore(ep->wrk, &oc, 0);
(void)HSH_DerefObjCore(ep->wrk, &oc);
return;
}

Expand Down Expand Up @@ -387,7 +387,7 @@ exp_expire(struct exp_priv *ep, vtim_real now)
VXID(ObjGetXID(ep->wrk, oc)), EXP_Ttl(NULL, oc) - now,
(intmax_t)oc->hits);
ObjSendEvent(ep->wrk, oc, OEV_EXPIRE);
(void)HSH_DerefObjCore(ep->wrk, &oc, 0);
(void)HSH_DerefObjCore(ep->wrk, &oc);
}
return (0);
}
Expand Down
8 changes: 4 additions & 4 deletions bin/varnishd/cache/cache_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
http_Teardown(bo->beresp);
// can not make assumptions about the number of references here #3434
if (bo->bereq_body != NULL)
(void) HSH_DerefObjCore(bo->wrk, &bo->bereq_body, 0);
(void)HSH_DerefObjCore(bo->wrk, &bo->bereq_body);

if (oc->boc->state == BOS_FINISHED) {
AZ(oc->flags & OC_F_FAILED);
Expand All @@ -1124,7 +1124,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
// AZ(oc->boc); // XXX

if (bo->stale_oc != NULL)
(void)HSH_DerefObjCore(wrk, &bo->stale_oc, 0);
(void)HSH_DerefObjCore(wrk, &bo->stale_oc);

wrk->vsl = NULL;
HSH_DerefBoc(wrk, oc);
Expand Down Expand Up @@ -1215,7 +1215,7 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
"No thread available for bgfetch");
(void)vbf_stp_fail(req->wrk, bo);
if (bo->stale_oc != NULL)
(void)HSH_DerefObjCore(wrk, &bo->stale_oc, 0);
(void)HSH_DerefObjCore(wrk, &bo->stale_oc);
HSH_DerefBoc(wrk, oc);
SES_Rel(bo->sp);
THR_SetBusyobj(NULL);
Expand All @@ -1238,5 +1238,5 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
assert(oc->boc == boc);
HSH_DerefBoc(wrk, oc);
if (mode == VBF_BACKGROUND)
(void)HSH_DerefObjCore(wrk, &oc, HSH_RUSH_POLICY);
(void)HSH_DerefObjCore(wrk, &oc);
}
12 changes: 5 additions & 7 deletions bin/varnishd/cache/cache_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
EXP_Remove(ocp[i], NULL);
else
EXP_Reduce(ocp[i], ttl_now, ttl, grace, keep);
(void)HSH_DerefObjCore(wrk, &ocp[i], 0);
(void)HSH_DerefObjCore(wrk, &ocp[i]);
AZ(ocp[i]);
total++;
}
Expand Down Expand Up @@ -903,7 +903,7 @@ HSH_Withdraw(struct worker *wrk, struct objcore **ocp)
assert(oh->refcnt > 0);
oc->flags = OC_F_WITHDRAWN;
hsh_rush1(wrk, oc, &rush);
AZ(HSH_DerefObjCoreUnlock(wrk, &oc, 0));
AZ(HSH_DerefObjCoreUnlock(wrk, &oc));

hsh_rush2(wrk, &rush);
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ HSH_DerefBoc(struct worker *wrk, struct objcore *oc)
*/

int
HSH_DerefObjCore(struct worker *wrk, struct objcore **ocp, int rushmax)
HSH_DerefObjCore(struct worker *wrk, struct objcore **ocp)
{
struct objcore *oc;
struct objhead *oh;
Expand All @@ -1111,11 +1111,11 @@ HSH_DerefObjCore(struct worker *wrk, struct objcore **ocp, int rushmax)
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);

Lck_Lock(&oh->mtx);
return (HSH_DerefObjCoreUnlock(wrk, &oc, rushmax));
return (HSH_DerefObjCoreUnlock(wrk, &oc));
}

int
HSH_DerefObjCoreUnlock(struct worker *wrk, struct objcore **ocp, int rushmax)
HSH_DerefObjCoreUnlock(struct worker *wrk, struct objcore **ocp)
{
struct objcore *oc;
struct objhead *oh;
Expand All @@ -1125,8 +1125,6 @@ HSH_DerefObjCoreUnlock(struct worker *wrk, struct objcore **ocp, int rushmax)
TAKE_OBJ_NOTNULL(oc, ocp, OBJCORE_MAGIC);
assert(oc->refcnt > 0);

(void)rushmax;

oh = oc->objhead;
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);

Expand Down
7 changes: 2 additions & 5 deletions bin/varnishd/cache/cache_objhead.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ int HSH_Snipe(const struct worker *, struct objcore *);
struct boc *HSH_RefBoc(const struct objcore *);
void HSH_DerefBoc(struct worker *wrk, struct objcore *);
void HSH_DeleteObjHead(const struct worker *, struct objhead *);

int HSH_DerefObjCore(struct worker *, struct objcore **, int rushmax);
#define HSH_RUSH_POLICY -1

int HSH_DerefObjCoreUnlock(struct worker *, struct objcore **, int rushmax);
int HSH_DerefObjCore(struct worker *, struct objcore **);
int HSH_DerefObjCoreUnlock(struct worker *, struct objcore **);
enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct objcore **);
void HSH_Ref(struct objcore *o);
void HSH_AddString(struct req *, void *ctx, const char *str);
Expand Down
10 changes: 5 additions & 5 deletions bin/varnishd/cache/cache_req_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
if (STV_NewObject(req->wrk, req->body_oc, stv, 0) == 0) {
req->req_body_status = BS_ERROR;
HSH_DerefBoc(req->wrk, req->body_oc);
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc, 0));
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc));
(void)VFP_Error(vfc, "Object allocation failed:"
" Ran out of space in %s", stv->vclname);
return (-1);
Expand All @@ -94,7 +94,7 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
if (VFP_Open(ctx, vfc) < 0) {
req->req_body_status = BS_ERROR;
HSH_DerefBoc(req->wrk, req->body_oc);
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc, 0));
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc));
return (-1);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
VSLb_ts_req(req, "ReqBody", VTIM_real());
if (func != NULL) {
HSH_DerefBoc(req->wrk, req->body_oc);
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc, 0));
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc));
if (vfps == VFP_END && r == 0 && (flush & OBJ_ITER_END) == 0)
r = func(priv, flush | OBJ_ITER_END, NULL, 0);
if (vfps != VFP_END) {
Expand All @@ -158,7 +158,7 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)

if (vfps != VFP_END) {
req->req_body_status = BS_ERROR;
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc, 0));
AZ(HSH_DerefObjCore(req->wrk, &req->body_oc));
return (-1);
}

Expand Down Expand Up @@ -279,7 +279,7 @@ VRB_Free(struct req *req)
if (req->body_oc == NULL)
return;

r = HSH_DerefObjCore(req->wrk, &req->body_oc, 0);
r = HSH_DerefObjCore(req->wrk, &req->body_oc);

// each busyobj may have gained a reference
assert (r >= 0);
Expand Down
16 changes: 8 additions & 8 deletions bin/varnishd/cache/cache_req_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
ObjTouch(req->wrk, req->objcore, req->t_prev);

if (Resp_Setup_Deliver(req)) {
(void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY);
(void)HSH_DerefObjCore(wrk, &req->objcore);
req->err_code = 500;
req->req_step = R_STP_SYNTH;
return (REQ_FSM_MORE);
Expand All @@ -237,7 +237,7 @@ cnt_deliver(struct worker *wrk, struct req *req)

if (wrk->vpi->handling != VCL_RET_DELIVER) {
HSH_Cancel(wrk, req->objcore, NULL);
(void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY);
(void)HSH_DerefObjCore(wrk, &req->objcore);
http_Teardown(req->resp);

switch (wrk->vpi->handling) {
Expand Down Expand Up @@ -411,7 +411,7 @@ cnt_synth(struct worker *wrk, struct req *req)
VSLb(req->vsl, SLT_Error, "Could not get storage");
req->doclose = SC_OVERLOAD;
VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
(void)HSH_DerefObjCore(wrk, &req->objcore, 1);
(void)HSH_DerefObjCore(wrk, &req->objcore);
http_Teardown(req->resp);
return (REQ_FSM_DONE);
}
Expand Down Expand Up @@ -509,7 +509,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
if (boc != NULL)
HSH_DerefBoc(wrk, req->objcore);

(void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY);
(void)HSH_DerefObjCore(wrk, &req->objcore);
http_Teardown(req->resp);

req->vdp_filter_list = NULL;
Expand All @@ -536,7 +536,7 @@ cnt_fetch(struct worker *wrk, struct req *req)
if (req->objcore->flags & OC_F_FAILED) {
req->err_code = 503;
req->req_step = R_STP_SYNTH;
(void)HSH_DerefObjCore(wrk, &req->objcore, 1);
(void)HSH_DerefObjCore(wrk, &req->objcore);
AZ(req->objcore);
return (REQ_FSM_MORE);
}
Expand Down Expand Up @@ -664,7 +664,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
}

/* Drop our object, we won't need it */
(void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY);
(void)HSH_DerefObjCore(wrk, &req->objcore);

if (busy != NULL) {
HSH_Withdraw(wrk, &busy);
Expand Down Expand Up @@ -694,7 +694,7 @@ cnt_miss(struct worker *wrk, struct req *req)
wrk->stats->cache_miss++;
VBF_Fetch(wrk, req, req->objcore, req->stale_oc, VBF_NORMAL);
if (req->stale_oc != NULL)
(void)HSH_DerefObjCore(wrk, &req->stale_oc, 0);
(void)HSH_DerefObjCore(wrk, &req->stale_oc);
req->req_step = R_STP_FETCH;
return (REQ_FSM_MORE);
case VCL_RET_FAIL:
Expand All @@ -714,7 +714,7 @@ cnt_miss(struct worker *wrk, struct req *req)
}
VRY_Clear(req);
if (req->stale_oc != NULL)
(void)HSH_DerefObjCore(wrk, &req->stale_oc, 0);
(void)HSH_DerefObjCore(wrk, &req->stale_oc);
HSH_Withdraw(wrk, &req->objcore);
return (REQ_FSM_MORE);
}
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_vrt_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ VRT_u_bereq_body(VRT_CTX)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
if (ctx->bo->bereq_body != NULL) {
(void)HSH_DerefObjCore(ctx->bo->wrk, &ctx->bo->bereq_body, 0);
(void)HSH_DerefObjCore(ctx->bo->wrk, &ctx->bo->bereq_body);
http_Unset(ctx->bo->bereq, H_Content_Length);
}

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/storage/storage_lru.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,6 @@ LRU_NukeOne(struct worker *wrk, struct lru *lru)
ObjSlim(wrk, oc);

VSLb(wrk->vsl, SLT_ExpKill, "LRU xid=%ju", VXID(ObjGetXID(wrk, oc)));
(void)HSH_DerefObjCore(wrk, &oc, 0); // Ref from HSH_Snipe
(void)HSH_DerefObjCore(wrk, &oc); // Ref from HSH_Snipe
return (1);
}
2 changes: 1 addition & 1 deletion bin/varnishd/storage/storage_persistent_silo.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
HSH_Insert(wrk, so->hash, oc, ban);
AN(oc->ban);
HSH_DerefBoc(wrk, oc); // XXX Keep it an stream resurrection?
(void)HSH_DerefObjCore(wrk, &oc, HSH_RUSH_POLICY);
(void)HSH_DerefObjCore(wrk, &oc);
wrk->stats->n_vampireobject++;
}
Pool_Sumstat(wrk);
Expand Down

0 comments on commit 16af9b8

Please sign in to comment.