[master] 82eb76934 integrate the VCL_Rel() step into vcl_get()
Nils Goroll
nils.goroll at uplex.de
Mon Jan 27 15:21:06 UTC 2020
commit 82eb76934ad782e7b6e2e752dafc22cbb95ff5f8
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Wed Jan 22 10:01:53 2020 +0100
integrate the VCL_Rel() step into vcl_get()
... potentially saving a lock/unlock on the critical vcl_mtx
Both callers of vcl_get(), VPI_vcl_select() and VCL_Refresh(),
potentially have to unref another vcl first.
For VCL_Refresh(), this happens when the active vcl changes and the
previously active vcl is cached in (struct worker).vcl, which can be
assumed to always be the case on a busy system.
For VPI_vcl_select(), this happens when switching vcls at
esi_level > 0.
To summarize, this patch will primarily reduce contention on the
vcl_mtx after a 'vcl.use' CLI command on a busy system and for
'return(vcl(...))' with ESI.
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 4dc504b03..fa653c636 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -259,10 +259,21 @@ VCL_Panic(struct vsb *vsb, const char *nm, const struct vcl *vcl)
void
vcl_get(struct vcl **vcc, struct vcl *vcl)
{
+ struct vcl *old;
+
AN(vcc);
- AZ(*vcc);
+
+ old = *vcc;
+ *vcc = NULL;
+
+ CHECK_OBJ_ORNULL(old, VCL_MAGIC);
Lck_Lock(&vcl_mtx);
+ if (old != NULL) {
+ assert(old->busy > 0);
+ old->busy--;
+ }
+
if (vcl == NULL)
vcl = vcl_active; /* Sample vcl_active under lock to avoid
* race */
diff --git a/bin/varnishd/cache/cache_vpi.c b/bin/varnishd/cache/cache_vpi.c
index 298cac7a9..fd168fc18 100644
--- a/bin/varnishd/cache/cache_vpi.c
+++ b/bin/varnishd/cache/cache_vpi.c
@@ -108,8 +108,6 @@ VPI_vcl_select(VRT_CTX, VCL_VCL vcl)
AZ(req->top->vcl0);
req->top->vcl0 = req->vcl;
req->vcl = NULL;
- } else {
- VCL_Rel(&req->vcl);
}
vcl_get(&req->vcl, vcl);
VSLb(ctx->req->vsl, SLT_VCL_use, "%s via %s",
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 2da13502f..d02f9bddc 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -84,8 +84,6 @@ VCL_Refresh(struct vcl **vcc)
if (*vcc == vcl_active)
return;
- if (*vcc != NULL)
- VCL_Rel(vcc); /* XXX: optimize locking */
vcl_get(vcc, NULL);
}
More information about the varnish-commit
mailing list