Skip to content

Commit

Permalink
hash: Skip the cache ceremony for private objects
Browse files Browse the repository at this point in the history
This reduces a great deal of spurious activity on the private_oh waiting
list and removes unncessary conditionals when dealing with cacheable (or
at least searchable) objects.

There is still some waiting list no-op activity via HSH_Fail() but it
can be considered negligible compared to the happy path.
  • Loading branch information
dridi committed Jan 29, 2024
1 parent 7080515 commit 71b00d5
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions bin/varnishd/cache/cache_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,27 +918,36 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(oc->boc, BOC_MAGIC);
AN(oc->flags & OC_F_BUSY);

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

/* NB: It is guaranteed that exactly one request is waiting for
* the objcore for pass objects. The other reference is held by
* the current fetch task.
*/
if (oh == private_oh) {
assert(oc->refcnt == 2);
oc->flags &= ~OC_F_BUSY;
return;
}

INIT_OBJ(&rush, RUSH_MAGIC);

AN(oc->stobj->stevedore);
AN(oc->flags & OC_F_BUSY);
AZ(oc->flags & OC_F_PRIVATE);
assert(oh->refcnt > 0);
assert(oc->refcnt > 0);

if (!(oc->flags & OC_F_PRIVATE)) {
BAN_NewObjCore(oc);
AN(oc->ban);
}
BAN_NewObjCore(oc);
AN(oc->ban);

/* XXX: pretouch neighbors on oh->objcs to prevent page-on under mtx */
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
assert(oc->refcnt > 0);
if (!(oc->flags & OC_F_PRIVATE))
EXP_RefNewObjcore(oc); /* Takes a ref for expiry */
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);
Expand All @@ -948,8 +957,7 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc)
hsh_rush1(wrk, oc, &rush);
}
Lck_Unlock(&oh->mtx);
EXP_Insert(wrk, oc); /* Does nothing unless EXP_RefNewObjcore was
* called */
EXP_Insert(wrk, oc);
hsh_rush2(wrk, &rush);
}

Expand Down

0 comments on commit 71b00d5

Please sign in to comment.