Skip to content

Commit

Permalink
hash: Avoid locking objhead twice to withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
dridi committed Jan 29, 2024
1 parent e918ee6 commit ea4ba6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 19 additions & 5 deletions bin/varnishd/cache/cache_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,11 +954,10 @@ HSH_Withdraw(struct worker *wrk, struct objcore **ocp)
assert(oh->refcnt > 0);
oc->flags = OC_F_WITHDRAW;
hsh_rush1(wrk, oc, &rush);
Lck_Unlock(&oh->mtx);
AZ(HSH_DerefObjCoreUnlock(wrk, &oc));

hsh_rush2(wrk, &rush);

AZ(HSH_DerefObjCore(wrk, &oc));
}

/*---------------------------------------------------------------------
Expand Down Expand Up @@ -1145,18 +1144,33 @@ HSH_DerefObjCore(struct worker *wrk, struct objcore **ocp)
{
struct objcore *oc;
struct objhead *oh;
struct rush rush;
int r;

CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
TAKE_OBJ_NOTNULL(oc, ocp, OBJCORE_MAGIC);
assert(oc->refcnt > 0);
INIT_OBJ(&rush, RUSH_MAGIC);

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

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

int
HSH_DerefObjCoreUnlock(struct worker *wrk, struct objcore **ocp)
{
struct objcore *oc;
struct objhead *oh;
int r;

CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
TAKE_OBJ_NOTNULL(oc, ocp, OBJCORE_MAGIC);
assert(oc->refcnt > 0);

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

Lck_AssertHeld(&oh->mtx);
assert(oh->refcnt > 0);
r = --oc->refcnt;
if (!r)
Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/cache/cache_objhead.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ 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 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

0 comments on commit ea4ba6f

Please sign in to comment.