[master] d232d7f Reduce cost of HSH_Insert by one oh->mtx lock/unlock by grabbing the refcount adjecent to the call.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Feb 26 23:53:40 CET 2016
commit d232d7f6635da66b5e7d24edd5501023e6506ff4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Feb 26 22:53:08 2016 +0000
Reduce cost of HSH_Insert by one oh->mtx lock/unlock by grabbing
the refcount adjecent to the call.
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 9bdd92e..a6c2d3f 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -124,12 +124,11 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+ assert(oc->refcnt >= 2);
AZ(oc->exp_flags & (OC_EF_INSERT | OC_EF_MOVE));
AZ(oc->flags & OC_F_DYING);
- HSH_Ref(oc);
-
ObjSendEvent(wrk, oc, OEV_INSERT);
exp_mail_it(oc, OC_EF_INSERT | OC_EF_EXP | OC_EF_MOVE);
}
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index f952769..3a48d86 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -263,7 +263,9 @@ HSH_Insert(struct worker *wrk, const void *digest, struct objcore *oc,
AN(digest);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
AN(ban);
+ AN(oc->flags & OC_F_BUSY);
AZ(oc->flags & OC_F_PRIVATE);
+ assert(oc->refcnt == 1);
hsh_prealloc(wrk);
@@ -275,9 +277,9 @@ HSH_Insert(struct worker *wrk, const void *digest, struct objcore *oc,
/* Mark object busy and insert (precreated) objcore in
objecthead. The new object inherits our objhead reference. */
- oc->flags |= OC_F_BUSY;
oc->objhead = oh;
VTAILQ_INSERT_TAIL(&oh->objcs, oc, hsh_list);
+ oc->refcnt++; // For EXP_Insert
Lck_Unlock(&oh->mtx);
BAN_RefBan(oc, ban);
@@ -662,16 +664,19 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc)
AN(oc->stobj->stevedore);
AN(oc->flags & OC_F_BUSY);
assert(oh->refcnt > 0);
+ assert(oc->refcnt > 0);
if (!(oc->flags & OC_F_PRIVATE)) {
BAN_NewObjCore(oc);
AN(oc->ban);
- EXP_Insert(wrk, oc);
}
/* 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))
+ oc->refcnt++; // For EXP_Insert
/* XXX: strictly speaking, we should sort in Date: order. */
VTAILQ_REMOVE(&oh->objcs, oc, hsh_list);
VTAILQ_INSERT_HEAD(&oh->objcs, oc, hsh_list);
@@ -679,6 +684,8 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc)
if (!VTAILQ_EMPTY(&oh->waitinglist))
hsh_rush(wrk, oh);
Lck_Unlock(&oh->mtx);
+ if (!(oc->flags & OC_F_PRIVATE))
+ EXP_Insert(wrk, oc);
}
/*====================================================================
More information about the varnish-commit
mailing list