[master] a63b4a53b obj: Rush objcores based on BOC state changes
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Aug 27 15:23:06 UTC 2025
commit a63b4a53b40d5b7365e3cdcdbe851c2542532c90
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Mon Jan 22 14:58:27 2024 +0100
obj: Rush objcores based on BOC state changes
The BOS_PREP_STREAM state is retired. It was used as a stop-gap to
"unbusy" objects before waking up the client task for good. Instead,
the HSH_Unbusy() and HSH_Fail() functions are called once the gap is
closed, depending on the outcome.
This removes one unnecessary signal and consolidates multiple call
sites, ensuring that objects always drop the OC_F_BUSY flag from a
central location, for fetch tasks.
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 79798847d..f00516812 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -712,11 +712,8 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
assert(oc->boc->state == BOS_REQ_DONE);
- if (bo->do_stream) {
- ObjSetState(wrk, oc, BOS_PREP_STREAM);
- HSH_Unbusy(wrk, oc);
+ if (bo->do_stream)
ObjSetState(wrk, oc, BOS_STREAM);
- }
VSLb(bo->vsl, SLT_Fetch_Body, "%u %s %s",
bo->htc->body_status->nbr, bo->htc->body_status->name,
@@ -751,11 +748,8 @@ vbf_stp_fetchend(struct worker *wrk, struct busyobj *bo)
if (bo->do_stream)
assert(oc->boc->state == BOS_STREAM);
- else {
+ else
assert(oc->boc->state == BOS_REQ_DONE);
- ObjSetState(wrk, oc, BOS_PREP_STREAM);
- HSH_Unbusy(wrk, oc);
- }
ObjSetState(wrk, oc, BOS_FINISHED);
VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
@@ -884,11 +878,8 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
ObjSetFlag(bo->wrk, oc, OF_IMSCAND, 0);
AZ(ObjCopyAttr(bo->wrk, oc, stale_oc, OA_GZIPBITS));
- if (bo->do_stream) {
- ObjSetState(wrk, oc, BOS_PREP_STREAM);
- HSH_Unbusy(wrk, oc);
+ if (bo->do_stream)
ObjSetState(wrk, oc, BOS_STREAM);
- }
INIT_OBJ(vop, VBF_OBITER_PRIV_MAGIC);
vop->bo = bo;
@@ -1038,8 +1029,6 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
assert(o == VSB_len(synth_body));
AZ(ObjSetU64(wrk, oc, OA_LEN, o));
VSB_destroy(&synth_body);
- ObjSetState(wrk, oc, BOS_PREP_STREAM);
- HSH_Unbusy(wrk, oc);
if (stale != NULL && oc->ttl > 0)
HSH_Kill(stale);
ObjSetState(wrk, oc, BOS_FINISHED);
@@ -1060,9 +1049,8 @@ vbf_stp_fail(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
assert(oc->boc->state < BOS_FINISHED);
- HSH_Fail(wrk, oc);
- HSH_Kill(oc);
ObjSetState(wrk, oc, BOS_FAILED);
+ HSH_Kill(oc);
return (F_STP_DONE);
}
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 4c40d3b8d..172e29a8b 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -86,6 +86,7 @@
#include "cache_varnishd.h"
#include "cache_obj.h"
+#include "cache_objhead.h"
#include "vend.h"
#include "storage/storage.h"
@@ -490,8 +491,7 @@ ObjVAICancel(struct worker *wrk, struct boc *boc, struct vai_qe *qe)
*/
void
-ObjSetState(struct worker *wrk, const struct objcore *oc,
- enum boc_state_e next)
+ObjSetState(struct worker *wrk, struct objcore *oc, enum boc_state_e next)
{
const struct obj_methods *om;
@@ -500,7 +500,6 @@ ObjSetState(struct worker *wrk, const struct objcore *oc,
assert(next > oc->boc->state);
CHECK_OBJ_ORNULL(oc->stobj->stevedore, STEVEDORE_MAGIC);
- assert(next != BOS_STREAM || oc->boc->state == BOS_PREP_STREAM);
assert(next != BOS_FINISHED || (oc->oa_present & (1 << OA_LEN)));
if (oc->stobj->stevedore != NULL) {
@@ -509,6 +508,11 @@ ObjSetState(struct worker *wrk, const struct objcore *oc,
om->objsetstate(wrk, oc, next);
}
+ if (next == BOS_FAILED)
+ HSH_Fail(wrk, oc);
+ else if (oc->boc->state < BOS_STREAM && next >= BOS_STREAM)
+ HSH_Unbusy(wrk, oc);
+
Lck_Lock(&oc->boc->mtx);
oc->boc->state = next;
obj_boc_notify(oc->boc);
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 572ad2a0b..1e00b4004 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -342,8 +342,7 @@ int ObjGetSpace(struct worker *, struct objcore *, ssize_t *sz, uint8_t **ptr);
void ObjExtend(struct worker *, struct objcore *, ssize_t l, int final);
uint64_t ObjWaitExtend(const struct worker *, const struct objcore *,
uint64_t l, enum boc_state_e *statep);
-void ObjSetState(struct worker *, const struct objcore *,
- enum boc_state_e next);
+void ObjSetState(struct worker *, struct objcore *, enum boc_state_e next);
void ObjWaitState(const struct objcore *, enum boc_state_e want);
void ObjTouch(struct worker *, struct objcore *, vtim_real now);
void ObjFreeObj(struct worker *, struct objcore *);
diff --git a/include/tbl/boc_state.h b/include/tbl/boc_state.h
index 44984de81..2e0413660 100644
--- a/include/tbl/boc_state.h
+++ b/include/tbl/boc_state.h
@@ -32,7 +32,6 @@
BOC_STATE(INVALID, invalid) /* don't touch (yet) */
BOC_STATE(REQ_DONE, req_done) /* bereq.* can be examined */
-BOC_STATE(PREP_STREAM, prep_stream) /* Prepare for streaming */
BOC_STATE(STREAM, stream) /* beresp.* can be examined */
BOC_STATE(FINISHED, finished) /* object is complete */
BOC_STATE(FAILED, failed) /* something went wrong */
More information about the varnish-commit
mailing list