From 82c1d4de9ebb8daca73338098b5e0cba75e160cb Mon Sep 17 00:00:00 2001 From: Dridi Boukelmoune Date: Tue, 19 Dec 2023 15:10:42 +0100 Subject: [PATCH] hash: Make HSH_Fail() rush the waiting list If the fetch task failed before reaching HSH_Unbusy() we make sure to signal the waiting list immediately and not wait for the final objcore reference to be dropped. The OC_F_FAILED flag will prevent it from being looked up, so there is no reason to delay the rush. --- bin/varnishd/cache/cache_fetch.c | 5 ++--- bin/varnishd/cache/cache_hash.c | 10 +++++++++- bin/varnishd/cache/cache_objhead.h | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index c55d30437f3..09ff2217afe 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -1043,9 +1043,8 @@ vbf_stp_fail(struct worker *wrk, struct busyobj *bo) CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); assert(oc->boc->state < BOS_FINISHED); - HSH_Fail(oc); - if (!(oc->flags & OC_F_BUSY)) - HSH_Kill(oc); + HSH_Fail(wrk, oc); + HSH_Kill(oc); ObjSetState(wrk, oc, BOS_FAILED); return (F_STP_DONE); } diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index fc8be63848a..cbf57060f48 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -838,13 +838,16 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now, */ void -HSH_Fail(struct objcore *oc) +HSH_Fail(struct worker *wrk, struct objcore *oc) { struct objhead *oh; + struct rush rush; + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); oh = oc->objhead; CHECK_OBJ(oh, OBJHEAD_MAGIC); + INIT_OBJ(&rush, RUSH_MAGIC); /* * We have to have either a busy bit, so that HSH_Lookup @@ -854,8 +857,13 @@ HSH_Fail(struct objcore *oc) assert((oc->flags & OC_F_BUSY) || (oc->stobj->stevedore != NULL)); Lck_Lock(&oh->mtx); + if (oc->flags & OC_F_BUSY) { + oc->flags &= ~OC_F_BUSY; + hsh_rush1(wrk, oc, &rush); + } oc->flags |= OC_F_FAILED; Lck_Unlock(&oh->mtx); + hsh_rush2(wrk, &rush); } /*--------------------------------------------------------------------- diff --git a/bin/varnishd/cache/cache_objhead.h b/bin/varnishd/cache/cache_objhead.h index 785af5badab..cd55ea32191 100644 --- a/bin/varnishd/cache/cache_objhead.h +++ b/bin/varnishd/cache/cache_objhead.h @@ -67,11 +67,11 @@ enum lookup_e { HSH_BUSY, }; -void HSH_Fail(struct objcore *); void HSH_Kill(struct objcore *); void HSH_Insert(struct worker *, const void *hash, struct objcore *, struct ban *); void HSH_Unbusy(struct worker *, struct objcore *); +void HSH_Fail(struct worker *, struct objcore *); int HSH_Snipe(const struct worker *, struct objcore *); struct boc *HSH_RefBoc(const struct objcore *); void HSH_DerefBoc(struct worker *wrk, struct objcore *);