Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit ed508fa

Browse files
committed
hash: Operate waiting list rush on objcores
Operating on an objcore allows to preserve the different rush strategies that existed so far: - rush one request for failed fetch tasks - rush one request for withdrawn objects - rush rush_exponent requests otherwise For the cases where no rush is expected, a null objcore is passed. For cacheable objects, all waiters are temporarily woken up at once, until waiting list matches are handled separately.
1 parent f1d56eb commit ed508fa

1 file changed

Lines changed: 35 additions & 22 deletions

File tree

bin/varnishd/cache/cache_hash.c

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ struct rush {
7575
static const struct hash_slinger *hash;
7676
static struct objhead *private_oh;
7777

78-
static void hsh_rush1(const struct worker *, struct objhead *,
79-
struct rush *, int);
78+
static void hsh_rush1(const struct worker *, struct objcore *,
79+
struct rush *);
8080
static void hsh_rush2(struct worker *, struct rush *);
8181
static int hsh_deref_objhead(struct worker *wrk, struct objhead **poh);
8282
static int hsh_deref_objhead_unlock(struct worker *wrk, struct objhead **poh,
83-
int);
83+
struct objcore *oc);
8484

8585
/*---------------------------------------------------------------------*/
8686

@@ -323,7 +323,7 @@ HSH_Insert(struct worker *wrk, const void *digest, struct objcore *oc,
323323
VTAILQ_REMOVE(&oh->objcs, oc, hsh_list);
324324
VTAILQ_INSERT_HEAD(&oh->objcs, oc, hsh_list);
325325
if (!VTAILQ_EMPTY(&oh->waitinglist))
326-
hsh_rush1(wrk, oh, &rush, HSH_RUSH_POLICY);
326+
hsh_rush1(wrk, oc, &rush);
327327
Lck_Unlock(&oh->mtx);
328328
hsh_rush2(wrk, &rush);
329329

@@ -501,7 +501,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
501501
if (oc != NULL && oc->flags & OC_F_HFP) {
502502
xid = VXID(ObjGetXID(wrk, oc));
503503
dttl = EXP_Dttl(req, oc);
504-
AN(hsh_deref_objhead_unlock(wrk, &oh, HSH_RUSH_POLICY));
504+
AN(hsh_deref_objhead_unlock(wrk, &oh, oc));
505505
wrk->stats->cache_hitpass++;
506506
VSLb(req->vsl, SLT_HitPass, "%u %.6f", xid, dttl);
507507
return (HSH_HITPASS);
@@ -521,7 +521,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
521521
}
522522
oc->hits++;
523523
boc_progress = oc->boc == NULL ? -1 : oc->boc->fetched_so_far;
524-
AN(hsh_deref_objhead_unlock(wrk, &oh, HSH_RUSH_POLICY));
524+
AN(hsh_deref_objhead_unlock(wrk, &oh, oc));
525525
Req_LogHit(wrk, req, oc, boc_progress);
526526
return (HSH_HIT);
527527
}
@@ -570,7 +570,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
570570
exp_oc->refcnt++;
571571
*ocp = exp_oc;
572572
exp_oc->hits++;
573-
AN(hsh_deref_objhead_unlock(wrk, &oh, 0));
573+
AN(hsh_deref_objhead_unlock(wrk, &oh, NULL));
574574
Req_LogHit(wrk, req, exp_oc, boc_progress);
575575
return (HSH_GRACE);
576576
}
@@ -603,22 +603,34 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
603603
*/
604604

605605
static void
606-
hsh_rush1(const struct worker *wrk, struct objhead *oh, struct rush *r, int max)
606+
hsh_rush1(const struct worker *wrk, struct objcore *oc, struct rush *r)
607607
{
608-
int i;
608+
struct objhead *oh;
609609
struct req *req;
610-
611-
if (max == 0)
612-
return;
613-
if (max == HSH_RUSH_POLICY)
614-
max = cache_param->rush_exponent;
615-
assert(max > 0);
610+
int i, max;
616611

617612
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
618-
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
613+
CHECK_OBJ_ORNULL(oc, OBJCORE_MAGIC);
619614
CHECK_OBJ_NOTNULL(r, RUSH_MAGIC);
620615
VTAILQ_INIT(&r->reqs);
616+
617+
if (oc == NULL)
618+
return;
619+
620+
oh = oc->objhead;
621+
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
621622
Lck_AssertHeld(&oh->mtx);
623+
624+
AZ(oc->flags & OC_F_BUSY);
625+
AZ(oc->flags & OC_F_PRIVATE);
626+
if (oc->flags & (OC_F_WITHDRAWN|OC_F_FAILED))
627+
max = 1;
628+
else if (oc->flags & (OC_F_HFM|OC_F_HFP|OC_F_CANCEL|OC_F_DYING))
629+
max = cache_param->rush_exponent;
630+
else
631+
max = INT_MAX; /* XXX: temp */
632+
assert(max > 0);
633+
622634
for (i = 0; i < max; i++) {
623635
req = VTAILQ_FIRST(&oh->waitinglist);
624636
if (req == NULL)
@@ -805,7 +817,7 @@ HSH_Fail(struct worker *wrk, struct objcore *oc)
805817
oc->flags |= OC_F_FAILED;
806818
if (oc->flags & OC_F_BUSY) {
807819
oc->flags &= ~OC_F_BUSY;
808-
hsh_rush1(wrk, oh, &rush, 1);
820+
hsh_rush1(wrk, oc, &rush);
809821
}
810822
Lck_Unlock(&oh->mtx);
811823
hsh_rush2(wrk, &rush);
@@ -890,7 +902,7 @@ HSH_Withdraw(struct worker *wrk, struct objcore **ocp)
890902
assert(oc->refcnt == 1);
891903
assert(oh->refcnt > 0);
892904
oc->flags = OC_F_WITHDRAWN;
893-
hsh_rush1(wrk, oh, &rush, 1);
905+
hsh_rush1(wrk, oc, &rush);
894906
AZ(HSH_DerefObjCoreUnlock(wrk, &oc, 0));
895907

896908
hsh_rush2(wrk, &rush);
@@ -944,7 +956,7 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc)
944956
oc->flags &= ~OC_F_BUSY;
945957
if (!VTAILQ_EMPTY(&oh->waitinglist)) {
946958
assert(oh->refcnt > 1);
947-
hsh_rush1(wrk, oh, &rush, HSH_RUSH_POLICY);
959+
hsh_rush1(wrk, oc, &rush);
948960
}
949961
Lck_Unlock(&oh->mtx);
950962
EXP_Insert(wrk, oc);
@@ -1144,7 +1156,8 @@ HSH_DerefObjCoreUnlock(struct worker *wrk, struct objcore **ocp, int rushmax)
11441156
}
11451157

11461158
static int
1147-
hsh_deref_objhead_unlock(struct worker *wrk, struct objhead **poh, int max)
1159+
hsh_deref_objhead_unlock(struct worker *wrk, struct objhead **poh,
1160+
struct objcore *oc)
11481161
{
11491162
struct objhead *oh;
11501163
struct rush rush;
@@ -1166,7 +1179,7 @@ hsh_deref_objhead_unlock(struct worker *wrk, struct objhead **poh, int max)
11661179
INIT_OBJ(&rush, RUSH_MAGIC);
11671180
if (!VTAILQ_EMPTY(&oh->waitinglist)) {
11681181
assert(oh->refcnt > 1);
1169-
hsh_rush1(wrk, oh, &rush, max);
1182+
hsh_rush1(wrk, oc, &rush);
11701183
}
11711184

11721185
if (oh->refcnt == 1)
@@ -1187,7 +1200,7 @@ hsh_deref_objhead(struct worker *wrk, struct objhead **poh)
11871200
TAKE_OBJ_NOTNULL(oh, poh, OBJHEAD_MAGIC);
11881201

11891202
Lck_Lock(&oh->mtx);
1190-
return (hsh_deref_objhead_unlock(wrk, &oh, 0));
1203+
return (hsh_deref_objhead_unlock(wrk, &oh, NULL));
11911204
}
11921205

11931206
void

0 commit comments

Comments
 (0)